noExcessiveCognitiveComplexity
このコンテンツはまだ日本語訳がありません。
Diagnostic Category: lint/complexity/noExcessiveCognitiveComplexity
Since: v1.0.0
Sources:
- Same as:
sonarjs/cognitive-complexity
Disallow functions that exceed a given Cognitive Complexity score.
The more complexity a function contains, the harder it is to understand later on.
Reducing complexity helps to make code more maintenable, both by making it easier to understand as well as by reducing chances of accidental side-effects when making changes.
This rule calculates a complexity score for every function and disallows those that exceed a configured complexity threshold (default: 15).
The complexity score is calculated based on the Cognitive Complexity algorithm: https://redirect.sonarsource.com/doc/cognitive-complexity.html
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:10 lint/complexity/noExcessiveCognitiveComplexity ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Excessive complexity of 21 detected (max: 15).
> 1 │ function tooComplex() {
│ ^^^^^^^^^^
2 │ for (let x = 0; x < 10; x++) {
3 │ for (let y = 0; y < 10; y++) {
ℹ Please refactor this function to reduce its complexity score from 21 to the max allowed complexity 15.
Options
Section titled OptionsAllows to specify the maximum allowed complexity.
The allowed values range from 1 through 254. The default is 15.