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

Fix: shebang error in eslint-disable-new-line; add tests (fixes #9238) #9240

Merged
merged 1 commit into from Sep 8, 2017
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.js
Expand Up @@ -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);
Expand Down
41 changes: 40 additions & 1 deletion tests/lib/linter.js
Expand Up @@ -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');",
Expand Down Expand Up @@ -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 */",
Expand All @@ -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");
});
});
});

Expand Down