Skip to content

Commit

Permalink
Fix: parsing regex option failing when defined in a comment.
Browse files Browse the repository at this point in the history
(fixes eslint#9366) levn parsing string differently than JSON.parse,
e.g.
JSON.parse(          '{ "foo": "\\n" }') // => { foo: '\n' }
levn.parse('Object', '{ "foo": "\\n" }') // => { foo: '\\n' }
  • Loading branch information
薛定谔的猫 committed Sep 30, 2017
1 parent 8ebb034 commit 0467c98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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, "\\");

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

0 comments on commit 0467c98

Please sign in to comment.