From d59c7482ac3590b4b2837cd49931d0a82df8ba4a Mon Sep 17 00:00:00 2001 From: Ron Y <31330116+i-ron-y@users.noreply.github.com> Date: Tue, 5 Sep 2017 22:05:17 -0700 Subject: [PATCH] Fix: shebang error in eslint-disable-new-line; add tests (fixes #9238) --- lib/linter.js | 2 +- tests/lib/linter.js | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/lib/linter.js b/lib/linter.js index 76487c53ec2..63c703b5d30 100755 --- a/lib/linter.js +++ b/lib/linter.js @@ -336,7 +336,7 @@ function modifyConfigsFromComments(filename, ast, config, linterContext) { const problems = []; const reportingConfig = linterContext.reportingConfig; - ast.comments.forEach(comment => { + ast.comments.filter(token => token.type !== "Shebang").forEach(comment => { let value = comment.value.trim(); const match = /^(eslint(-\w+){0,3}|exported|globals?)(\s|$)/.exec(value); diff --git a/tests/lib/linter.js b/tests/lib/linter.js index 92d7fa8c715..183ef4b1118 100644 --- a/tests/lib/linter.js +++ b/tests/lib/linter.js @@ -1873,6 +1873,26 @@ describe("Linter", () => { assert.equal(messages[0].ruleId, "no-console"); }); + it("should ignore violations of only the specified rule on next line", () => { + const code = [ + "// eslint-disable-next-line quotes", + "alert(\"test\");", + "console.log('test');" + ].join("\n"); + const config = { + rules: { + "no-alert": 1, + quotes: [1, "single"], + "no-console": 1 + } + }; + const messages = linter.verify(code, config, filename); + + assert.equal(messages.length, 2); + assert.equal(messages[0].ruleId, "no-alert"); + assert.equal(messages[1].ruleId, "no-console"); + }); + it("should ignore violations of specified rule on next line only", () => { const code = [ "alert('test');", @@ -1913,7 +1933,7 @@ describe("Linter", () => { assert.equal(messages[0].ruleId, "no-console"); }); - it("should not report if comment is in block quotes", () => { + it("should not ignore violations if comment is in block quotes", () => { const code = [ "alert('test');", "/* eslint-disable-next-line no-alert */", @@ -1933,6 +1953,25 @@ describe("Linter", () => { assert.equal(messages[1].ruleId, "no-alert"); assert.equal(messages[2].ruleId, "no-console"); }); + + it("should not ignore violations if comment is of the type Shebang", () => { + const code = [ + "#! eslint-disable-next-line no-alert", + "alert('test');", + "console.log('test');" + ].join("\n"); + const config = { + rules: { + "no-alert": 1, + "no-console": 1 + } + }; + const messages = linter.verify(code, config, filename); + + assert.equal(messages.length, 2); + assert.equal(messages[0].ruleId, "no-alert"); + assert.equal(messages[1].ruleId, "no-console"); + }); }); });