Expand description
Canonical metric catalog: offender sub-metric ids with their
long-form sentences, metric_catalog::Direction and
metric_catalog::Scale, plus the family view rendered by
bca list-metrics and the metric-selector resolver
(metric_catalog::resolve_selector). Single source of truth
shared by the library’s offender formatters, the CLI’s threshold
engine (which pins its extractor ids to
metric_catalog::METRICS via a parity test), and the metric
selections of bca metrics --metrics and the Python metrics=.
metric_catalog::Threshold is the validated limit that answers
breach, severity, soft-tier, change and drift questions in the
metric’s own direction and scale.
Single source of truth for the metric catalog.
Before this module existed, the same set of offender metric ids was
hand-maintained in three places — output::sarif’s rule
descriptions, the CLI’s threshold extractor table, and a third copy
inside a “does every extractor have a description” test — plus a
fourth, differently-shaped table powering bca list-metrics. Those
tables drifted: ten of twenty-one rule-description keys once failed
to match any real offender id and went unnoticed for two model
versions.
METRICS is now the canonical
list of offender sub-metric ids (halstead.volume, mi.original,
…) together with their long-form sentences and
Direction.
FAMILIES is the canonical view
that bca list-metrics renders. The library’s offender formatters
(output::sarif, output::code_climate) read METRICS; the
CLI’s threshold engine keys its extractor table off the same ids and
a parity test pins the two id-sets together, so a new metric cannot
ship with a half-updated catalog.
Each entry also records its Scale:
ratio for the counts, interval for the Maintainability Index family,
whose zero is arbitrary and whose values go negative.
Threshold builds on direction
and scale together. It is a validated limit that answers every value
question a gate asks: whether a value breaches, by how much, how two
breaches rank, where the soft tier sits, and how far a value has
moved from its baseline. Those answers then mean the same thing on
every surface (#1621).
resolve_selector reads
both tables to turn a selector — a name saying what to compute — into
the Metric family that computes it. bca metrics --metrics and the
Python bindings’ metrics= both resolve through it, so a name copied
from bca list-metrics or bca check --threshold works in either or
neither (#1614).
Structs§
- Checked
- A successfully validated
Threshold, together with any advisory the limit raised. - Metric
Family - A top-level metric family as surfaced by
bca list-metrics. - Metric
Info - Catalog entry for one offender-emitting sub-metric id.
- Metric
Row - A
bca list-metricsrow: the bare name printed innamesmode and the one-line summary printed indescriptionsmode. - Threshold
- A metric limit that has been checked against the metric’s
Scale: the metric id is known, the limit is finite, and a ratio-scale limit is non-negative. - Unknown
Selector Error - Error returned by
resolve_selectorfor a name that is no metric selector.
Enums§
- Change
- How a value has moved relative to its baseline record, oriented so
a positive number means worse. Returned by
Threshold::change. - Direction
- Which direction of a metric’s value is unhealthy.
- Limit
Error - Why a limit was rejected by
Threshold::checkor a soft ratio byThreshold::soft_limit. - Limit
Warning - An advisory raised by a limit
Threshold::checkaccepted. - Metric
Scope - The space kind a metric’s threshold is meaningful on (issue #969).
- Scale
- The measurement scale of a metric’s value: which arithmetic on it means anything (issue #1621).
Constants§
- FAMILIES
- Canonical
bca list-metricsview. Family summaries moved here verbatim from the CLI’s former hand-maintained catalog. Declaration order is thelist-metricsprint order. - METRICS
- Canonical offender sub-metric catalog. Long-form sentences and the
mi.*lower-is-worse direction moved here verbatim from the formeroutput::rule_descriptionstable.
Functions§
- lookup
- Catalog entry for a known offender id, or
None. Callers pick their own fallback for unknown ids (SARIF emits the raw id; Code Climate falls through to its default message). - lower_
is_ worse Deprecated - Whether a lower value of the metric
idis the unhealthy direction (themi.*Maintainability Index family). An id the catalog does not know defaults to higher-is-worse (#698). - resolve_
selector - Resolve a metric selector to the
Metricfamily that computes it. - scale
- The
Scaleof metricid(issue #1621), orNonefor an id the catalog does not know. The free-function twin ofscope. - scope
- The
MetricScopeof metricid— the space kind its threshold gates (issue #969).Nonefor an id the catalog does not know; both front-ends treat an unknown id as a usage error before reaching here, so theNonearm is only a defensive fallback. - selector_
names - The names
resolve_selectoradvertises: every family name (loc,halstead, …) and everybca list-metricsrow name (sloc,dloc, …), sorted and deduplicated.