Skip to main content

Core analyzer

Function-Level Analysis

Per-function complexity, length, and parameter-count diagnostics.

technical-debt core-functions

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.

Which functions are listed. Every function that has a body and is not inside another function, however it is bound: a declaration, a function assigned to a variable, a function passed to a call (memo(...), forwardRef(...), a store factory), an object-literal member, a class method, accessor, constructor or property, a default export. A function nested inside another one is listed too when it has a name: a nested declaration, a method, a function bound to a variable or property (directly or through useCallback-style wrappers), a named function expression, or the callback of a test registration (it('…', () => {})). An inline callback without a name belongs to the function that contains it.

What is measured. Each listed function's numbers are its own: decisions, cognitive score and lines inside a nested function that is listed separately are not counted again in the function around it. Length is the number of lines that hold a token of the function — blank lines and comment lines are not counted. A TypeScript this pseudo-parameter is not a parameter.

Score. Each function's quality is its weakest dimension, read off the same piecewise-linear curves as the other core analyses; the file's score is the mean function quality weighted by function length, so it says how much of the file's function code lives in poor functions.

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, because 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.
Documentation