Skip to content

Commit

Permalink
Update: no-constant-condition allows for narrower scope of varriable …
Browse files Browse the repository at this point in the history
…arrays
  • Loading branch information
tickct committed Oct 7, 2019
1 parent b146b51 commit 5bc5562
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/rules/no-constant-condition.js
Expand Up @@ -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;
}
Expand All @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/no-constant-condition.js
Expand Up @@ -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" }]
}
]
});

0 comments on commit 5bc5562

Please sign in to comment.