diff --git a/lib/linter.js b/lib/linter.js index e96e713ffdb..c5d57629fcd 100755 --- a/lib/linter.js +++ b/lib/linter.js @@ -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, "\\"); + items = levn.parse("Object", string) || {}; // Some tests say that it should ignore invalid comments such as `/*eslint no-alert:abc*/`. diff --git a/tests/lib/linter.js b/tests/lib/linter.js index b9d1c5d3ace..cd8bb435fff 100644 --- a/tests/lib/linter.js +++ b/tests/lib/linter.js @@ -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; }";