Complexity rules
What adds a decision point to a function's cyclomatic complexity, and what does not.
Every function starts at 1. Each of these adds one:
if,elif, andelse if, and Rust’slet … else.- A ternary or conditional expression.
- Each loop:
for,while,do, and Rust’sloop. - Each
caseof aswitch, arm of amatch, or case of a Goselect. Default arms add nothing:default, Rust’s_ =>, and Python’scase _:. A guardedcase _ if x:still counts, and so does its guard. - Each
catchorexceptclause. - Each
&&,||,and, andor, including the&&of a Rustif letchain. - Each
forandifclause in a Python comprehension.
These add nothing: ?? and ?., Rust’s ?, finally, early returns, and a
nested function, which is scored on its own.