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:.
Changing a limit
Section titled “Changing a limit”The limit rules (max_function_length, max_cyclomatic_complexity and the others in the table below) take max:
assay: rules: max_function_length: max: 80Each 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.
The limits of each preset
Section titled “The limits of each preset”| Metric | Limit rule | core |
recommended |
strict |
|---|---|---|---|---|
| Cyclomatic complexity | max_cyclomatic_complexity |
— | 15 | 10 |
| Cognitive complexity | max_cognitive_complexity |
— | — | 15 |
| Function length | max_function_length |
— | 60 | 40 |
| Nesting depth | max_nesting_depth |
— | 4 | 3 |
| Parameter count | max_parameters |
— | 6 | 4 |
| Methods per class | none: reported only | |||
| File length | max_file_length |
— | 600 | 400 |
- 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
maxis in effect, it reports nothing. - In the test directories (
test/**,integration_test/**,test_driver/**),recommendedandstrictmakemax_function_lengthandmax_file_lengthsilent, 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
excludeof its own (Configuring rules). The metric then has no limit, or none in those paths, andassay metricsstill lists its values. max_widget_nestingtakesmaxin the same way, 10 underrecommendedand 7 understrict. It has a count of its own and is not one of the seven metrics.
Gate conditions
Section titled “Gate conditions”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: 10Duplication, 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: 5Both 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
enabledand noexclude: it is on where it is written. To cancel one that an included file writes, write0for a coverage threshold or100for 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 withassay 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 raisesmin_tokensofduplicated_codeso that fewer copies are found (assay.cross_file.duplicated_code.min_tokens: 100 -> 400).