Skip to content
Permalink
Browse files

Update: Add default limit to `complexity` (fixes #4808)

  • Loading branch information...
IanVS committed Dec 31, 2015
1 parent 1623db4 commit 1288ba435d6758394bf97495583159b32742bfaa
Showing with 4 additions and 3 deletions.
  1. +1 −1 docs/rules/complexity.md
  2. +1 −1 lib/rules/complexity.js
  3. +2 −1 tests/lib/rules/complexity.js
@@ -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:

@@ -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
@@ -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] },

0 comments on commit 1288ba4

Please sign in to comment.
You can’t perform that action at this time.