diff --git a/lib/rules/no-constant-condition.js b/lib/rules/no-constant-condition.js index 06c35f6aab45..744b8c6245f1 100644 --- a/lib/rules/no-constant-condition.js +++ b/lib/rules/no-constant-condition.js @@ -91,10 +91,7 @@ module.exports = { */ function isConstant(node, inBooleanPosition) { - /* - * Bug in espree (#425) causes [,] to return children of null - * so we need to check for existance until that is fixed - */ + // node.elements can return null values in the case of sparse arrays ex. [,] if (!node) { return true; } @@ -106,7 +103,7 @@ module.exports = { return true; case "ArrayExpression": { - if (inBooleanPosition) { + if (!(node.parent.operator === "+")) { return true; } return node.elements.every(element => isConstant(element, false)); diff --git a/tests/lib/rules/no-constant-condition.js b/tests/lib/rules/no-constant-condition.js index cfc2134eb4b2..84dd1976c0d9 100644 --- a/tests/lib/rules/no-constant-condition.js +++ b/tests/lib/rules/no-constant-condition.js @@ -209,6 +209,10 @@ ruleTester.run("no-constant-condition", rule, { { code: "if(''+[]) {}", errors: [{ messageId: "unexpected", type: "BinaryExpression" }] + }, + { + code: "if([a]==[a]) {}", + errors: [{ messageId: "unexpected", type: "BinaryExpression" }] } ] });