Skip to content

Configuring metrics

The limit of a metric is the rule parameter max of its limit rule, set under assay: rules: in the project’s root analysis_options.yaml (Configuration). Line coverage and duplicated code have no limit rule: the gate holds them to the gate conditions you write under assay: gate:.

The limit rules (max_function_length, max_cyclomatic_complexity and the others in the table below) take max:

assay:
rules:
max_function_length:
max: 80

Each preset sets its own limits; Presets lists them. Your value replaces the preset’s, and the rule’s exclude stays as the preset set it.

  • A dash means the preset does not hold the rule, so the metric has no limit under it.
  • A limit rule has no limit of its own. Where no max is in effect, it reports nothing.
  • In the test directories (test/**, integration_test/**, test_driver/**), recommended and strict make max_function_length and max_file_length silent, so a value there has no limit. See Files and limits.
  • A limit rule is a rule like any other: it can be switched off or given an exclude of its own (Configuring rules). The metric then has no limit, or none in those paths, and assay metrics still lists its values.
  • max_widget_nesting takes max in the same way, 10 under recommended and 7 under strict. It has a count of its own and is not one of the seven metrics.

A gate condition is a threshold the gate fails below, or a ceiling it fails above, on a measure of the project. assay.gate has two keys, and no other: coverage and duplication.

Coverage, under assay.gate.coverage (Coverage):

Key What it is Default
min_on_new_lines The least share of the new coverable lines of a change that its tests cover, in percent: a number from 0 to 100, whole or not (80, 72.5). none: no condition
min_overall The least share of all coverable lines of the project that its tests cover, in percent, written the same way. none: no condition
small_change A change of fewer new coverable lines than this is a small change: the condition on the new lines is not judged for it. A whole number, zero or more; 0 judges every change. 20
assay:
gate:
coverage:
min_on_new_lines: 80
min_overall: 70
small_change: 10

Duplication, under assay.gate.duplication (Duplication):

Key What it is Default
max_on_new_lines The largest share of the new code lines of a change that are duplicated, in percent: a number from 0 to 100, whole or not (3, 4.5). none: no condition
max_overall The largest share of all code lines of the project that are duplicated (its duplication density), in percent, written the same way. none: no condition
small_change A change of fewer new code lines than this is a small change: the condition on the new lines is not judged for it. A whole number, zero or more. It is apart from the small_change of coverage, which counts coverable lines. 20
assay:
gate:
duplication:
max_on_new_lines: 3
max_overall: 5

Both kinds work alike:

  • There is no condition unless an options file writes one. No preset writes one, so adopting a preset changes nothing here.
  • A condition has no enabled and no exclude: it is on where it is written. To cancel one that an included file writes, write 0 for a coverage threshold or 100 for a duplication ceiling. A value with no number (min_overall:, ~) is an error like any value of the wrong type, not a way to take a condition away.
  • The gate judges them only when asked: the coverage conditions on a coverage report (assay gate --coverage <file>), the duplication conditions with assay gate --duplication. The gate at turn end is never asked, so a configured condition never fails a turn end. Without a report, each coverage condition is listed as not judged; see Coverage.
  • Every value is a configuration change. An agent that lowers a threshold, raises a ceiling or takes one away is shown it at turn end (assay.gate.coverage.min_on_new_lines: 80 -> 60, assay.gate.duplication.max_on_new_lines: 3 -> 10). So is one that raises min_tokens of duplicated_code so that fewer copies are found (assay.cross_file.duplicated_code.min_tokens: 100 -> 400).