Cyclomatic Complexity
ID |
javascript.cyclomatic_complexity |
Severity |
low |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Complexity |
Language |
JavaScript |
Tags |
code-style, complexity |
Description
Reports functions whose cyclomatic complexity (CCN) exceeds a configurable threshold. CCN measures the number of linearly-independent execution paths through a function — high CCN correlates with hard-to-test, hard-to-maintain code.
Rationale
-
CCN captures nested branching, long
if/elsechains, compound boolean conditions, and deeply nested loops as a single number that is straightforward to reason about. -
The threshold is intentionally conservative — most code under it does not require special review, but values above it routinely correlate with defect density and refactoring difficulty.
Remediation
Extract independent branches into helper functions, replace deeply nested ternary chains with switch, or split the function along its decision boundaries.