From e456847daaaf37ef086356c978170b4a7fe955be Mon Sep 17 00:00:00 2001 From: Kevin Partington Date: Thu, 21 Dec 2017 23:14:51 -0600 Subject: [PATCH] Update: Logical-and is counted in `complexity` rule (fixes #8535) --- lib/rules/complexity.js | 4 +--- tests/lib/rules/complexity.js | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/rules/complexity.js b/lib/rules/complexity.js index e0313fa78f1..e90a6626e07 100644 --- a/lib/rules/complexity.js +++ b/lib/rules/complexity.js @@ -133,9 +133,7 @@ module.exports = { * @private */ function increaseLogicalComplexity(node) { - - // Avoiding && - if (node.operator === "||") { + if (node.operator === "&&" || node.operator === "||") { 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 },