eslint-plugin-complexity

raw JSON →
1.0.2 verified Sat Apr 25 auth: no javascript

ESLint plugin providing additional complexity-related rules beyond ESLint's built-in complexity rule. Version 1.0.2 is the latest stable release, published on npm. It adds a custom rule 'complexity/comment' to warn when a function's cyclomatic complexity exceeds a configurable maximum. Differentiator: focused solely on complexity with a comment-based rule, not a general-purpose plugin.

error Configuration for rule "complexity/comment" is invalid: Value "{max:10}" should be object.
cause Configuration of rule 'complexity/comment' is not an object with max property.
fix
Use { max: 10 } with quotes: 'complexity/comment': ['warn', { max: 10 }]
error ESLint couldn't find the plugin "eslint-plugin-complexity".
cause Plugin not installed or not listed in plugins array correctly.
fix
Run npm i eslint-plugin-complexity -D and add 'complexity' to plugins array in config.
gotcha Rule 'complexity/comment' only checks functions with a leading comment (e.g., /* complexity: 5 */). Without a comment, no warning is emitted.
fix Ensure a comment like '/* complexity: N */' is present before the function to be checked.
npm install eslint-plugin-complexity
yarn add eslint-plugin-complexity
pnpm add eslint-plugin-complexity

Configures ESLint to warn when function cyclomatic complexity exceeds 10 using the comment rule.

module.exports = {
  plugins: ['complexity'],
  rules: {
    'complexity/comment': ['warn', { max: 10 }]
  }
};