Function-Level Analysis
Per-function complexity, length, and parameter-count diagnostics.
File-level metrics smooth over hot functions. A 200-line file with 10 simple functions and one 150-line monster can have an acceptable file-level score while harbouring a maintenance hazard inside it. Function-level analysis surfaces the specific functions that drive complexity, so refactors can be targeted.
Each function is evaluated against four independent heuristics: cyclomatic complexity, cognitive complexity (with nesting penalty), length, and parameter count. Any of these exceeding its threshold triggers a per-function insight pointing directly at the location.
Severity guide
- info
- A function exceeds the parameter-count guideline; consider grouping related arguments into an options object.
- warning
- A function exceeds cyclomatic, cognitive, or length thresholds. Decompose into smaller, focused units.
- critical
- Not currently emitted by this analysis (file-level critical signals come from cyclomatic and maintainability).
Remediation
Decompose flagged functions into smaller named helpers; group long parameter lists into an options object.
- Identify logical phases inside the function (validation, transformation, side effect, formatting) and extract each into a named helper.
- For high-cognitive-complexity functions, prioritize reducing nesting depth — early returns and guard clauses give the largest wins.
- For long parameter lists, introduce an options object. This makes calls self-documenting and additions backward-compatible.
- Always add or update tests after extraction; the goal is to preserve behavior while making it easier to verify in pieces.