2 * @fileoverview Tests for apply-disable-directives
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const assert
= require("chai").assert
;
13 const applyDisableDirectives
= require("../../../lib/linter/apply-disable-directives");
15 //-----------------------------------------------------------------------------
17 //-----------------------------------------------------------------------------
20 * Creates a ParentComment for a given range.
21 * @param {[number, number]} range total range of the comment
22 * @param {string} value String value of the comment
23 * @param {string[]} ruleIds Rule IDs reported in the value
24 * @returns {ParentComment} Test-ready ParentComment object.
26 function createParentComment(range
, value
, ruleIds
= []) {
37 column
: value
? value
.length
: 10
46 //------------------------------------------------------------------------------
48 //------------------------------------------------------------------------------
50 describe("apply-disable-directives", () => {
51 describe("/* eslint-disable */ comments without rules", () => {
52 it("keeps problems before the comment on the same line", () => {
53 assert
.deepStrictEqual(
54 applyDisableDirectives({
55 directives
: [{ parentComment
: createParentComment([0, 7]), type
: "disable", line
: 1, column
: 8, ruleId
: null, justification
: "justification" }],
56 problems
: [{ line
: 1, column
: 7, ruleId
: "foo" }]
58 [{ line
: 1, column
: 7, ruleId
: "foo" }]
62 it("keeps problems on a previous line before the comment", () => {
63 assert
.deepStrictEqual(
64 applyDisableDirectives({
65 directives
: [{ parentComment
: createParentComment([21, 27]), type
: "disable", line
: 2, column
: 1, ruleId
: null, justification
: "justification" }],
66 problems
: [{ line
: 1, column
: 10, ruleId
: "foo" }]
68 [{ line
: 1, column
: 10, ruleId
: "foo" }]
72 it("filters problems at the same location as the comment", () => {
73 assert
.deepStrictEqual(
74 applyDisableDirectives({
75 directives
: [{ type
: "disable", line
: 1, column
: 8, ruleId
: null, justification
: "justification" }],
76 problems
: [{ line
: 1, column
: 8, ruleId
: null }]
78 [{ line
: 1, column
: 8, ruleId
: null, suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
82 it("filters out problems after the comment on the same line", () => {
83 assert
.deepStrictEqual(
84 applyDisableDirectives({
85 directives
: [{ type
: "disable", line
: 1, column
: 8, ruleId
: null, justification
: "justification" }],
86 problems
: [{ line
: 1, column
: 10, ruleId
: "foo" }]
88 [{ line
: 1, column
: 10, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
92 it("filters out problems on a later line than the comment", () => {
93 assert
.deepStrictEqual(
94 applyDisableDirectives({
95 directives
: [{ type
: "disable", line
: 1, column
: 8, ruleId
: null, justification
: "justification" }],
96 problems
: [{ line
: 2, column
: 3, ruleId
: "foo" }]
98 [{ line
: 2, column
: 3, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
103 describe("/* eslint-disable */ comments with rules", () => {
104 it("filters problems after the comment that have the same ruleId", () => {
105 assert
.deepStrictEqual(
106 applyDisableDirectives({
107 directives
: [{ type
: "disable", line
: 1, column
: 8, ruleId
: "foo", justification
: "justification" }],
108 problems
: [{ line
: 2, column
: 3, ruleId
: "foo" }]
110 [{ line
: 2, column
: 3, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
114 it("filters problems in the same location as the comment that have the same ruleId", () => {
115 assert
.deepStrictEqual(
116 applyDisableDirectives({
117 directives
: [{ type
: "disable", line
: 1, column
: 8, ruleId
: "foo", justification
: "justification" }],
118 problems
: [{ line
: 1, column
: 8, ruleId
: "foo" }]
120 [{ line
: 1, column
: 8, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
124 it("keeps problems after the comment that have a different ruleId", () => {
125 assert
.deepStrictEqual(
126 applyDisableDirectives({
128 parentComment
: createParentComment([26, 29]),
133 justification
: "justification"
135 problems
: [{ line
: 2, column
: 3, ruleId
: "not-foo" }]
137 [{ line
: 2, column
: 3, ruleId
: "not-foo" }]
141 it("keeps problems before the comment that have the same ruleId", () => {
142 assert
.deepStrictEqual(
143 applyDisableDirectives({
145 parentComment
: createParentComment([7, 31]),
151 problems
: [{ line
: 1, column
: 7, ruleId
: "foo" }]
153 [{ line
: 1, column
: 7, ruleId
: "foo" }]
158 describe("eslint-enable comments without rules", () => {
159 it("keeps problems after the eslint-enable comment", () => {
160 assert
.deepStrictEqual(
161 applyDisableDirectives({
164 parentComment
: createParentComment([0, 26]),
172 parentComment
: createParentComment([27, 45]),
180 problems
: [{ line
: 1, column
: 27, ruleId
: "foo" }]
182 [{ line
: 1, column
: 27, ruleId
: "foo" }]
186 it("keeps problems in the same location as the eslint-enable comment", () => {
187 assert
.deepStrictEqual(
188 applyDisableDirectives({
191 parentComment
: createParentComment([0, 25]),
199 parentComment
: createParentComment([26, 40]),
207 problems
: [{ line
: 1, column
: 26, ruleId
: "foo" }]
209 [{ line
: 1, column
: 26, ruleId
: "foo" }]
213 it("filters out problems before the eslint-enable comment", () => {
214 assert
.deepStrictEqual(
215 applyDisableDirectives({
217 { type
: "disable", line
: 1, column
: 1, ruleId
: null, justification
: "j1" },
218 { type
: "enable", line
: 1, column
: 26, ruleId
: null, justification
: "j2" }
220 problems
: [{ line
: 1, column
: 3, ruleId
: "foo" }]
222 [{ line
: 1, column
: 3, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "j1" }] }]
226 it("filter out problems if disable all then enable foo and then disable foo", () => {
227 assert
.deepStrictEqual(
228 applyDisableDirectives({
231 parentComment
: createParentComment([0, 20]),
239 parentComment
: createParentComment([26, 44]),
247 parentComment
: createParentComment([45, 63]),
255 problems
: [{ line
: 3, column
: 3, ruleId
: "foo" }]
257 [{ line
: 3, column
: 3, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "j3" }] }]
261 it("filter out problems if disable all then enable foo and then disable all", () => {
262 assert
.deepStrictEqual(
263 applyDisableDirectives({
266 parentComment
: createParentComment([0, 20]),
274 parentComment
: createParentComment([21, 44]),
282 parentComment
: createParentComment([45, 63]),
290 problems
: [{ line
: 3, column
: 3, ruleId
: "foo" }]
292 [{ line
: 3, column
: 3, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "j3" }] }]
296 it("keeps problems before the eslint-enable comment if there is no corresponding disable comment", () => {
297 assert
.deepStrictEqual(
298 applyDisableDirectives({
301 parentComment
: createParentComment([0, 20]),
309 parentComment
: createParentComment([25, 44]),
317 problems
: [{ line
: 1, column
: 3, ruleId
: "not-foo" }]
319 [{ line
: 1, column
: 3, ruleId
: "not-foo" }]
324 describe("eslint-enable comments with rules", () => {
325 it("keeps problems after the comment that have the same ruleId as the eslint-enable comment", () => {
326 assert
.deepStrictEqual(
327 applyDisableDirectives({
330 parentComment
: createParentComment([0, 20]),
338 parentComment
: createParentComment([21, 44]),
346 problems
: [{ line
: 2, column
: 4, ruleId
: "foo" }]
348 [{ line
: 2, column
: 4, ruleId
: "foo" }]
352 it("keeps problems in the same location as the comment that have the same ruleId as the eslint-enable comment", () => {
353 assert
.deepStrictEqual(
354 applyDisableDirectives({
357 parentComment
: createParentComment([0, 20]),
365 parentComment
: createParentComment([21, 44]),
373 problems
: [{ line
: 2, column
: 1, ruleId
: "foo" }]
375 [{ line
: 2, column
: 1, ruleId
: "foo" }]
379 it("filters problems after the comment that have a different ruleId as the eslint-enable comment", () => {
380 assert
.deepStrictEqual(
381 applyDisableDirectives({
384 parentComment
: createParentComment([0, 20]),
392 parentComment
: createParentComment([21, 44]),
400 problems
: [{ line
: 2, column
: 4, ruleId
: "not-foo" }]
402 [{ line
: 2, column
: 4, ruleId
: "not-foo", suppressions
: [{ kind
: "directive", justification
: "j1" }] }]
406 it("reenables reporting correctly even when followed by another enable comment", () => {
407 assert
.deepStrictEqual(
408 applyDisableDirectives({
410 { type
: "disable", line
: 1, column
: 1, ruleId
: null, justification
: "j1" },
411 { type
: "enable", line
: 1, column
: 22, ruleId
: "foo", justification
: "j2" },
412 { type
: "enable", line
: 1, column
: 46, ruleId
: "bar", justification
: "j3" }
415 { line
: 1, column
: 10, ruleId
: "foo" },
416 { line
: 1, column
: 10, ruleId
: "bar" },
417 { line
: 1, column
: 30, ruleId
: "foo" },
418 { line
: 1, column
: 30, ruleId
: "bar" },
419 { line
: 1, column
: 50, ruleId
: "foo" },
420 { line
: 1, column
: 50, ruleId
: "bar" }
424 { line
: 1, column
: 10, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "j1" }] },
425 { line
: 1, column
: 10, ruleId
: "bar", suppressions
: [{ kind
: "directive", justification
: "j1" }] },
426 { line
: 1, column
: 30, ruleId
: "foo" },
427 { line
: 1, column
: 30, ruleId
: "bar", suppressions
: [{ kind
: "directive", justification
: "j1" }] },
428 { line
: 1, column
: 50, ruleId
: "foo" },
429 { line
: 1, column
: 50, ruleId
: "bar" }
435 describe("eslint-disable-line comments without rules", () => {
436 it("keeps problems on a previous line", () => {
437 assert
.deepStrictEqual(
438 applyDisableDirectives({
440 parentComment
: createParentComment([6, 27]),
441 type
: "disable-line",
445 justification
: "justification"
447 problems
: [{ line
: 1, column
: 5, ruleId
: "foo" }]
449 [{ line
: 1, column
: 5, ruleId
: "foo" }]
453 it("filters problems before the comment on the same line", () => {
454 assert
.deepStrictEqual(
455 applyDisableDirectives({
457 parentComment
: createParentComment([7, 28]),
458 type
: "disable-line",
462 justification
: "justification"
464 problems
: [{ line
: 1, column
: 1, ruleId
: "foo" }]
466 [{ line
: 1, column
: 1, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
470 it("filters problems after the comment on the same line", () => {
471 assert
.deepStrictEqual(
472 applyDisableDirectives({
474 parentComment
: createParentComment([7, 28]),
475 type
: "disable-line",
479 justification
: "justification"
481 problems
: [{ line
: 1, column
: 10, ruleId
: "foo" }]
483 [{ line
: 1, column
: 10, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
487 it("keeps problems on a following line", () => {
488 assert
.deepStrictEqual(
489 applyDisableDirectives({
491 parentComment
: createParentComment([7, 34]),
492 type
: "disable-line",
496 justification
: "justification"
498 problems
: [{ line
: 2, column
: 1, ruleId
: "foo" }]
500 [{ line
: 2, column
: 1, ruleId
: "foo" }]
505 describe("eslint-disable-line comments with rules", () => {
506 it("filters problems on the current line that match the ruleId", () => {
507 assert
.deepStrictEqual(
508 applyDisableDirectives({
510 parentComment
: createParentComment([7, 34]),
511 type
: "disable-line",
515 justification
: "justification"
517 problems
: [{ line
: 1, column
: 2, ruleId
: "foo" }]
519 [{ line
: 1, column
: 2, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
523 it("keeps problems on the current line that do not match the ruleId", () => {
524 assert
.deepStrictEqual(
525 applyDisableDirectives({
527 parentComment
: createParentComment([0, 27]),
528 type
: "disable-line",
532 justification
: "justification"
534 problems
: [{ line
: 1, column
: 2, ruleId
: "not-foo" }]
536 [{ line
: 1, column
: 2, ruleId
: "not-foo" }]
540 it("filters problems on the current line that do not match the ruleId if preceded by a disable comment", () => {
541 assert
.deepStrictEqual(
542 applyDisableDirectives({
545 parentComment
: createParentComment([0, 21]),
553 parentComment
: createParentComment([24, 28]),
554 type
: "disable-line",
561 problems
: [{ line
: 1, column
: 5, ruleId
: "not-foo" }]
563 [{ line
: 1, column
: 5, ruleId
: "not-foo", suppressions
: [{ kind
: "directive", justification
: "j1" }] }]
567 it("handles consecutive comments appropriately", () => {
568 assert
.deepStrictEqual(
569 applyDisableDirectives({
572 parentComment
: createParentComment([7, 34]),
573 type
: "disable-line",
580 parentComment
: createParentComment([38, 73]),
581 type
: "disable-line",
588 parentComment
: createParentComment([76, 111]),
589 type
: "disable-line",
596 parentComment
: createParentComment([114, 149]),
597 type
: "disable-line",
604 parentComment
: createParentComment([152, 187]),
605 type
: "disable-line",
612 parentComment
: createParentComment([190, 225]),
613 type
: "disable-line",
620 problems
: [{ line
: 2, column
: 1, ruleId
: "foo" }]
622 [{ line
: 2, column
: 1, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "j2" }] }]
627 describe("eslint-disable-next-line comments without rules", () => {
628 it("filters problems on the next line", () => {
629 assert
.deepStrictEqual(
630 applyDisableDirectives({
632 parentComment
: createParentComment([0, 31]),
633 type
: "disable-next-line",
637 justification
: "justification"
639 problems
: [{ line
: 2, column
: 3, ruleId
: "foo" }]
641 [{ line
: 2, column
: 3, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
645 it("keeps problems on the same line", () => {
646 assert
.deepStrictEqual(
647 applyDisableDirectives({
649 parentComment
: createParentComment([0, 31]),
650 type
: "disable-next-line",
655 problems
: [{ line
: 1, column
: 3, ruleId
: "foo" }]
657 [{ line
: 1, column
: 3, ruleId
: "foo" }]
661 it("keeps problems after the next line", () => {
662 assert
.deepStrictEqual(
663 applyDisableDirectives({
665 parentComment
: createParentComment([0, 31]),
666 type
: "disable-next-line",
670 justification
: "justification"
672 problems
: [{ line
: 3, column
: 3, ruleId
: "foo" }]
674 [{ line
: 3, column
: 3, ruleId
: "foo" }]
678 it("filters problems on the next line even if there is an eslint-enable comment on the same line", () => {
679 assert
.deepStrictEqual(
680 applyDisableDirectives({
682 { parentComment
: createParentComment([0, 31]), type
: "disable-next-line", line
: 1, column
: 1, ruleId
: null, justification
: "j1" },
683 { type
: "enable", line
: 1, column
: 5, ruleId
: null, justification
: "j2" }
685 problems
: [{ line
: 2, column
: 2, ruleId
: "foo" }]
687 [{ line
: 2, column
: 2, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "j1" }] }]
692 describe("eslint-disable-next-line comments with rules", () => {
693 it("filters problems on the next line that match the ruleId", () => {
694 assert
.deepStrictEqual(
695 applyDisableDirectives({
696 directives
: [{ type
: "disable-next-line", line
: 1, column
: 1, ruleId
: "foo", justification
: "justification" }],
697 problems
: [{ line
: 2, column
: 1, ruleId
: "foo" }]
699 [{ line
: 2, column
: 1, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
703 it("keeps problems on the next line that do not match the ruleId", () => {
704 assert
.deepStrictEqual(
705 applyDisableDirectives({
707 parentComment
: createParentComment([0, 31]),
708 type
: "disable-next-line",
712 justification
: "justification"
714 problems
: [{ line
: 2, column
: 1, ruleId
: "not-foo" }]
716 [{ line
: 2, column
: 1, ruleId
: "not-foo" }]
721 describe("unrecognized directive types", () => {
722 it("throws a TypeError when it encounters an unrecognized directive", () => {
725 applyDisableDirectives({
726 directives
: [{ type
: "foo", line
: 1, column
: 4, ruleId
: "foo", justification
: "justification" }],
729 "Unrecognized directive type 'foo'"
734 describe("unused directives", () => {
735 it("Adds a problem for /* eslint-disable */", () => {
736 assert
.deepStrictEqual(
737 applyDisableDirectives({
739 parentComment
: createParentComment([0, 20]),
743 justification
: "justification"
746 reportUnusedDisableDirectives
: "error"
750 message
: "Unused eslint-disable directive (no problems were reported).",
763 it("Does not fix a problem for /* eslint-disable */ when disableFixes is enabled", () => {
764 assert
.deepStrictEqual(
765 applyDisableDirectives({
767 parentComment
: createParentComment([0, 20]),
771 justification
: "justification"
775 reportUnusedDisableDirectives
: "error"
779 message
: "Unused eslint-disable directive (no problems were reported).",
788 it("Does not add a problem for /* eslint-disable */ /* (problem) */", () => {
789 assert
.deepStrictEqual(
790 applyDisableDirectives({
791 directives
: [{ type
: "disable", line
: 1, column
: 1, ruleId
: null, justification
: "justification" }],
792 problems
: [{ line
: 2, column
: 1, ruleId
: "foo" }],
793 reportUnusedDisableDirectives
: "error"
795 [{ line
: 2, column
: 1, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
799 it("Adds a problem for /* eslint-disable foo */", () => {
800 assert
.deepStrictEqual(
801 applyDisableDirectives({
803 parentComment
: createParentComment([0, 21]),
808 justification
: "justification"
811 reportUnusedDisableDirectives
: "error"
815 message
: "Unused eslint-disable directive (no problems were reported from 'foo').",
828 it("Adds a problem for /* eslint-disable foo */ /* (problem from another rule) */", () => {
829 assert
.deepStrictEqual(
830 applyDisableDirectives({
832 parentComment
: createParentComment([0, 24]),
837 justification
: "justification"
839 problems
: [{ line
: 1, column
: 20, ruleId
: "not-foo" }],
840 reportUnusedDisableDirectives
: "error"
845 message
: "Unused eslint-disable directive (no problems were reported from 'foo').",
864 it("Adds a problem for /* (problem from foo) */ /* eslint-disable */ /* eslint-enable foo */", () => {
865 assert
.deepStrictEqual(
866 applyDisableDirectives({
869 parentComment
: createParentComment([0, 21]),
877 parentComment
: createParentComment([0, 21]),
885 problems
: [{ line
: 1, column
: 2, ruleId
: "foo" }],
886 reportUnusedDisableDirectives
: "error"
896 message
: "Unused eslint-disable directive (no problems were reported).",
910 it("Adds a problem for /* eslint-disable */ /* eslint-enable */", () => {
911 assert
.deepStrictEqual(
912 applyDisableDirectives({
915 parentComment
: createParentComment([0, 20]),
923 parentComment
: createParentComment([21, 41]),
932 reportUnusedDisableDirectives
: "error"
936 message
: "Unused eslint-disable directive (no problems were reported).",
949 it("Adds two problems for /* eslint-disable */ /* eslint-disable */", () => {
950 assert
.deepStrictEqual(
951 applyDisableDirectives({
954 parentComment
: createParentComment([0, 21]),
962 parentComment
: createParentComment([21, 42]),
971 reportUnusedDisableDirectives
: "error"
976 message
: "Unused eslint-disable directive (no problems were reported).",
988 message
: "Unused eslint-disable directive (no problems were reported).",
1002 it("Adds a problem for /* eslint-disable */ /* eslint-disable */ /* (problem) */", () => {
1003 assert
.deepStrictEqual(
1004 applyDisableDirectives({
1007 parentComment
: createParentComment([0, 21]),
1015 parentComment
: createParentComment([22, 45]),
1023 problems
: [{ line
: 3, column
: 1, ruleId
: "foo" }],
1024 reportUnusedDisableDirectives
: "error"
1029 message
: "Unused eslint-disable directive (no problems were reported).",
1044 { kind
: "directive", justification
: "j1" },
1045 { kind
: "directive", justification
: "j2" }
1052 it("Adds a problem for /* eslint-disable foo */ /* eslint-disable */ /* (problem from foo) */", () => {
1053 assert
.deepStrictEqual(
1054 applyDisableDirectives({
1057 parentComment
: createParentComment([0, 21]),
1065 parentComment
: createParentComment([22, 45]),
1073 problems
: [{ line
: 3, column
: 1, ruleId
: "foo" }],
1074 reportUnusedDisableDirectives
: "error"
1079 message
: "Unused eslint-disable directive (no problems were reported from 'foo').",
1094 { kind
: "directive", justification
: "j1" },
1095 { kind
: "directive", justification
: "j2" }
1102 it("Does not add a problem for /* eslint-disable foo */ /* (problem from foo) */", () => {
1103 assert
.deepStrictEqual(
1104 applyDisableDirectives({
1105 directives
: [{ type
: "disable", line
: 1, column
: 1, ruleId
: "foo", justification
: "justification" }],
1106 problems
: [{ line
: 1, column
: 6, ruleId
: "foo" }],
1107 reportUnusedDisableDirectives
: "error"
1109 [{ line
: 1, column
: 6, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
1113 it("Adds a problem for /* eslint-disable */ /* eslint-disable foo */ /* (problem from foo) */", () => {
1114 assert
.deepStrictEqual(
1115 applyDisableDirectives({
1118 parentComment
: createParentComment([0, 21]),
1126 parentComment
: createParentComment([22, 45]),
1134 problems
: [{ line
: 3, column
: 1, ruleId
: "foo" }],
1135 reportUnusedDisableDirectives
: "error"
1140 message
: "Unused eslint-disable directive (no problems were reported).",
1155 { kind
: "directive", justification
: "j1" },
1156 { kind
: "directive", justification
: "j2" }
1163 it("Adds a problem for /* eslint-disable */ /* eslint-disable foo */ /* (problem from another rule) */", () => {
1164 assert
.deepStrictEqual(
1165 applyDisableDirectives({
1168 parentComment
: createParentComment([0, 20]),
1176 parentComment
: createParentComment([21, 45]),
1184 problems
: [{ line
: 3, column
: 1, ruleId
: "bar" }],
1185 reportUnusedDisableDirectives
: "error"
1190 message
: "Unused eslint-disable directive (no problems were reported from 'foo').",
1204 suppressions
: [{ kind
: "directive", justification
: "j1" }]
1210 it("Adds a problem for /* eslint-disable foo */ /* eslint-enable foo */ /* (problem from foo) */", () => {
1211 assert
.deepStrictEqual(
1212 applyDisableDirectives({
1215 parentComment
: createParentComment([0, 20]),
1223 parentComment
: createParentComment([25, 46]),
1231 problems
: [{ line
: 1, column
: 30, ruleId
: "foo" }],
1232 reportUnusedDisableDirectives
: "error"
1237 message
: "Unused eslint-disable directive (no problems were reported from 'foo').",
1256 it("Adds a problem for /* eslint-disable foo */ /* eslint-enable */ /* (problem from foo) */", () => {
1257 assert
.deepStrictEqual(
1258 applyDisableDirectives({
1261 parentComment
: createParentComment([0, 24]),
1269 parentComment
: createParentComment([25, 49]),
1277 problems
: [{ line
: 1, column
: 30, ruleId
: "foo" }],
1278 reportUnusedDisableDirectives
: "error"
1283 message
: "Unused eslint-disable directive (no problems were reported from 'foo').",
1302 it("Adds two problems for /* eslint-disable */ /* eslint-disable foo */ /* eslint-enable foo */ /* (problem from foo) */", () => {
1303 assert
.deepStrictEqual(
1304 applyDisableDirectives({
1307 parentComment
: createParentComment([0, 21]),
1315 parentComment
: createParentComment([22, 45]),
1323 parentComment
: createParentComment([46, 69]),
1331 problems
: [{ line
: 4, column
: 1, ruleId
: "foo" }],
1332 reportUnusedDisableDirectives
: "error"
1337 message
: "Unused eslint-disable directive (no problems were reported).",
1349 message
: "Unused eslint-disable directive (no problems were reported from 'foo').",
1368 it("Adds a problem for // eslint-disable-line", () => {
1369 assert
.deepStrictEqual(
1370 applyDisableDirectives({
1372 parentComment
: createParentComment([0, 22]),
1373 type
: "disable-line",
1377 justification
: "justification"
1380 reportUnusedDisableDirectives
: "error"
1385 message
: "Unused eslint-disable directive (no problems were reported).",
1400 it("Does not add a problem for // eslint-disable-line (problem)", () => {
1401 assert
.deepStrictEqual(
1402 applyDisableDirectives({
1403 directives
: [{ type
: "disable-line", line
: 1, column
: 1, ruleId
: null, justification
: "justification" }],
1404 problems
: [{ line
: 1, column
: 10, ruleId
: "foo" }],
1405 reportUnusedDisableDirectives
: "error"
1407 [{ line
: 1, column
: 10, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
1411 it("Adds a problem for // eslint-disable-next-line", () => {
1412 assert
.deepStrictEqual(
1413 applyDisableDirectives({
1415 parentComment
: createParentComment([0, 27]),
1416 type
: "disable-next-line",
1420 justification
: "justification"
1423 reportUnusedDisableDirectives
: "error"
1428 message
: "Unused eslint-disable directive (no problems were reported).",
1442 it("Does not add a problem for // eslint-disable-next-line \\n (problem)", () => {
1443 assert
.deepStrictEqual(
1444 applyDisableDirectives({
1445 directives
: [{ type
: "disable-next-line", line
: 1, column
: 1, ruleId
: null, justification
: "justification" }],
1446 problems
: [{ line
: 2, column
: 10, ruleId
: "foo" }],
1447 reportUnusedDisableDirectives
: "error"
1449 [{ line
: 2, column
: 10, ruleId
: "foo", suppressions
: [{ kind
: "directive", justification
: "justification" }] }]
1453 it("adds two problems for /* eslint-disable */ // eslint-disable-line", () => {
1454 assert
.deepStrictEqual(
1455 applyDisableDirectives({
1457 { parentComment
: createParentComment([0, 20]), type
: "disable", line
: 1, column
: 1, ruleId
: null },
1458 { parentComment
: createParentComment([20, 43]), type
: "disable-line", line
: 1, column
: 22, ruleId
: null }
1461 reportUnusedDisableDirectives
: "error"
1466 message
: "Unused eslint-disable directive (no problems were reported).",
1478 message
: "Unused eslint-disable directive (no problems were reported).",
1492 it("Does not add problems when reportUnusedDisableDirectives: \"off\" is used", () => {
1493 assert
.deepStrictEqual(
1494 applyDisableDirectives({
1496 parentComment
: createParentComment([0, 27]),
1497 type
: "disable-next-line",
1501 justification
: "justification"
1504 reportUnusedDisableDirectives
: "off"
1511 describe("unused rules within directives", () => {
1512 it("Adds a problem for /* eslint-disable used, unused */", () => {
1513 const parentComment
= createParentComment([0, 32], " eslint-disable used, unused ", ["used", "unused"]);
1515 assert
.deepStrictEqual(
1516 applyDisableDirectives({
1535 problems
: [{ line
: 2, column
: 1, ruleId
: "used" }],
1536 reportUnusedDisableDirectives
: "error"
1541 message
: "Unused eslint-disable directive (no problems were reported from 'unused').",
1555 suppressions
: [{ kind
: "directive", justification
: "j1" }]
1560 it("Adds a problem for /* eslint-disable used , unused , -- unused and used are ok */", () => {
1561 const parentComment
= createParentComment([0, 62], " eslint-disable used , unused , -- unused and used are ok ", ["used", "unused"]);
1563 assert
.deepStrictEqual(
1564 applyDisableDirectives({
1583 problems
: [{ line
: 2, column
: 1, ruleId
: "used" }],
1584 reportUnusedDisableDirectives
: "error"
1589 message
: "Unused eslint-disable directive (no problems were reported from 'unused').",
1603 suppressions
: [{ kind
: "directive", justification
: "j1" }]
1609 it("Adds a problem for /* eslint-disable unused, used */", () => {
1610 const parentComment
= createParentComment([0, 32], " eslint-disable unused, used ", ["unused", "used"]);
1612 assert
.deepStrictEqual(
1613 applyDisableDirectives({
1632 problems
: [{ line
: 2, column
: 1, ruleId
: "used" }],
1633 reportUnusedDisableDirectives
: "error"
1638 message
: "Unused eslint-disable directive (no problems were reported from 'unused').",
1652 suppressions
: [{ kind
: "directive", justification
: "j2" }]
1658 it("Adds a problem for /* eslint-disable unused,, ,, used */", () => {
1659 const parentComment
= createParentComment([0, 37], " eslint-disable unused,, ,, used ", ["unused", "used"]);
1661 assert
.deepStrictEqual(
1662 applyDisableDirectives({
1681 problems
: [{ line
: 2, column
: 1, ruleId
: "used" }],
1682 reportUnusedDisableDirectives
: "error"
1687 message
: "Unused eslint-disable directive (no problems were reported from 'unused').",
1701 suppressions
: [{ kind
: "directive", justification
: "j2" }]
1707 it("Adds a problem for /* eslint-disable unused-1, unused-2, used */", () => {
1708 const parentComment
= createParentComment([0, 45], " eslint-disable unused-1, unused-2, used ", ["unused-1", "unused-2", "used"]);
1710 assert
.deepStrictEqual(
1711 applyDisableDirectives({
1738 problems
: [{ line
: 2, column
: 1, ruleId
: "used" }],
1739 reportUnusedDisableDirectives
: "error"
1744 message
: "Unused eslint-disable directive (no problems were reported from 'unused-1').",
1756 message
: "Unused eslint-disable directive (no problems were reported from 'unused-2').",
1770 suppressions
: [{ kind
: "directive", justification
: "j3" }]
1776 it("Adds a problem for /* eslint-disable unused-1, unused-2, used, unused-3 */", () => {
1777 const parentComment
= createParentComment([0, 55], " eslint-disable unused-1, unused-2, used, unused-3 ", ["unused-1", "unused-2", "used", "unused-3"]);
1779 assert
.deepStrictEqual(
1780 applyDisableDirectives({
1815 problems
: [{ line
: 2, column
: 1, ruleId
: "used" }],
1816 reportUnusedDisableDirectives
: "error"
1821 message
: "Unused eslint-disable directive (no problems were reported from 'unused-1').",
1833 message
: "Unused eslint-disable directive (no problems were reported from 'unused-2').",
1845 message
: "Unused eslint-disable directive (no problems were reported from 'unused-3').",
1859 suppressions
: [{ kind
: "directive", justification
: "j3" }]
1865 it("Adds a problem for /* eslint-disable unused-1, unused-2 */", () => {
1866 const parentComment
= createParentComment([0, 39], " eslint-disable unused-1, unused-2 ", ["unused-1", "unused-2"]);
1868 assert
.deepStrictEqual(
1869 applyDisableDirectives({
1889 reportUnusedDisableDirectives
: "error"
1894 message
: "Unused eslint-disable directive (no problems were reported from 'unused-1' or 'unused-2').",
1908 it("Adds a problem for /* eslint-disable unused-1, unused-2, unused-3 */", () => {
1909 const parentComment
= createParentComment([0, 49], " eslint-disable unused-1, unused-2, unused-3 ", ["unused-1", "unused-2", "unused-3"]);
1911 assert
.deepStrictEqual(
1912 applyDisableDirectives({
1937 reportUnusedDisableDirectives
: "error"
1942 message
: "Unused eslint-disable directive (no problems were reported from 'unused-1', 'unused-2', or 'unused-3').",
1956 it("Adds a problem for /* eslint-disable foo */ \\n (problem from foo and bar) // eslint-disable-line foo, bar", () => {
1957 assert
.deepStrictEqual(
1958 applyDisableDirectives({
1961 parentComment
: createParentComment([0, 29], " eslint-disable foo ", ["foo"]),
1969 parentComment
: createParentComment([41, 81], " eslint-disable-line foo, bar", ["foo", "bar"]),
1971 type
: "disable-line",
1977 parentComment
: createParentComment([41, 81], " eslint-disable-line foo, bar ", ["foo", "bar"]),
1979 type
: "disable-line",
1986 { line
: 2, column
: 1, ruleId
: "bar" },
1987 { line
: 2, column
: 6, ruleId
: "foo" }
1989 reportUnusedDisableDirectives
: "error"
1996 suppressions
: [{ kind
: "directive", justification
: "j2" }]
2003 { kind
: "directive", justification
: "j1" },
2004 { kind
: "directive", justification
: "j2" }
2009 message
: "Unused eslint-disable directive (no problems were reported from 'foo').",