Skip to content

Commit

Permalink
add more test and identifier for all rules
Browse files Browse the repository at this point in the history
  • Loading branch information
gyandeeps committed Sep 17, 2017
1 parent 8093c02 commit 22bf943
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/util/apply-disable-directives.js
Expand Up @@ -7,6 +7,8 @@

const lodash = require("lodash");

const ALL_RULE_IDENTIFIER = Symbol("all");

/**
* Compares the locations of two objects in a source file
* @param {{line: number, column: number}} itemA The first object
Expand Down Expand Up @@ -87,11 +89,11 @@ module.exports = options => {

switch (directive.type) {
case "disable-line":
tempDisabledByLine.add(directive.ruleId === null ? "all" : directive.ruleId);
tempDisabledByLine.add(directive.ruleId === null ? ALL_RULE_IDENTIFIER : directive.ruleId);
break;

case "enable-line":
tempDisabledByLine.delete(directive.ruleId === null ? "all" : directive.ruleId);
tempDisabledByLine.delete(directive.ruleId === null ? ALL_RULE_IDENTIFIER : directive.ruleId);
break;

case "disable":
Expand Down Expand Up @@ -122,7 +124,7 @@ module.exports = options => {

if (
enabledRules.has(problem.ruleId) ||
(!tempDisabledByLine.has("all") && !tempDisabledByLine.has(problem.ruleId) &&
(!tempDisabledByLine.has(ALL_RULE_IDENTIFIER) && !tempDisabledByLine.has(problem.ruleId) &&
!globalDisableActive && !disabledRules.has(problem.ruleId))
) {
problems.push(problem);
Expand Down
13 changes: 13 additions & 0 deletions tests/lib/linter.js
Expand Up @@ -2072,6 +2072,19 @@ describe("Linter", () => {
assert.equal(messages.length, 0);
});

it("should report no violation", () => {
const code = [
"/* eslint-disable quotes */",
"console.log(\"foo\");",
"/* eslint-enable quotes */"
].join("\n");
const config = { rules: { quotes: 2 } };

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

assert.equal(messages.length, 0);
});

it("should report a violation", () => {
const code = [
"/*eslint-disable no-alert, no-console */",
Expand Down

0 comments on commit 22bf943

Please sign in to comment.