Skip to content

Commit

Permalink
Update: support multiline /*eslint-env*/ directives (fixes #14652) (#…
Browse files Browse the repository at this point in the history
…14660)

* Fix: linter ignores multiline /*eslint-env*/ directives (fixes #14652)

* Update lib/linter/linter.js

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>

* Chore: add more tests

Co-authored-by: Milos Djermanovic <milos.djermanovic@gmail.com>
  • Loading branch information
aladdin-add and mdjermanovic committed Jun 4, 2021
1 parent 8d1e75a commit c545163
Show file tree
Hide file tree
Showing 2 changed files with 18 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(.+?)\*\//gsu;

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

// https://github.com/eslint/eslint/issues/14652
it("should not report a violation", () => {
const codes = [
"/*eslint-env es6\n */ new Promise();",
"/*eslint-env browser,\nes6 */ window;Promise;",
"/*eslint-env\nbrowser,es6 */ window;Promise;"
];
const config = { rules: { "no-undef": 1 } };

for (const code of codes) {
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 c545163

Please sign in to comment.