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: ignore messages without a ruleId
in getRulesMetaForResults
#16409
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3660,6 +3660,24 @@ describe("FlatESLint", () => { | |
const results = await engine.lintText("a", { filePath: "foo.js" }); | ||
const rulesMeta = engine.getRulesMetaForResults(results); | ||
|
||
assert.strictEqual(Object.keys(rulesMeta).length, 1); | ||
assert.strictEqual(rulesMeta.semi, coreRules.get("semi").meta); | ||
}); | ||
|
||
it("should return one rule meta when there is a suppressed linting error", async () => { | ||
const engine = new FlatESLint({ | ||
overrideConfigFile: true, | ||
overrideConfig: { | ||
rules: { | ||
semi: 2 | ||
} | ||
} | ||
}); | ||
|
||
const results = await engine.lintText("a // eslint-disable-line semi"); | ||
const rulesMeta = engine.getRulesMetaForResults(results); | ||
|
||
assert.strictEqual(Object.keys(rulesMeta).length, 1); | ||
assert.strictEqual(rulesMeta.semi, coreRules.get("semi").meta); | ||
}); | ||
|
||
|
@@ -3707,6 +3725,46 @@ describe("FlatESLint", () => { | |
nodePlugin.rules["no-new-require"].meta | ||
); | ||
}); | ||
|
||
it("should ignore messages not related to a rule", async () => { | ||
const engine = new FlatESLint({ | ||
overrideConfigFile: true, | ||
overrideConfig: { rules: { "no-var": "warn" } }, | ||
reportUnusedDisableDirectives: "warn" | ||
}); | ||
|
||
{ | ||
const results = await engine.lintText("syntax error"); | ||
const rulesMeta = engine.getRulesMetaForResults(results); | ||
|
||
assert.deepStrictEqual(rulesMeta, {}); | ||
} | ||
{ | ||
const results = await engine.lintText("// eslint-disable-line no-var"); | ||
const rulesMeta = engine.getRulesMetaForResults(results); | ||
|
||
assert.deepStrictEqual(rulesMeta, {}); | ||
} | ||
{ | ||
const results = await engine.lintText("", { filePath: "/.ignored.js", warnIgnored: true }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use some explicitly ignored file path instead of (the same for the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated as suggested, thanks! |
||
const rulesMeta = engine.getRulesMetaForResults(results); | ||
|
||
assert.deepStrictEqual(rulesMeta, {}); | ||
} | ||
}); | ||
|
||
it("should return a non-empty value if some of the messages are related to a rule", async () => { | ||
const engine = new FlatESLint({ | ||
overrideConfigFile: true, | ||
overrideConfig: { rules: { "no-var": "warn" } }, | ||
reportUnusedDisableDirectives: "warn" | ||
}); | ||
|
||
const results = await engine.lintText("// eslint-disable-line no-var\nvar foo;"); | ||
const rulesMeta = engine.getRulesMetaForResults(results); | ||
|
||
assert.deepStrictEqual(rulesMeta, { "no-var": coreRules.get("no-var").meta }); | ||
}); | ||
}); | ||
|
||
describe("outputFixes()", () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it also make sense to ensure that there is only one key in
rulesMeta
? (Based on the name of this test.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an assertion to make sure that there is only one key to the two unit tests that mention "one rule meta" in the title. Thanks @nzakas!