diff --git a/src/jshint.js b/src/jshint.js index 5ae1ae3904..44b12e70a0 100644 --- a/src/jshint.js +++ b/src/jshint.js @@ -2433,7 +2433,15 @@ var JSHINT = (function() { that.right = expression(context, orPrecendence); return that; }, orPrecendence); - infix("&&", "and", 50); + + var andPrecedence = 50; + infix("&&", function(context, left, that) { + increaseComplexityCount(); + that.left = left; + that.right = expression(context, andPrecedence); + return that; + }, andPrecedence); + // The Exponentiation operator, introduced in ECMAScript 2016 // // ExponentiationExpression[Yield] : diff --git a/tests/unit/fixtures/max-cyclomatic-complexity-per-function.js b/tests/unit/fixtures/max-cyclomatic-complexity-per-function.js index 2680048fe6..5429775307 100644 --- a/tests/unit/fixtures/max-cyclomatic-complexity-per-function.js +++ b/tests/unit/fixtures/max-cyclomatic-complexity-per-function.js @@ -80,3 +80,11 @@ function functionWithCyclomaticComplexityDueToTernaryStatements_2(a) { function functionWithCyclomaticComplexityDueToOrOperators_2(a) { var b = a || {}; } + +function functionWithCyclomaticComplexityDueToAndOperators_2(a) { + var b = a && {}; +} + +function functionWithCyclomaticComplexityDueToAndOperatorsWithNot_2(a) { + var b = !(!a && {}); +} diff --git a/tests/unit/options.js b/tests/unit/options.js index fc9541f3ed..65aa31a0c4 100644 --- a/tests/unit/options.js +++ b/tests/unit/options.js @@ -2725,6 +2725,8 @@ exports.maxcomplexity = function (test) { .addError(47, 44, "This function's cyclomatic complexity is too high. (8)") .addError(76, 66, "This function's cyclomatic complexity is too high. (2)") .addError(80, 60, "This function's cyclomatic complexity is too high. (2)") + .addError(84, 61, "This function's cyclomatic complexity is too high. (2)") + .addError(88, 68, "This function's cyclomatic complexity is too high. (2)") .test(src, { es3: true, maxcomplexity: 1 }); TestRun(test)