ALL-FUNC0009 · nesting_depth
Measure the deepest control nesting one callable reaches.
This is a deterministic rule for all languages. Read its implementation.
Definition
Section titled “Definition”Read the nesting depth a provider recorded for every control structure inside one callable and return the deepest one. Depth counts the structures enclosing a structure rather than the structure itself, so the outermost loop of a body sits at depth zero and a condition written inside it sits at depth one. Depth is what forces a reader to hold earlier conditions in mind while reading the innermost statement, which is why it is measured on its own rather than folded into a single complexity number.
Evidence
Section titled “Evidence”Each finding records the callable range and the deepest structure with its own range. The value is that depth.
Exceptions
Section titled “Exceptions”A callable with no resolved control structure has depth zero. Guard clauses that return early keep depth low by construction and are the usual repair, so the measurement rewards them without naming them.
Examples
Section titled “Examples”A loop holding a condition holding a second condition returns 2, since the loop is at depth
zero and the two conditions at depths one and two. The same logic written as three sequential
guard clauses returns 0, because no structure encloses another. A callable with no control
structure at all also returns 0.
References
Section titled “References”- Generalizes Clippy excessive_nesting. Open reference
- Generalizes ESLint max-depth. Open reference
- Cites Pylint R1702 too-many-nested-blocks. Open reference