sonarjs/cognitive-complexity
eslint-plugin-sonarjs
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"sonarjs/cognitive-complexity": "error",
},
},
];function tooComplex() {
for (let x = 0; x < 10; x++) {
for (let y = 0; y < 10; y++) {
for (let z = 0; z < 10; z++) {
if (x % 2 === 0) {
if (y % 2 === 0) {
console.log(x > y ? `${x} > ${y}` : `${y} > ${x}`);
}
}
}
}
}
}The documentation shows no correct example for this rule.
Examples from the Biome documentation.
sonarjs/cognitive-complexity
eslint-plugin-sonarjs
export default [
{
rules: {
"sonarjs/cognitive-complexity": "error",
},
},
];Oxlint does not have this rule.
complexity/noExcessiveCognitiveComplexity
complexity · since 1.0.0
{
"linter": {
"rules": {
"complexity": {
"noExcessiveCognitiveComplexity": "error"
}
}
}
}A "while" loop should be used instead of a "for" loop
Template literals should not be nested
Alternatives in regular expressions should be grouped when used with anchors
Arguments to built-in functions should match documented types
Callbacks of array methods should have return statements