Skip to content

builtin.complexity.cyclomatic

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

Cyclomatic complexity measures the number of linearly independent paths through a function — 1 for a straight-line function, plus one for every branch (if, match / switch arm, while, for, try / except, ternary, etc.). It’s a strong predictor of how hard a function is to test and maintain: every additional path is another case the reader must hold in their head and another scenario the tests must cover.

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

[complexity]
cyclomatic_warn = 10
cyclomatic_error = 20
SettingDefaultEffect
cyclomatic_warn10Functions at or above this trigger a warn.
cyclomatic_error20Functions at or above this escalate to error.
  • Extract guard clauses — turn early-return branches into top-of-function validation so the body deals only with the happy path.
  • Pull conditional logic into helpers — a match over many cases is often clearer when each arm calls a named function.
  • Replace flag arguments with separate functionsdo_thing(opts) that branches on opts.kind is usually two functions in disguise.
  • Use polymorphism / table-driven dispatch — long if/else if chains on a tag value beg for a lookup table or trait object.