Skip to content
Fallow home
All docs pages

Docs home

High CRAP score

What a high-crap-score finding of fallow health means, why it matters and how to fix it.

What it reports

Function has a high CRAP score (complexity combined with low coverage).

Health explains how fallow finds it.

Why it matters

The function's CRAP (Change Risk Anti-Patterns) score meets or exceeds the configured threshold. CRAP combines cyclomatic complexity with test coverage using the Savoia and Evans (2007) formula: CC^2 * (1 - coverage/100)^3 + CC. High CRAP indicates changes to this function carry high risk because it is complex and poorly tested. Pair with --coverage for accurate per-function scoring; without it fallow estimates coverage from the module graph. This rule fires on functions only: synthetic template-family units (<template>, Svelte <snippet:NAME>) are excluded from the CRAP dimension, because a template is exercised only through its component and carries no coverage the formula could measure. Templates gate on the cyclomatic and cognitive dimensions instead.

Example

A complex function has little or no matching Istanbul coverage, so its CRAP score crosses the configured gate. Synthetic template-family units (the <template> units on Angular, Vue, Svelte and Astro markup, and Svelte <snippet:NAME> units) are not scored on this dimension: a template carries no direct coverage of its own, so fallow gates templates on the cyclomatic and cognitive dimensions instead.

Fix

Add focused tests for the risky branches first, then simplify the function if the score remains high. Template findings never carry this rule, so a maxCrap override scoped to a template unit buys nothing and can be removed. To report these findings without a failed run, set the complexity-crap rule to warn.

Facts

FactValue
Issue typehigh-crap-score
Rule id in SARIF outputfallow/high-crap-score
Commandfallow health
Default severityerror
Config key in rulescomplexity-crap
Filter option--complexity
Suppression comment// fallow-ignore-next-line complexity
Fixable with fallow fixNo
Opt-inNo

When to keep the code

  • Without coverage data, fallow estimates the coverage from the imports of the test files. A function that a test imports gets 85 percent, a function in a file that a test reaches gets 40 percent, and other functions get 0. A function that tests reach through another path can then get a score that is too high. Run with --coverage before you act on such a finding.