Skip to content

builtin.complexity.nesting

FieldValue
idbuiltin.complexity.nesting
severitywarn
categorycomplexity
scopefile
languagesrust, python, go, java, typescript, tsx, javascript
evaluatorbuiltin / nesting

Deeply nested control flow (if inside for inside while inside another if…) is one of the strongest correlates with bug density. Each level of nesting multiplies the number of state combinations the reader has to track and shrinks the working memory left for the actual logic.

Configure under [complexity] in .sextant/config.toml:

[complexity]
nesting_warn = 4
nesting_error = 6
SettingDefaultEffect
nesting_warn4Functions reaching this depth trigger a warn.
nesting_error6Functions reaching this depth escalate to error.

The depth is the maximum nesting level reached anywhere inside the function body. The function declaration itself counts as level 0.

  • Invert conditions and return earlyif !valid { return Err(_) } is one level shallower than if valid { ... }.
  • Extract inner blocks into helpers — pull the innermost loop body into its own function and replace it with a single call.
  • Use iterator chains over manual loopsiter().filter().map().sum() is a flat pipeline; the manual equivalent is at least two levels of nesting.
  • Split combined predicatesif a && b && c reads better as guard clauses; if (a, b, c) == ... collapses many branches into one match.