From 5bc5562e95e5efdc308b9ec33debf967912b006f Mon Sep 17 00:00:00 2001 From: Sean Gray Date: Mon, 7 Oct 2019 17:36:57 -0500 Subject: [PATCH] Update: no-constant-condition allows for narrower scope of varriable arrays --- lib/rules/no-constant-condition.js | 7 ++----- tests/lib/rules/no-constant-condition.js | 4 ++++ 2 files changed, 6 insertions(+), 5 deletions(-) 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" }] } ] });