Skip to content

Commit

Permalink
Merge remote-tracking branch 'lukeapage/complexity'
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike committed Jun 20, 2020
2 parents 0f0acd8 + 047d5af commit 4966651
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/jshint.js
Expand Up @@ -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] :
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/fixtures/max-cyclomatic-complexity-per-function.js
Expand Up @@ -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 && {});
}
2 changes: 2 additions & 0 deletions tests/unit/options.js
Expand Up @@ -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)
Expand Down

0 comments on commit 4966651

Please sign in to comment.