Skip to content

Commit

Permalink
Update: Logical-and is counted in complexity rule (fixes #8535) (#9754
Browse files Browse the repository at this point in the history
)
  • Loading branch information
platinumazure authored and gyandeeps committed Dec 23, 2017
1 parent eb4b1e0 commit 75c7419
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
16 changes: 1 addition & 15 deletions lib/rules/complexity.js
Expand Up @@ -126,20 +126,6 @@ module.exports = {
}
}

/**
* Increase the logical path complexity in context
* @param {ASTNode} node node to evaluate
* @returns {void}
* @private
*/
function increaseLogicalComplexity(node) {

// Avoiding &&
if (node.operator === "||") {
increaseComplexity();
}
}

//--------------------------------------------------------------------------
// Public API
//--------------------------------------------------------------------------
Expand All @@ -154,7 +140,7 @@ module.exports = {

CatchClause: increaseComplexity,
ConditionalExpression: increaseComplexity,
LogicalExpression: increaseLogicalComplexity,
LogicalExpression: increaseComplexity,
ForStatement: increaseComplexity,
ForInStatement: increaseComplexity,
ForOfStatement: increaseComplexity,
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/rules/complexity.js
Expand Up @@ -51,7 +51,7 @@ ruleTester.run("complexity", rule, {
{ code: "function a(x) {return x === 4 ? 3 : 5;}", options: [2] },
{ code: "function a(x) {return x === 4 ? 3 : (x === 3 ? 2 : 1);}", options: [3] },
{ code: "function a(x) {return x || 4;}", options: [2] },
{ code: "function a(x) {x && 4;}", options: [1] },
{ code: "function a(x) {x && 4;}", options: [2] },
{ code: "function a(x) {switch(x){case 1: 1; break; case 2: 2; break; default: 3;}}", options: [3] },
{ code: "function a(x) {switch(x){case 1: 1; break; case 2: 2; break; default: if(x == 'foo') {5;};}}", options: [4] },
{ code: "function a(x) {while(true) {'foo';}}", options: [2] },
Expand Down Expand Up @@ -80,7 +80,7 @@ ruleTester.run("complexity", rule, {
{ code: "function a(x) {return x === 4 ? 3 : 5;}", options: [1], errors: 1 },
{ code: "function a(x) {return x === 4 ? 3 : (x === 3 ? 2 : 1);}", options: [2], errors: 1 },
{ code: "function a(x) {return x || 4;}", options: [1], errors: 1 },
{ code: "function a(x) {x && 4;}", options: [0], errors: 1 },
{ code: "function a(x) {x && 4;}", options: [1], errors: 1 },
{ code: "function a(x) {switch(x){case 1: 1; break; case 2: 2; break; default: 3;}}", options: [2], errors: 1 },
{ code: "function a(x) {switch(x){case 1: 1; break; case 2: 2; break; default: if(x == 'foo') {5;};}}", options: [3], errors: 1 },
{ code: "function a(x) {while(true) {'foo';}}", options: [1], errors: 1 },
Expand Down

0 comments on commit 75c7419

Please sign in to comment.