1 # Limit Cyclomatic Complexity (complexity)
3 Cyclomatic complexity measures the number of linearly independent paths through a program's source code. This rule allows setting a cyclomatic complexity threshold.
10 return x+1; // 2nd path
19 This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is `20`).
21 Examples of **incorrect** code for a maximum of 2:
24 /*eslint complexity: ["error", 2]*/
37 Examples of **correct** code for a maximum of 2:
40 /*eslint complexity: ["error", 2]*/
53 Optionally, you may specify a `max` object property:
56 "complexity": ["error", 2]
62 "complexity": ["error", { "max": 2 }]
65 **Deprecated:** the object property `maximum` is deprecated. Please use the property `max` instead.
69 If you can't determine an appropriate complexity limit for your code, then it's best to disable this rule.
73 * [Cyclomatic Complexity](https://en.wikipedia.org/wiki/Cyclomatic_complexity)
74 * [Complexity Analysis of JavaScript Code](https://ariya.io/2012/12/complexity-analysis-of-javascript-code)
75 * [More about Complexity in JavaScript](https://craftsmanshipforsoftware.com/2015/05/25/complexity-for-javascript/)
76 * [About Complexity](https://web.archive.org/web/20160808115119/http://jscomplexity.org/complexity)
77 * [Discussion about Complexity in ESLint and more links](https://github.com/eslint/eslint/issues/4808#issuecomment-167795140)
81 * [max-depth](max-depth.md)
82 * [max-len](max-len.md)
83 * [max-lines](max-lines.md)
84 * [max-lines-per-function](max-lines-per-function.md)
85 * [max-nested-callbacks](max-nested-callbacks.md)
86 * [max-params](max-params.md)
87 * [max-statements](max-statements.md)