Skip to content

Commit

Permalink
checking that eslint-disable-line is on one line
Browse files Browse the repository at this point in the history
  • Loading branch information
erindepew committed Jan 31, 2018
1 parent 0b047bc commit 248359d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/linter.js
Expand Up @@ -329,10 +329,13 @@ function modifyConfigsFromComments(filename, ast, config, ruleMapper) {
break;

case "eslint-disable-line":
[].push.apply(disableDirectives, createDisableDirectives("disable-line", comment.loc.start, value));
if (comment.loc.start.line === comment.loc.end.line) {
[].push.apply(disableDirectives, createDisableDirectives("disable-line", comment.loc.start, value));
}
break;

case "eslint-disable-next-line":

[].push.apply(disableDirectives, createDisableDirectives("disable-next-line", comment.loc.start, value));
break;

Expand Down
45 changes: 45 additions & 0 deletions tests/lib/linter.js
Expand Up @@ -1923,6 +1923,51 @@ describe("Linter", () => {
assert.strictEqual(messages[0].ruleId, "no-console");
});

it("should report a violation", () => {
const code = [
"alert('test'); /* eslint-disable-line ",
"no-alert */",
"console.log('test'); /* eslint-disable-line */"
].join("\n");
const config = {
rules: {
"no-alert": 1,
quotes: [1, "double"],
semi: [1, "always"],
"no-console": 1
}
};

const messages = linter.verify(code, config, filename);

assert.strictEqual(messages.length, 2);

assert.strictEqual(messages[0].ruleId, "no-alert");
assert.strictEqual(messages[1].ruleId, "quotes");
});
it("should report a violation", () => {
const code = [
"/* eslint-disable-line",
"no-alert */ alert('test');",
"console.log('test'); /* eslint-disable-line */"
].join("\n");
const config = {
rules: {
"no-alert": 1,
quotes: [1, "double"],
semi: [1, "always"],
"no-console": 1
}
};

const messages = linter.verify(code, config, filename);

assert.strictEqual(messages.length, 2);

assert.strictEqual(messages[0].ruleId, "no-alert");
assert.strictEqual(messages[1].ruleId, "quotes");
});

it("should not report a violation", () => {
const code = [
"alert('test'); // eslint-disable-line no-alert",
Expand Down

0 comments on commit 248359d

Please sign in to comment.