Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Complexity rules

RuleWhat it catches
cyclomatic-per-unitA function with too many independent paths to test
cognitive-per-unitA function that is hard to follow, reported with its nesting penalty
npath-per-unitA function with too many execution paths
exits-per-unitA function that returns from too many places
low-maintainabilityA function with a low maintainability index
cyclomatic-per-fileA file dense with decisions

NPath complexity

NPath counts acyclic execution paths rather than independent branches. Sequential branches multiply rather than add, so a function with fourteen sequential if statements has a cyclomatic complexity of fifteen and over sixteen thousand execution paths. The two metrics are reported separately because they answer different questions: cyclomatic complexity tells you how many tests you need, while NPath tells you how many paths a reader has to reason about.

Exit count

A function with many exits is hard to reason about because the reader must hold every escape in mind to know what it guarantees. Early returns are still preferred to nesting, so the rule only fires well past the point where guards are idiomatic.

Maintainability index

The index combines Halstead volume, cyclomatic complexity, and line count, so it catches a unit that is dense with arithmetic rather than branches — a case the other complexity rules miss.