Repository: eslint/eslint
File: tests/lib/rules/no-loop-func.js (JavaScript)

Code before:
                "}",
                "result.__default = 6;"
            ].join("\n"),
            parserOptions: { ecmaVersion: 6 }
        },
        {
            code: [
                "while (true) {",
                "    (function() { a; });",
                "}",
                "let a;"
            ].join("\n"),
            parserOptions: { ecmaVersion: 6 }
        },

        /*
         * 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" }]
        },

        /**
         * 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" }]
        },

        /**
         * These loops use an undeclared variable, and so shouldn't be flagged by this rule,
         * they'll be picked up by no-undef.
         */
        {
            code: "for (var i=0; i<l; i++) { (function() { undeclared; }) }",
            parserOptions: { ecmaVersion: 6 }
        },

Review comment (suggestion):
```suggestion
            code: "do { (function() { i; }) } while (i)"
```

Code after:
                "}",
                "result.__default = 6;"
            ].join("\n"),
            parserOptions: { ecmaVersion: 6 }
        },
        {
            code: [
                "while (true) {",
                "    (function() { a; });",
                "}",
                "let a;"
            ].join("\n"),
            parserOptions: { ecmaVersion: 6 }
        },

        /*
         * 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.
         */
        "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
         * and is not updated in or after the loop, they're fine as far as this rule is concerned.
         * The variable that's captured is just the one variable shared by all the loops, but that's
         * explicitly expected in these cases.
         */
        "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,
         * they'll be picked up by no-undef.
         */
        {
            code: "for (var i=0; i<l; i++) { (function() { undeclared; }) }",
            parserOptions: { ecmaVersion: 6 }
        },
        {
            code: "for (let i=0; i<l; i++) { (function() { undeclared; }) }",
            parserOptions: { ecmaVersion: 6 }
        },
        {
            code: "for (var i in {}) { i = 7; (function() { undeclared; }) }",
            parserOptions: { ecmaVersion: 6 }
        },
        {
            code: "for (let i in {}) { i = 7; (function() { undeclared; }) }",
            parserOptions: { ecmaVersion: 6 }
        },