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: eslint-disable to be able to parse quoted rule names #17612

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion lib/linter/config-comment-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = class ConfigCommentParser {
const items = {};

string.split(",").forEach(name => {
const trimmedName = name.replace(/^\s*(?<quote>['"]?)(?<ruleId>\S*)\k<quote>\s*$/u, "$<ruleId>");
const trimmedName = name.trim().replace(/^(?<quote>['"]?)(?<ruleId>.*)\k<quote>$/us, "$<ruleId>");
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 also add some tests that have the whitespace @mdjermanovic mentioned to verify that this is the correct fix?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a test case to tests/lib/linter/config-comment-parser.js 👍


if (trimmedName) {
items[trimmedName] = true;
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/linter/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13060,7 +13060,7 @@ var a = "test2";
assert.strictEqual(suppressedMessages[1].line, 3);
});

it("should report a violation with literals", () => {
it("should report a violation with literals in eslint-disable", () => {
const code = [
"/*eslint-disable 'no-alert' */",
"alert('test');",
Expand All @@ -13084,7 +13084,7 @@ var a = "test2";
assert.strictEqual(suppressedMessages[1].ruleId, "no-console");
});

it("should report a violation with literals", () => {
it("should report a violation with literals in eslint-enable", () => {
const code = [
"/*eslint-disable no-alert, no-console */",
"alert('test');",
Expand Down Expand Up @@ -13347,7 +13347,7 @@ var a = "test2";
assert.strictEqual(suppressedMessages.length, 5);
});

it("should report a violation with literals", () => {
it("should report a violation with literals in eslint-disable-line", () => {
const code = [
"alert('test'); // eslint-disable-line 'no-alert'",
"console.log('test');", // here
Expand Down