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

Update: support multiline /*eslint-env*/ directives (fixes #14652) #14660

Merged
merged 3 commits into from Jun 4, 2021
Merged
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
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 @@ -2957,6 +2957,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);
}

aladdin-add marked this conversation as resolved.
Show resolved Hide resolved
});

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

Expand Down