cyclomatic-complexity
Installation
SKILL.md
Cyclomatic complexity
Cyclomatic complexity counts the independent paths through a function. It estimates two things: the minimum number of test cases needed for branch coverage, and how much a reader must hold in mind at once.
Counting rule
Start at 1. Add 1 for each decision point.
| Add 1 for | Notes |
|---|---|
if, else if |
else adds nothing, it is the fall-through path |
for, while, do-while |
each loop |
case in a switch |
each case label. The switch and default add nothing |
catch / except |
each handler. try and finally add nothing |
&&, ||, ?? |
each short-circuit operator |
ternary ? : |
one each |
?. optional chaining |
one each, though some tools skip it |
| pattern-match arm with a condition | each arm |