Skip to content

Commit

Permalink
fix: Update no-loop-func to not overlap with no-undef
Browse files Browse the repository at this point in the history
  • Loading branch information
matwilko committed Jul 14, 2023
1 parent 4778eb4 commit 6cd7aae
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions tests/lib/rules/no-loop-func.js
Expand Up @@ -117,29 +117,17 @@ ruleTester.run("no-loop-func", rule, {
* These loops _look_ like they might be unsafe, but because i is undeclared, they're fine
* at least as far as this rule is concerned - the loop doesn't declare/generate the variable.
*/
{
code: "while(i) { (function() { i; }) }",
errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "FunctionExpression" }]
},
{
code: "do { (function() { i; }) } while (i)",
errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "FunctionExpression" }]
},
"while(i) { (function() { i; }) }",
"do { (function() { i; }) } while (i)",

/**
* These loops _look_ like they might be unsafe, but because i is declared outside the loop,
* they're fine as far as this rule is concerned - the loop doesn't declare/generate the variable.
* The variable that's captured is just the one variable shared by all the loops, but that's
* explicitly expected in these cases.
*/
{
code: "var i; while(i) { (function() { i; }) }",
errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "FunctionExpression" }]
},
{
code: "var i; do { (function() { i; }) } while (i)",
errors: [{ messageId: "unsafeRefs", data: { varNames: "'i'" }, type: "FunctionExpression" }]
},
"var i; while(i) { (function() { i; }) }",
"var i; do { (function() { i; }) } while (i)",

/**
* These loops use an undeclared variable, and so shouldn't be flagged by this rule,
Expand Down

0 comments on commit 6cd7aae

Please sign in to comment.