diff --git a/lib/linter.js b/lib/linter.js index e36fa995aa1e..a9bf2bf25f73 100755 --- a/lib/linter.js +++ b/lib/linter.js @@ -301,7 +301,7 @@ function modifyConfigsFromComments(filename, ast, config, linterContext) { const problems = []; const disableDirectives = []; - 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 1d432ea3d348..d3f66531576d 100644 --- a/tests/lib/linter.js +++ b/tests/lib/linter.js @@ -1869,6 +1869,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');", @@ -1909,7 +1929,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 */", @@ -1929,6 +1949,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"); + }); }); });