oxlint-plugin-complexity
Cyclomatic and cognitive complexity rules for oxlint with actionable error messages
A linter plugin that analyzes code complexity metrics, helping developers identify and refactor hard-to-maintain code. Framework support spans React, Vue, Angular, Svelte, Astro, Solid, and Qwik, across .js, .mjs, .cjs, .ts, .tsx, .jsx, .vue, .svelte, and .astro files.
Installation
npm install oxlint-plugin-complexity --save-dev
Configuration
Add to your .oxlintrc.json. Cyclomatic and cognitive limits are configured together in a single complexity rule:
{
"jsPlugins": ["oxlint-plugin-complexity"],
"rules": {
"complexity/complexity": [
"error",
{
"cyclomatic": 20,
"cognitive": 15
}
]
}
}
Actionable Error Messages
The plugin delivers detailed feedback with a summary, a line-by-line breakdown, and refactoring tips for the deepest nesting:
complexity(complexity): Function 'processData' has Cognitive Complexity of 15.
Maximum allowed is 10. [if: +14, for: +1]
Breakdown:
Line 2: +1 for 'for'
>>> Line 6: +5 for 'if' (incl. +4 nesting) [top offender]
↳ Tip: Extract inner loops into helper functions — each extraction removes one nesting level
Metrics
Cyclomatic Complexity
Adds +1 for conditional branches, loops, case statements, catch, logical operators (&&, ||, ??), and ternaries.
Cognitive Complexity
Evaluates complexity considering nesting depth and specific patterns. React components using PascalCase naming that return JSX are excluded, as are standard default-value expressions. Only cognitive complexity tracks nesting depth, so refactoring tips require it.
Additional Features
- Standalone library — Analyze complexity programmatically via the
/standaloneand/diffentry points, no oxlint runtime needed - Git diff analysis — Score only the functions touched by a diff for CI gates and pre-commit hooks
- Smart extraction suggestions — Variable-flow analysis identifies extractable blocks and proposes typed signatures
- Industry Standard — Based on established specifications for complexity measurement