Skip to content

Commit

Permalink
Merge pull request #4836 from eslint/issue4808
Browse files Browse the repository at this point in the history
Update: Add default limit to `complexity` (fixes #4808)
  • Loading branch information
nzakas committed Dec 31, 2015
2 parents fd18d4e + 1288ba4 commit 994c8ee
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/rules/complexity.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function a(x) {

## Rule Details

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.
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`).

The following patterns are considered problems:

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/complexity.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

module.exports = function(context) {

var THRESHOLD = context.options[0];
var THRESHOLD = (typeof context.options[0] !== "undefined") ? context.options[0] : 20;

//--------------------------------------------------------------------------
// Helpers
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/complexity.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ var rule = require("../../../lib/rules/complexity"),
var ruleTester = new RuleTester();
ruleTester.run("complexity", rule, {
valid: [
{ code: "function a(x) {}", options: [1] },
{ code: "function a(x) {}" },
{ code: "function b(x) {}", options: [1] },
{ code: "function a(x) {if (true) {return x;}}", options: [2] },
{ code: "function a(x) {if (true) {return x;} else {return x+1;}}", options: [2] },
{ code: "function a(x) {if (true) {return x;} else if (false) {return x+1;} else {return 4;}}", options: [3] },
Expand Down

0 comments on commit 994c8ee

Please sign in to comment.