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: id-match mysteriously fails when defined in a comment. (fixes #9… #9372

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions lib/linter.js
Expand Up @@ -94,6 +94,10 @@ function parseJsonConfig(string, location) {

// Parses a JSON-like comment by the same way as parsing CLI option.
try {

// https://github.com/eslint/eslint/issues/9366
string = string.replace(/\\\\/g, "\\");
Copy link
Member Author

Choose a reason for hiding this comment

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

@not-an-aardvark it can fix the issue. but has a side effect:

// `\` is optional, so either is fine. 
/* eslint id-match: [2, "^(([^$\\W]|\\$[a-f\\d]{2})+|[$_]\\w*|[^\\W\\d]\\w*|[A-Z]([A-Z_]*[A-Z])?)$"]*/
/* eslint id-match: [2, "^(([^$\W]|\$[a-f\d]{2})+|[$_]\w*|[^\W\d]\w*|[A-Z]([A-Z_]*[A-Z])?)$"]*/


items = levn.parse("Object", string) || {};

// Some tests say that it should ignore invalid comments such as `/*eslint no-alert:abc*/`.
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/linter.js
Expand Up @@ -1513,6 +1513,15 @@ describe("Linter", () => {
assert.include(messages[0].nodeType, "CallExpression");
});

// https://github.com/eslint/eslint/issues/9366
it("rules should parse regex option correctly", () => {
const config = {};
const code = String.raw`/* eslint id-match: [2, "^(([^$\\W]|\\$[a-f\\d]{2})+|[$_]\\w*|[^\\W\\d]\\w*|[A-Z]([A-Z_]*[A-Z])?)$", {properties: true}] */ var is$2dvoid = 0;`;
const messages = linter.verify(code, config, filename, false);

assert.equal(messages.length, 0);
});

it("rules should not change initial config", () => {
const config = { rules: { strict: 2 } };
const codeA = "/*eslint strict: 0*/ function bar() { return 2; }";
Expand Down