Skip to content

Commit

Permalink
Fix: linter ignores multiline /*eslint-env*/ directives (fixes eslint…
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Jun 3, 2021
1 parent 2e43dac commit 4fd6945
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/linter/linter.js
Expand Up @@ -444,7 +444,7 @@ function normalizeEcmaVersion(ecmaVersion) {
return ecmaVersion >= 2015 ? ecmaVersion - 2009 : ecmaVersion;
}

const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)\*\//gu;
const eslintEnvPattern = /\/\*\s*eslint-env\s([\s\S]+?)\*\//gu;

/**
* Checks whether or not there is a comment which has "eslint-env *" in a given text.
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/linter/linter.js
Expand Up @@ -2957,6 +2957,18 @@ var a = "test2";
assert.strictEqual(messages.length, 0);
});

// https://github.com/eslint/eslint/issues/14652
it("should not report a violation", () => {
const code = "/*eslint-env es6\n */ new Promise();";

const config = { rules: { "no-undef": 1 } };

const messages = linter.verify(code, config, filename);

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


it("should not report a violation", () => {
const code = `/*${ESLINT_ENV} mocha,node */ require();describe();`;

Expand Down

0 comments on commit 4fd6945

Please sign in to comment.