Skip to content

Commit

Permalink
Update: Logical-and is counted in complexity rule (fixes #8535)
Browse files Browse the repository at this point in the history
  • Loading branch information
platinumazure committed Dec 22, 2017
1 parent eb4b1e0 commit e456847
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/rules/complexity.js
Expand Up @@ -133,9 +133,7 @@ module.exports = {
* @private
*/
function increaseLogicalComplexity(node) {

// Avoiding &&
if (node.operator === "||") {
if (node.operator === "&&" || node.operator === "||") {
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 e456847

Please sign in to comment.