Repository: eslint/eslint
File: tests/lib/linter/code-path-analysis/code-path-analyzer.js (JavaScript)

Code before:
                        if (count === 1) {

                            // connect path: "right" -> "left"
                            assert(node.parent.type === "ForOfStatement");
                        } else if (count === 2) {
                            assert(node.type === "ForOfStatement");
                        }
                    }
                })
            });
            linter.verify(
                "for (var x of xs) { foo(); }",
                { rules: { test: 2 }, env: { es6: true } }
            );

            assert(count === 2);
        });
    });

    describe("completed code paths are correct", () => {
        const testDataDir = path.join(__dirname, "../../../fixtures/code-path-analysis/");
        const testDataFiles = fs.readdirSync(testDataDir);

        testDataFiles.forEach(file => {

            // if (!file.includes("--and-qq")) return;
            it(file, () => {
                const source = fs.readFileSync(path.join(testDataDir, file), { encoding: "utf8" });
                const expected = getExpectedDotArrows(source);
                const actual = [];

                assert(expected.length > 0, "/*expected */ comments not found.");

                linter.defineRule("test", {
                    create: () => ({
                        onCodePathEnd(codePath) {
                            actual.push(debug.makeDotArrows(codePath));
                        }
                    })
                });
                const messages = linter.verify(source, {
                    parserOptions: { ecmaVersion: 2022 },
                    rules: { test: 2 }
                });

                assert.strictEqual(messages.length, 0, "Unexpected linting error in code.");
                assert.strictEqual(actual.length, expected.length, "a count of code paths is wrong.");

                for (let i = 0; i < actual.length; ++i) {
                    assert.strictEqual(actual[i], expected[i]);
                }

Review comment (bug):
```suggestion
```

Also probably for debugging.

Code after:
                        if (count === 1) {

                            // connect path: "right" -> "left"
                            assert(node.parent.type === "ForOfStatement");
                        } else if (count === 2) {
                            assert(node.type === "ForOfStatement");
                        }
                    }
                })
            });
            linter.verify(
                "for (var x of xs) { foo(); }",
                { rules: { test: 2 }, env: { es6: true } }
            );

            assert(count === 2);
        });
    });

    describe("completed code paths are correct", () => {
        const testDataDir = path.join(__dirname, "../../../fixtures/code-path-analysis/");
        const testDataFiles = fs.readdirSync(testDataDir);

        testDataFiles.forEach(file => {
            it(file, () => {
                const source = fs.readFileSync(path.join(testDataDir, file), { encoding: "utf8" });
                const expected = getExpectedDotArrows(source);
                const actual = [];

                assert(expected.length > 0, "/*expected */ comments not found.");

                linter.defineRule("test", {
                    create: () => ({
                        onCodePathEnd(codePath) {
                            actual.push(debug.makeDotArrows(codePath));
                        }
                    })
                });
                const messages = linter.verify(source, {
                    parserOptions: { ecmaVersion: 2022 },
                    rules: { test: 2 }
                });

                assert.strictEqual(messages.length, 0, "Unexpected linting error in code.");
                assert.strictEqual(actual.length, expected.length, "a count of code paths is wrong.");

                for (let i = 0; i < actual.length; ++i) {
                    assert.strictEqual(actual[i], expected[i]);
                }
            });
        });