Skip to content

ESLint plugin

eslint-plugin-complexijs enforces a per-function cognitive complexity threshold using the same Rust/WASM engine as the CLI. The analysis runs on raw source text, so it does not depend on ESLint's AST.

TypeScript files work: the WASM engine can parse them directly, though you still need the usual typescript-eslint parser configured for ESLint itself if you want type-aware rules.

Install

npm install --save-dev eslint eslint-plugin-complexijs

Flat config

// eslint.config.js
const complexijs = require("eslint-plugin-complexijs");

module.exports = [
  {
    plugins: { complexijs },
    rules: {
      "complexijs/complexity": ["error", { max: 15 }],
    },
  },
];

The recommended config wires up the rule at warn with max: 15:

// eslint.config.js
const complexijs = require("eslint-plugin-complexijs");

module.exports = [
  complexijs.configs.recommended,
];

Rule options

Option Type Default Description
max integer >= 0 15 Maximum allowed cognitive complexity per function. Functions strictly above this value are reported.

Suppressing a function

Place a // complexijs: ignore or // noqa: complexijs comment on the function definition line or on the line directly above it:

// complexijs: ignore
function legacyRouter(req, res) {
  // ...
}

function alsoSkipped() {} // noqa: complexijs

Both markers are case-insensitive and work in // and /* */ comments. The marker is processed by the WASM engine, not by the ESLint rule, so it works regardless of the max setting.

How the WASM engine relates to the CLI

Both the ESLint plugin and the CLI use the same Rust scoring engine. The plugin loads it as a WASM module bundled inside eslint-plugin-complexijs. The CLI is a native binary built from the same source. Scores are identical between the two.

For the full scoring model, see the Complexity model page.