Skip to content
Fallow home
All docs pages

Docs home

High cyclomatic complexity

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

What it reports

Function has high cyclomatic complexity.

Health explains how fallow finds it.

Why it matters

McCabe cyclomatic complexity exceeds the configured threshold. Cyclomatic complexity counts the number of independent paths through a function (1 + decision points: if/else, switch cases, loops, ternary, logical operators). High values indicate functions that are hard to test exhaustively. fallow also emits this rule on synthetic <template> findings across every supported template dialect (Angular .html templates and inline @Component({ template: ... }) literals, Vue SFC <template> blocks, Svelte markup, Astro markup), counting each dialect's control-flow blocks (Angular @if/@else if/@for/@case/@defer (when ...) and legacy *ngIf/*ngFor; Vue v-if/v-else-if/v-for; Svelte {#if}/{:else if}/{#each}/{#await}/{#key}; the Astro equivalents) plus ternary and logical operators inside bound attributes and interpolations; on each top-level Svelte {#snippet name(...)} block, emitted as its own <snippet:NAME> unit; and on synthetic <component> rollup findings whose cyclomatic is the worst class method's score plus the template's. Ranking and --targets use the rollup total; JSON exposes the per-half breakdown under component_rollup.

Example

function route(req) has a switch with 14 case labels and two if checks. Its cyclomatic complexity is 17, while health.maxCyclomatic is 15.

Fix

For function findings, extract named helpers, split independent branches, flatten guard clauses, and add tests around the behavior before refactoring. For <template> findings, flatten nested control flow and move branch selection out of the markup: Angular @if/@for/@switch/@defer and legacy *ngIf/*ngFor into computed signals on the component class, Vue v-if/v-else-if/v-for into computed properties, Svelte {#if}/{:else if}/{#each}/{#await}/{#key} into derived state, Astro control flow into props resolved in the frontmatter. In Svelte, moving a repeated or deeply nested block into a top-level {#snippet} gives it its own <snippet:NAME> unit with nesting rebased to zero, so the in-file extraction moves the score; splitting a large template into child components lowers the score in every dialect. For <component> rollup findings, attack the larger half first; the per-half breakdown lives in component_rollup. To report these findings without a failed run, set the complexity-cyclomatic or complexity-cognitive rule to warn.

Facts

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

When to keep the code

  • Generated code, such as a GraphQL or OpenAPI client: leave it out with health.ignore.
  • A test file with many it() blocks can have a high count. Tests must cover many paths.
  • To keep one function visible with a higher limit, add a health.thresholdOverrides entry. A suppression hides the function completely.