Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle files with unspecified path in getRulesMetaForResults #16437

Merged
merged 4 commits into from Oct 31, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions tests/lib/eslint/flat-eslint.js
Expand Up @@ -3813,6 +3813,26 @@ describe("FlatESLint", () => {
assert.deepStrictEqual(rulesMeta, {});
});

it("should not throw an error if results contain linted files and one ignored file", async () => {
const engine = new FlatESLint({
overrideConfigFile: true,
cwd: getFixturePath(),
ignorePatterns: "passing*",
overrideConfig: {
rules: {
"no-undef": 2,
semi: 1
}
}
});

const results = await engine.lintFiles(["missing-semicolon.js", "passing.js", "undef.js"]);
const rulesMeta = engine.getRulesMetaForResults(results);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we verify that a file is actually being ignored here before doing the other assertions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I've added an assertion to make sure that one of the messages returned by lintFiles belongs to an ignored file.
I chose this implementation because it doesn't require calling another method on the engine under test.
Alternatively, we could pass the filePath of each result to isPathIgnored().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works. 👍


assert.deepStrictEqual(rulesMeta["no-undef"], coreRules.get("no-undef").meta);
assert.deepStrictEqual(rulesMeta.semi, coreRules.get("semi").meta);
});

it("should return empty object when there are no linting errors", async () => {
const engine = new FlatESLint({
overrideConfigFile: true
Expand Down