From 4fd6945817e8fc134e0252c670b838080cd2c204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Thu, 3 Jun 2021 15:01:53 +0800 Subject: [PATCH 1/3] Fix: linter ignores multiline /*eslint-env*/ directives (fixes #14652) --- lib/linter/linter.js | 2 +- tests/lib/linter/linter.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/linter/linter.js b/lib/linter/linter.js index bdc6c1b1d01..72a9b24f9b6 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -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. diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index 976bd765755..20ddeef601b 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -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();`; From d1a01a24d08bcf5f1a0907edcc1269633e465c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=96=9B=E5=AE=9A=E8=B0=94=E7=9A=84=E7=8C=AB?= Date: Thu, 3 Jun 2021 19:05:06 +0800 Subject: [PATCH 2/3] Update lib/linter/linter.js Co-authored-by: Milos Djermanovic --- lib/linter/linter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/linter/linter.js b/lib/linter/linter.js index 72a9b24f9b6..0e240edc4f5 100644 --- a/lib/linter/linter.js +++ b/lib/linter/linter.js @@ -444,7 +444,7 @@ function normalizeEcmaVersion(ecmaVersion) { return ecmaVersion >= 2015 ? ecmaVersion - 2009 : ecmaVersion; } -const eslintEnvPattern = /\/\*\s*eslint-env\s([\s\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. From 6863e8f881d82f836d79489684cad3877fa260bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Fri, 4 Jun 2021 11:57:49 +0800 Subject: [PATCH 3/3] Chore: add more tests --- tests/lib/linter/linter.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/lib/linter/linter.js b/tests/lib/linter/linter.js index 20ddeef601b..7345aa77ac0 100644 --- a/tests/lib/linter/linter.js +++ b/tests/lib/linter/linter.js @@ -2959,15 +2959,20 @@ var a = "test2"; // https://github.com/eslint/eslint/issues/14652 it("should not report a violation", () => { - const code = "/*eslint-env es6\n */ new Promise();"; - + 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 } }; - const messages = linter.verify(code, config, filename); + for (const code of codes) { + const messages = linter.verify(code, config, filename); - assert.strictEqual(messages.length, 0); - }); + assert.strictEqual(messages.length, 0); + } + }); it("should not report a violation", () => { const code = `/*${ESLINT_ENV} mocha,node */ require();describe();`;