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.
Common errors
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.
Warnings
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.
Install
npm install eslint-plugin-complexity yarn add eslint-plugin-complexity pnpm add eslint-plugin-complexity Imports
- default export (plugin object) wrong
const complexity = require('eslint-plugin-complexity')correctimport complexity from 'eslint-plugin-complexity' - Flat config (ESLint 9+) wrong
module.exports = { plugins: ['complexity'], rules: { 'complexity/comment': 'warn' } }correctimport complexity from 'eslint-plugin-complexity'; export default [ { plugins: { complexity }, rules: { 'complexity/comment': 'warn' } } ] - Legacy .eslintrc config wrong
import complexity from 'eslint-plugin-complexity'; export default { plugins: { complexity }, rules: { 'complexity/comment': 'warn' } }correctmodule.exports = { plugins: ['complexity'], rules: { 'complexity/comment': 'warn' } }
Quickstart
module.exports = {
plugins: ['complexity'],
rules: {
'complexity/comment': ['warn', { max: 10 }]
}
};