From 75c741946e4255cdd8e744578bf474b3a7571cec Mon Sep 17 00:00:00 2001 From: Kevin Partington Date: Sat, 23 Dec 2017 13:02:53 -0600 Subject: [PATCH] Update: Logical-and is counted in `complexity` rule (fixes #8535) (#9754) --- lib/rules/complexity.js | 16 +--------------- tests/lib/rules/complexity.js | 4 ++-- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/lib/rules/complexity.js b/lib/rules/complexity.js index e0313fa78f1..323fdbff8ea 100644 --- a/lib/rules/complexity.js +++ b/lib/rules/complexity.js @@ -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 //-------------------------------------------------------------------------- @@ -154,7 +140,7 @@ module.exports = { CatchClause: increaseComplexity, ConditionalExpression: increaseComplexity, - LogicalExpression: increaseLogicalComplexity, + LogicalExpression: increaseComplexity, ForStatement: increaseComplexity, ForInStatement: increaseComplexity, ForOfStatement: increaseComplexity, diff --git a/tests/lib/rules/complexity.js b/tests/lib/rules/complexity.js index b1b031173dd..9e2b5d92b5d 100644 --- a/tests/lib/rules/complexity.js +++ b/tests/lib/rules/complexity.js @@ -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] }, @@ -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 },