* Welcome to my corner of the web! *

oxlint-plugin-complexity

Cyclomatic and cognitive complexity rules for oxlint with actionable error messages

  • TypeScript
  • oxlint
  • Vitest

A linter plugin that analyzes code complexity metrics, helping developers identify and refactor hard-to-maintain code. Supports .js, .mjs, .cjs, .ts, .tsx, .jsx, and .vue files.

Installation

npm install oxlint-plugin-complexity --save-dev

Configuration

Add to your .oxlintrc.json:

{
  "jsPlugins": ["oxlint-plugin-complexity"],
  "rules": {
    "complexity/max-cyclomatic": ["error", { "max": 20 }],
    "complexity/max-cognitive": ["error", { "max": 15 }]
  }
}

Actionable Error Messages

The plugin delivers detailed feedback showing exactly which constructs contributed to complexity violations:

Function ‘processData’ has a Cognitive Complexity of 6. Refactor to reduce it to the 5 allowed. [if: +5, for…of: +1]

Rules

Cyclomatic Complexity (max-cyclomatic)

Adds +1 for conditional branches, loops, case statements, logical operators, and ternary operators.

Cognitive Complexity (max-cognitive)

Evaluates complexity considering nesting depth and specific patterns. React components using PascalCase naming that return JSX are excluded, as are standard default-value expressions.

Additional Features

  • Programmatic API — Use as a standalone library in custom tooling
  • Vue Support — Analyzes script blocks in Vue single-file components
  • Industry Standard — Based on established specifications for complexity measurement