Skip to content

Commit

Permalink
Fix: shebang error in eslint-disable-new-line; add tests (fixes #9238) (
Browse files Browse the repository at this point in the history
  • Loading branch information
i-ron-y authored and not-an-aardvark committed Sep 8, 2017
1 parent 8f6546c commit 7ba46e6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/linter.js
Expand Up @@ -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);
Expand Down
41 changes: 40 additions & 1 deletion tests/lib/linter.js
Expand Up @@ -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');",
Expand Down Expand Up @@ -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 */",
Expand All @@ -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");
});
});
});

Expand Down

0 comments on commit 7ba46e6

Please sign in to comment.