]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/linter/apply-disable-directives.js
import 8.23.1 source
[pve-eslint.git] / eslint / tests / lib / linter / apply-disable-directives.js
1 /**
2 * @fileoverview Tests for apply-disable-directives
3 * @author Teddy Katz
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const assert = require("chai").assert;
13 const applyDisableDirectives = require("../../../lib/linter/apply-disable-directives");
14
15 //-----------------------------------------------------------------------------
16 // Helpers
17 //-----------------------------------------------------------------------------
18
19 /**
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.
25 */
26 function createParentComment(range, value, ruleIds = []) {
27 return {
28 commentToken: {
29 range,
30 loc: {
31 start: {
32 line: 1,
33 column: 1
34 },
35 end: {
36 line: 1,
37 column: value ? value.length : 10
38 }
39 },
40 value
41 },
42 ruleIds
43 };
44 }
45
46 //------------------------------------------------------------------------------
47 // Tests
48 //------------------------------------------------------------------------------
49
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" }]
57 }),
58 [{ line: 1, column: 7, ruleId: "foo" }]
59 );
60 });
61
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" }]
67 }),
68 [{ line: 1, column: 10, ruleId: "foo" }]
69 );
70 });
71
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 }]
77 }),
78 [{ line: 1, column: 8, ruleId: null, suppressions: [{ kind: "directive", justification: "justification" }] }]
79 );
80 });
81
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" }]
87 }),
88 [{ line: 1, column: 10, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
89 );
90 });
91
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" }]
97 }),
98 [{ line: 2, column: 3, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
99 );
100 });
101 });
102
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" }]
109 }),
110 [{ line: 2, column: 3, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
111 );
112 });
113
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" }]
119 }),
120 [{ line: 1, column: 8, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
121 );
122 });
123
124 it("keeps problems after the comment that have a different ruleId", () => {
125 assert.deepStrictEqual(
126 applyDisableDirectives({
127 directives: [{
128 parentComment: createParentComment([26, 29]),
129 type: "disable",
130 line: 1,
131 column: 1,
132 ruleId: "foo",
133 justification: "justification"
134 }],
135 problems: [{ line: 2, column: 3, ruleId: "not-foo" }]
136 }),
137 [{ line: 2, column: 3, ruleId: "not-foo" }]
138 );
139 });
140
141 it("keeps problems before the comment that have the same ruleId", () => {
142 assert.deepStrictEqual(
143 applyDisableDirectives({
144 directives: [{
145 parentComment: createParentComment([7, 31]),
146 type: "disable",
147 line: 1,
148 column: 8,
149 ruleId: "foo"
150 }],
151 problems: [{ line: 1, column: 7, ruleId: "foo" }]
152 }),
153 [{ line: 1, column: 7, ruleId: "foo" }]
154 );
155 });
156 });
157
158 describe("eslint-enable comments without rules", () => {
159 it("keeps problems after the eslint-enable comment", () => {
160 assert.deepStrictEqual(
161 applyDisableDirectives({
162 directives: [
163 {
164 parentComment: createParentComment([0, 26]),
165 type: "disable",
166 line: 1,
167 column: 1,
168 ruleId: null,
169 justification: "j1"
170 },
171 {
172 parentComment: createParentComment([27, 45]),
173 type: "enable",
174 line: 1,
175 column: 26,
176 ruleId: null,
177 justification: "j2"
178 }
179 ],
180 problems: [{ line: 1, column: 27, ruleId: "foo" }]
181 }),
182 [{ line: 1, column: 27, ruleId: "foo" }]
183 );
184 });
185
186 it("keeps problems in the same location as the eslint-enable comment", () => {
187 assert.deepStrictEqual(
188 applyDisableDirectives({
189 directives: [
190 {
191 parentComment: createParentComment([0, 25]),
192 type: "disable",
193 line: 1,
194 column: 1,
195 ruleId: null,
196 justification: "j1"
197 },
198 {
199 parentComment: createParentComment([26, 40]),
200 type: "enable",
201 line: 1,
202 column: 26,
203 ruleId: null,
204 justification: "j2"
205 }
206 ],
207 problems: [{ line: 1, column: 26, ruleId: "foo" }]
208 }),
209 [{ line: 1, column: 26, ruleId: "foo" }]
210 );
211 });
212
213 it("filters out problems before the eslint-enable comment", () => {
214 assert.deepStrictEqual(
215 applyDisableDirectives({
216 directives: [
217 { type: "disable", line: 1, column: 1, ruleId: null, justification: "j1" },
218 { type: "enable", line: 1, column: 26, ruleId: null, justification: "j2" }
219 ],
220 problems: [{ line: 1, column: 3, ruleId: "foo" }]
221 }),
222 [{ line: 1, column: 3, ruleId: "foo", suppressions: [{ kind: "directive", justification: "j1" }] }]
223 );
224 });
225
226 it("filter out problems if disable all then enable foo and then disable foo", () => {
227 assert.deepStrictEqual(
228 applyDisableDirectives({
229 directives: [
230 {
231 parentComment: createParentComment([0, 20]),
232 type: "disable",
233 line: 1,
234 column: 1,
235 ruleId: null,
236 justification: "j1"
237 },
238 {
239 parentComment: createParentComment([26, 44]),
240 type: "enable",
241 line: 1,
242 column: 26,
243 ruleId: "foo",
244 justification: "j2"
245 },
246 {
247 parentComment: createParentComment([45, 63]),
248 type: "disable",
249 line: 2,
250 column: 1,
251 ruleId: "foo",
252 justification: "j3"
253 }
254 ],
255 problems: [{ line: 3, column: 3, ruleId: "foo" }]
256 }),
257 [{ line: 3, column: 3, ruleId: "foo", suppressions: [{ kind: "directive", justification: "j3" }] }]
258 );
259 });
260
261 it("filter out problems if disable all then enable foo and then disable all", () => {
262 assert.deepStrictEqual(
263 applyDisableDirectives({
264 directives: [
265 {
266 parentComment: createParentComment([0, 20]),
267 type: "disable",
268 line: 1,
269 column: 1,
270 ruleId: null,
271 justification: "j1"
272 },
273 {
274 parentComment: createParentComment([21, 44]),
275 type: "enable",
276 line: 1,
277 column: 26,
278 ruleId: "foo",
279 justification: "j2"
280 },
281 {
282 parentComment: createParentComment([45, 63]),
283 type: "disable",
284 line: 2,
285 column: 1,
286 ruleId: null,
287 justification: "j3"
288 }
289 ],
290 problems: [{ line: 3, column: 3, ruleId: "foo" }]
291 }),
292 [{ line: 3, column: 3, ruleId: "foo", suppressions: [{ kind: "directive", justification: "j3" }] }]
293 );
294 });
295
296 it("keeps problems before the eslint-enable comment if there is no corresponding disable comment", () => {
297 assert.deepStrictEqual(
298 applyDisableDirectives({
299 directives: [
300 {
301 parentComment: createParentComment([0, 20]),
302 type: "disable",
303 line: 1,
304 column: 1,
305 ruleId: "foo",
306 justification: "j1"
307 },
308 {
309 parentComment: createParentComment([25, 44]),
310 type: "enable",
311 line: 1,
312 column: 26,
313 ruleId: null,
314 justification: "j2"
315 }
316 ],
317 problems: [{ line: 1, column: 3, ruleId: "not-foo" }]
318 }),
319 [{ line: 1, column: 3, ruleId: "not-foo" }]
320 );
321 });
322 });
323
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({
328 directives: [
329 {
330 parentComment: createParentComment([0, 20]),
331 type: "disable",
332 line: 1,
333 column: 1,
334 ruleId: null,
335 justification: "j1"
336 },
337 {
338 parentComment: createParentComment([21, 44]),
339 type: "enable",
340 line: 2,
341 column: 1,
342 ruleId: "foo",
343 justification: "j2"
344 }
345 ],
346 problems: [{ line: 2, column: 4, ruleId: "foo" }]
347 }),
348 [{ line: 2, column: 4, ruleId: "foo" }]
349 );
350 });
351
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({
355 directives: [
356 {
357 parentComment: createParentComment([0, 20]),
358 type: "disable",
359 line: 1,
360 column: 1,
361 ruleId: null,
362 justification: "j1"
363 },
364 {
365 parentComment: createParentComment([21, 44]),
366 type: "enable",
367 line: 2,
368 column: 1,
369 ruleId: "foo",
370 justification: "j2"
371 }
372 ],
373 problems: [{ line: 2, column: 1, ruleId: "foo" }]
374 }),
375 [{ line: 2, column: 1, ruleId: "foo" }]
376 );
377 });
378
379 it("filters problems after the comment that have a different ruleId as the eslint-enable comment", () => {
380 assert.deepStrictEqual(
381 applyDisableDirectives({
382 directives: [
383 {
384 parentComment: createParentComment([0, 20]),
385 type: "disable",
386 line: 1,
387 column: 1,
388 ruleId: null,
389 justification: "j1"
390 },
391 {
392 parentComment: createParentComment([21, 44]),
393 type: "enable",
394 line: 2,
395 column: 1,
396 ruleId: "foo",
397 justification: "j2"
398 }
399 ],
400 problems: [{ line: 2, column: 4, ruleId: "not-foo" }]
401 }),
402 [{ line: 2, column: 4, ruleId: "not-foo", suppressions: [{ kind: "directive", justification: "j1" }] }]
403 );
404 });
405
406 it("reenables reporting correctly even when followed by another enable comment", () => {
407 assert.deepStrictEqual(
408 applyDisableDirectives({
409 directives: [
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" }
413 ],
414 problems: [
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" }
421 ]
422 }),
423 [
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" }
430 ]
431 );
432 });
433 });
434
435 describe("eslint-disable-line comments without rules", () => {
436 it("keeps problems on a previous line", () => {
437 assert.deepStrictEqual(
438 applyDisableDirectives({
439 directives: [{
440 parentComment: createParentComment([6, 27]),
441 type: "disable-line",
442 line: 2,
443 column: 1,
444 ruleId: null,
445 justification: "justification"
446 }],
447 problems: [{ line: 1, column: 5, ruleId: "foo" }]
448 }),
449 [{ line: 1, column: 5, ruleId: "foo" }]
450 );
451 });
452
453 it("filters problems before the comment on the same line", () => {
454 assert.deepStrictEqual(
455 applyDisableDirectives({
456 directives: [{
457 parentComment: createParentComment([7, 28]),
458 type: "disable-line",
459 line: 1,
460 column: 8,
461 ruleId: null,
462 justification: "justification"
463 }],
464 problems: [{ line: 1, column: 1, ruleId: "foo" }]
465 }),
466 [{ line: 1, column: 1, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
467 );
468 });
469
470 it("filters problems after the comment on the same line", () => {
471 assert.deepStrictEqual(
472 applyDisableDirectives({
473 directives: [{
474 parentComment: createParentComment([7, 28]),
475 type: "disable-line",
476 line: 1,
477 column: 8,
478 ruleId: null,
479 justification: "justification"
480 }],
481 problems: [{ line: 1, column: 10, ruleId: "foo" }]
482 }),
483 [{ line: 1, column: 10, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
484 );
485 });
486
487 it("keeps problems on a following line", () => {
488 assert.deepStrictEqual(
489 applyDisableDirectives({
490 directives: [{
491 parentComment: createParentComment([7, 34]),
492 type: "disable-line",
493 line: 1,
494 column: 8,
495 ruleId: "foo",
496 justification: "justification"
497 }],
498 problems: [{ line: 2, column: 1, ruleId: "foo" }]
499 }),
500 [{ line: 2, column: 1, ruleId: "foo" }]
501 );
502 });
503 });
504
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({
509 directives: [{
510 parentComment: createParentComment([7, 34]),
511 type: "disable-line",
512 line: 1,
513 column: 8,
514 ruleId: "foo",
515 justification: "justification"
516 }],
517 problems: [{ line: 1, column: 2, ruleId: "foo" }]
518 }),
519 [{ line: 1, column: 2, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
520 );
521 });
522
523 it("keeps problems on the current line that do not match the ruleId", () => {
524 assert.deepStrictEqual(
525 applyDisableDirectives({
526 directives: [{
527 parentComment: createParentComment([0, 27]),
528 type: "disable-line",
529 line: 1,
530 column: 1,
531 ruleId: "foo",
532 justification: "justification"
533 }],
534 problems: [{ line: 1, column: 2, ruleId: "not-foo" }]
535 }),
536 [{ line: 1, column: 2, ruleId: "not-foo" }]
537 );
538 });
539
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({
543 directives: [
544 {
545 parentComment: createParentComment([0, 21]),
546 type: "disable",
547 line: 1,
548 column: 1,
549 ruleId: null,
550 justification: "j1"
551 },
552 {
553 parentComment: createParentComment([24, 28]),
554 type: "disable-line",
555 line: 1,
556 column: 22,
557 ruleId: "foo",
558 justification: "j2"
559 }
560 ],
561 problems: [{ line: 1, column: 5, ruleId: "not-foo" }]
562 }),
563 [{ line: 1, column: 5, ruleId: "not-foo", suppressions: [{ kind: "directive", justification: "j1" }] }]
564 );
565 });
566
567 it("handles consecutive comments appropriately", () => {
568 assert.deepStrictEqual(
569 applyDisableDirectives({
570 directives: [
571 {
572 parentComment: createParentComment([7, 34]),
573 type: "disable-line",
574 line: 1,
575 column: 8,
576 ruleId: "foo",
577 justification: "j1"
578 },
579 {
580 parentComment: createParentComment([38, 73]),
581 type: "disable-line",
582 line: 2,
583 column: 8,
584 ruleId: "foo",
585 justification: "j2"
586 },
587 {
588 parentComment: createParentComment([76, 111]),
589 type: "disable-line",
590 line: 3,
591 column: 8,
592 ruleId: "foo",
593 justification: "j3"
594 },
595 {
596 parentComment: createParentComment([114, 149]),
597 type: "disable-line",
598 line: 4,
599 column: 8,
600 ruleId: "foo",
601 justification: "j4"
602 },
603 {
604 parentComment: createParentComment([152, 187]),
605 type: "disable-line",
606 line: 5,
607 column: 8,
608 ruleId: "foo",
609 justification: "j5"
610 },
611 {
612 parentComment: createParentComment([190, 225]),
613 type: "disable-line",
614 line: 6,
615 column: 8,
616 ruleId: "foo",
617 justification: "j6"
618 }
619 ],
620 problems: [{ line: 2, column: 1, ruleId: "foo" }]
621 }),
622 [{ line: 2, column: 1, ruleId: "foo", suppressions: [{ kind: "directive", justification: "j2" }] }]
623 );
624 });
625 });
626
627 describe("eslint-disable-next-line comments without rules", () => {
628 it("filters problems on the next line", () => {
629 assert.deepStrictEqual(
630 applyDisableDirectives({
631 directives: [{
632 parentComment: createParentComment([0, 31]),
633 type: "disable-next-line",
634 line: 1,
635 column: 1,
636 ruleId: null,
637 justification: "justification"
638 }],
639 problems: [{ line: 2, column: 3, ruleId: "foo" }]
640 }),
641 [{ line: 2, column: 3, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
642 );
643 });
644
645 it("keeps problems on the same line", () => {
646 assert.deepStrictEqual(
647 applyDisableDirectives({
648 directives: [{
649 parentComment: createParentComment([0, 31]),
650 type: "disable-next-line",
651 line: 1,
652 column: 1,
653 ruleId: null
654 }],
655 problems: [{ line: 1, column: 3, ruleId: "foo" }]
656 }),
657 [{ line: 1, column: 3, ruleId: "foo" }]
658 );
659 });
660
661 it("keeps problems after the next line", () => {
662 assert.deepStrictEqual(
663 applyDisableDirectives({
664 directives: [{
665 parentComment: createParentComment([0, 31]),
666 type: "disable-next-line",
667 line: 1,
668 column: 1,
669 ruleId: null,
670 justification: "justification"
671 }],
672 problems: [{ line: 3, column: 3, ruleId: "foo" }]
673 }),
674 [{ line: 3, column: 3, ruleId: "foo" }]
675 );
676 });
677
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({
681 directives: [
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" }
684 ],
685 problems: [{ line: 2, column: 2, ruleId: "foo" }]
686 }),
687 [{ line: 2, column: 2, ruleId: "foo", suppressions: [{ kind: "directive", justification: "j1" }] }]
688 );
689 });
690 });
691
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" }]
698 }),
699 [{ line: 2, column: 1, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
700 );
701 });
702
703 it("keeps problems on the next line that do not match the ruleId", () => {
704 assert.deepStrictEqual(
705 applyDisableDirectives({
706 directives: [{
707 parentComment: createParentComment([0, 31]),
708 type: "disable-next-line",
709 line: 1,
710 column: 1,
711 ruleId: "foo",
712 justification: "justification"
713 }],
714 problems: [{ line: 2, column: 1, ruleId: "not-foo" }]
715 }),
716 [{ line: 2, column: 1, ruleId: "not-foo" }]
717 );
718 });
719 });
720
721 describe("unrecognized directive types", () => {
722 it("throws a TypeError when it encounters an unrecognized directive", () => {
723 assert.throws(
724 () =>
725 applyDisableDirectives({
726 directives: [{ type: "foo", line: 1, column: 4, ruleId: "foo", justification: "justification" }],
727 problems: []
728 }),
729 "Unrecognized directive type 'foo'"
730 );
731 });
732 });
733
734 describe("unused directives", () => {
735 it("Adds a problem for /* eslint-disable */", () => {
736 assert.deepStrictEqual(
737 applyDisableDirectives({
738 directives: [{
739 parentComment: createParentComment([0, 20]),
740 type: "disable",
741 line: 1,
742 column: 1,
743 justification: "justification"
744 }],
745 problems: [],
746 reportUnusedDisableDirectives: "error"
747 }),
748 [{
749 ruleId: null,
750 message: "Unused eslint-disable directive (no problems were reported).",
751 line: 1,
752 column: 1,
753 fix: {
754 range: [0, 20],
755 text: " "
756 },
757 severity: 2,
758 nodeType: null
759 }]
760 );
761 });
762
763 it("Does not fix a problem for /* eslint-disable */ when disableFixes is enabled", () => {
764 assert.deepStrictEqual(
765 applyDisableDirectives({
766 directives: [{
767 parentComment: createParentComment([0, 20]),
768 type: "disable",
769 line: 1,
770 column: 1,
771 justification: "justification"
772 }],
773 disableFixes: true,
774 problems: [],
775 reportUnusedDisableDirectives: "error"
776 }),
777 [{
778 ruleId: null,
779 message: "Unused eslint-disable directive (no problems were reported).",
780 line: 1,
781 column: 1,
782 severity: 2,
783 nodeType: null
784 }]
785 );
786 });
787
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"
794 }),
795 [{ line: 2, column: 1, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
796 );
797 });
798
799 it("Adds a problem for /* eslint-disable foo */", () => {
800 assert.deepStrictEqual(
801 applyDisableDirectives({
802 directives: [{
803 parentComment: createParentComment([0, 21]),
804 type: "disable",
805 line: 1,
806 column: 1,
807 ruleId: "foo",
808 justification: "justification"
809 }],
810 problems: [],
811 reportUnusedDisableDirectives: "error"
812 }),
813 [{
814 ruleId: null,
815 message: "Unused eslint-disable directive (no problems were reported from 'foo').",
816 line: 1,
817 column: 1,
818 fix: {
819 range: [0, 21],
820 text: " "
821 },
822 severity: 2,
823 nodeType: null
824 }]
825 );
826 });
827
828 it("Adds a problem for /* eslint-disable foo */ /* (problem from another rule) */", () => {
829 assert.deepStrictEqual(
830 applyDisableDirectives({
831 directives: [{
832 parentComment: createParentComment([0, 24]),
833 type: "disable",
834 line: 1,
835 column: 1,
836 ruleId: "foo",
837 justification: "justification"
838 }],
839 problems: [{ line: 1, column: 20, ruleId: "not-foo" }],
840 reportUnusedDisableDirectives: "error"
841 }),
842 [
843 {
844 ruleId: null,
845 message: "Unused eslint-disable directive (no problems were reported from 'foo').",
846 line: 1,
847 column: 1,
848 fix: {
849 range: [0, 24],
850 text: " "
851 },
852 severity: 2,
853 nodeType: null
854 },
855 {
856 ruleId: "not-foo",
857 line: 1,
858 column: 20
859 }
860 ]
861 );
862 });
863
864 it("Adds a problem for /* (problem from foo) */ /* eslint-disable */ /* eslint-enable foo */", () => {
865 assert.deepStrictEqual(
866 applyDisableDirectives({
867 directives: [
868 {
869 parentComment: createParentComment([0, 21]),
870 type: "disable",
871 line: 1,
872 column: 8,
873 ruleId: null,
874 justification: "j1"
875 },
876 {
877 parentComment: createParentComment([0, 21]),
878 type: "enable",
879 line: 1,
880 column: 24,
881 ruleId: "foo",
882 justification: "j2"
883 }
884 ],
885 problems: [{ line: 1, column: 2, ruleId: "foo" }],
886 reportUnusedDisableDirectives: "error"
887 }),
888 [
889 {
890 ruleId: "foo",
891 line: 1,
892 column: 2
893 },
894 {
895 ruleId: null,
896 message: "Unused eslint-disable directive (no problems were reported).",
897 fix: {
898 range: [0, 21],
899 text: " "
900 },
901 line: 1,
902 column: 8,
903 severity: 2,
904 nodeType: null
905 }
906 ]
907 );
908 });
909
910 it("Adds a problem for /* eslint-disable */ /* eslint-enable */", () => {
911 assert.deepStrictEqual(
912 applyDisableDirectives({
913 directives: [
914 {
915 parentComment: createParentComment([0, 20]),
916 type: "disable",
917 line: 1,
918 column: 1,
919 ruleId: null,
920 justification: "j1"
921 },
922 {
923 parentComment: createParentComment([21, 41]),
924 type: "enable",
925 line: 1,
926 column: 12,
927 ruleId: null,
928 justification: "j2"
929 }
930 ],
931 problems: [],
932 reportUnusedDisableDirectives: "error"
933 }),
934 [{
935 ruleId: null,
936 message: "Unused eslint-disable directive (no problems were reported).",
937 line: 1,
938 column: 1,
939 fix: {
940 range: [0, 20],
941 text: " "
942 },
943 severity: 2,
944 nodeType: null
945 }]
946 );
947 });
948
949 it("Adds two problems for /* eslint-disable */ /* eslint-disable */", () => {
950 assert.deepStrictEqual(
951 applyDisableDirectives({
952 directives: [
953 {
954 parentComment: createParentComment([0, 21]),
955 type: "disable",
956 line: 1,
957 column: 1,
958 ruleId: null,
959 justification: "j1"
960 },
961 {
962 parentComment: createParentComment([21, 42]),
963 type: "disable",
964 line: 2,
965 column: 1,
966 ruleId: null,
967 justification: "j2"
968 }
969 ],
970 problems: [],
971 reportUnusedDisableDirectives: "error"
972 }),
973 [
974 {
975 ruleId: null,
976 message: "Unused eslint-disable directive (no problems were reported).",
977 line: 1,
978 column: 1,
979 fix: {
980 range: [0, 21],
981 text: " "
982 },
983 severity: 2,
984 nodeType: null
985 },
986 {
987 ruleId: null,
988 message: "Unused eslint-disable directive (no problems were reported).",
989 line: 2,
990 column: 1,
991 fix: {
992 range: [21, 42],
993 text: " "
994 },
995 severity: 2,
996 nodeType: null
997 }
998 ]
999 );
1000 });
1001
1002 it("Adds a problem for /* eslint-disable */ /* eslint-disable */ /* (problem) */", () => {
1003 assert.deepStrictEqual(
1004 applyDisableDirectives({
1005 directives: [
1006 {
1007 parentComment: createParentComment([0, 21]),
1008 type: "disable",
1009 line: 1,
1010 column: 1,
1011 ruleId: null,
1012 justification: "j1"
1013 },
1014 {
1015 parentComment: createParentComment([22, 45]),
1016 type: "disable",
1017 line: 2,
1018 column: 1,
1019 ruleId: null,
1020 justification: "j2"
1021 }
1022 ],
1023 problems: [{ line: 3, column: 1, ruleId: "foo" }],
1024 reportUnusedDisableDirectives: "error"
1025 }),
1026 [
1027 {
1028 ruleId: null,
1029 message: "Unused eslint-disable directive (no problems were reported).",
1030 line: 1,
1031 column: 1,
1032 fix: {
1033 range: [0, 21],
1034 text: " "
1035 },
1036 severity: 2,
1037 nodeType: null
1038 },
1039 {
1040 line: 3,
1041 column: 1,
1042 ruleId: "foo",
1043 suppressions: [
1044 { kind: "directive", justification: "j1" },
1045 { kind: "directive", justification: "j2" }
1046 ]
1047 }
1048 ]
1049 );
1050 });
1051
1052 it("Adds a problem for /* eslint-disable foo */ /* eslint-disable */ /* (problem from foo) */", () => {
1053 assert.deepStrictEqual(
1054 applyDisableDirectives({
1055 directives: [
1056 {
1057 parentComment: createParentComment([0, 21]),
1058 type: "disable",
1059 line: 1,
1060 column: 1,
1061 ruleId: "foo",
1062 justification: "j1"
1063 },
1064 {
1065 parentComment: createParentComment([22, 45]),
1066 type: "disable",
1067 line: 2,
1068 column: 1,
1069 ruleId: null,
1070 justification: "j2"
1071 }
1072 ],
1073 problems: [{ line: 3, column: 1, ruleId: "foo" }],
1074 reportUnusedDisableDirectives: "error"
1075 }),
1076 [
1077 {
1078 ruleId: null,
1079 message: "Unused eslint-disable directive (no problems were reported from 'foo').",
1080 line: 1,
1081 column: 1,
1082 fix: {
1083 range: [0, 21],
1084 text: " "
1085 },
1086 severity: 2,
1087 nodeType: null
1088 },
1089 {
1090 line: 3,
1091 column: 1,
1092 ruleId: "foo",
1093 suppressions: [
1094 { kind: "directive", justification: "j1" },
1095 { kind: "directive", justification: "j2" }
1096 ]
1097 }
1098 ]
1099 );
1100 });
1101
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"
1108 }),
1109 [{ line: 1, column: 6, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
1110 );
1111 });
1112
1113 it("Adds a problem for /* eslint-disable */ /* eslint-disable foo */ /* (problem from foo) */", () => {
1114 assert.deepStrictEqual(
1115 applyDisableDirectives({
1116 directives: [
1117 {
1118 parentComment: createParentComment([0, 21]),
1119 type: "disable",
1120 line: 1,
1121 column: 1,
1122 ruleId: null,
1123 justification: "j1"
1124 },
1125 {
1126 parentComment: createParentComment([22, 45]),
1127 type: "disable",
1128 line: 2,
1129 column: 1,
1130 ruleId: "foo",
1131 justification: "j2"
1132 }
1133 ],
1134 problems: [{ line: 3, column: 1, ruleId: "foo" }],
1135 reportUnusedDisableDirectives: "error"
1136 }),
1137 [
1138 {
1139 ruleId: null,
1140 message: "Unused eslint-disable directive (no problems were reported).",
1141 line: 1,
1142 column: 1,
1143 fix: {
1144 range: [0, 21],
1145 text: " "
1146 },
1147 severity: 2,
1148 nodeType: null
1149 },
1150 {
1151 line: 3,
1152 column: 1,
1153 ruleId: "foo",
1154 suppressions: [
1155 { kind: "directive", justification: "j1" },
1156 { kind: "directive", justification: "j2" }
1157 ]
1158 }
1159 ]
1160 );
1161 });
1162
1163 it("Adds a problem for /* eslint-disable */ /* eslint-disable foo */ /* (problem from another rule) */", () => {
1164 assert.deepStrictEqual(
1165 applyDisableDirectives({
1166 directives: [
1167 {
1168 parentComment: createParentComment([0, 20]),
1169 type: "disable",
1170 line: 1,
1171 column: 1,
1172 ruleId: null,
1173 justification: "j1"
1174 },
1175 {
1176 parentComment: createParentComment([21, 45]),
1177 type: "disable",
1178 line: 2,
1179 column: 1,
1180 ruleId: "foo",
1181 justification: "j2"
1182 }
1183 ],
1184 problems: [{ line: 3, column: 1, ruleId: "bar" }],
1185 reportUnusedDisableDirectives: "error"
1186 }),
1187 [
1188 {
1189 ruleId: null,
1190 message: "Unused eslint-disable directive (no problems were reported from 'foo').",
1191 line: 2,
1192 column: 1,
1193 fix: {
1194 range: [21, 45],
1195 text: " "
1196 },
1197 severity: 2,
1198 nodeType: null
1199 },
1200 {
1201 line: 3,
1202 column: 1,
1203 ruleId: "bar",
1204 suppressions: [{ kind: "directive", justification: "j1" }]
1205 }
1206 ]
1207 );
1208 });
1209
1210 it("Adds a problem for /* eslint-disable foo */ /* eslint-enable foo */ /* (problem from foo) */", () => {
1211 assert.deepStrictEqual(
1212 applyDisableDirectives({
1213 directives: [
1214 {
1215 parentComment: createParentComment([0, 20]),
1216 type: "disable",
1217 line: 1,
1218 column: 1,
1219 ruleId: "foo",
1220 justification: "j1"
1221 },
1222 {
1223 parentComment: createParentComment([25, 46]),
1224 type: "enable",
1225 line: 1,
1226 column: 26,
1227 ruleId: "foo",
1228 justification: "j2"
1229 }
1230 ],
1231 problems: [{ line: 1, column: 30, ruleId: "foo" }],
1232 reportUnusedDisableDirectives: "error"
1233 }),
1234 [
1235 {
1236 ruleId: null,
1237 message: "Unused eslint-disable directive (no problems were reported from 'foo').",
1238 line: 1,
1239 column: 1,
1240 fix: {
1241 range: [0, 20],
1242 text: " "
1243 },
1244 severity: 2,
1245 nodeType: null
1246 },
1247 {
1248 ruleId: "foo",
1249 line: 1,
1250 column: 30
1251 }
1252 ]
1253 );
1254 });
1255
1256 it("Adds a problem for /* eslint-disable foo */ /* eslint-enable */ /* (problem from foo) */", () => {
1257 assert.deepStrictEqual(
1258 applyDisableDirectives({
1259 directives: [
1260 {
1261 parentComment: createParentComment([0, 24]),
1262 type: "disable",
1263 line: 1,
1264 column: 1,
1265 ruleId: "foo",
1266 justification: "j1"
1267 },
1268 {
1269 parentComment: createParentComment([25, 49]),
1270 type: "enable",
1271 line: 1,
1272 column: 26,
1273 ruleId: null,
1274 justification: "j2"
1275 }
1276 ],
1277 problems: [{ line: 1, column: 30, ruleId: "foo" }],
1278 reportUnusedDisableDirectives: "error"
1279 }),
1280 [
1281 {
1282 ruleId: null,
1283 message: "Unused eslint-disable directive (no problems were reported from 'foo').",
1284 line: 1,
1285 column: 1,
1286 fix: {
1287 range: [0, 24],
1288 text: " "
1289 },
1290 severity: 2,
1291 nodeType: null
1292 },
1293 {
1294 ruleId: "foo",
1295 line: 1,
1296 column: 30
1297 }
1298 ]
1299 );
1300 });
1301
1302 it("Adds two problems for /* eslint-disable */ /* eslint-disable foo */ /* eslint-enable foo */ /* (problem from foo) */", () => {
1303 assert.deepStrictEqual(
1304 applyDisableDirectives({
1305 directives: [
1306 {
1307 parentComment: createParentComment([0, 21]),
1308 type: "disable",
1309 line: 1,
1310 column: 1,
1311 ruleId: null,
1312 justification: "j1"
1313 },
1314 {
1315 parentComment: createParentComment([22, 45]),
1316 type: "disable",
1317 line: 2,
1318 column: 1,
1319 ruleId: "foo",
1320 justification: "j2"
1321 },
1322 {
1323 parentComment: createParentComment([46, 69]),
1324 type: "enable",
1325 line: 3,
1326 column: 1,
1327 ruleId: "foo",
1328 justification: "j3"
1329 }
1330 ],
1331 problems: [{ line: 4, column: 1, ruleId: "foo" }],
1332 reportUnusedDisableDirectives: "error"
1333 }),
1334 [
1335 {
1336 ruleId: null,
1337 message: "Unused eslint-disable directive (no problems were reported).",
1338 line: 1,
1339 column: 1,
1340 fix: {
1341 range: [0, 21],
1342 text: " "
1343 },
1344 severity: 2,
1345 nodeType: null
1346 },
1347 {
1348 ruleId: null,
1349 message: "Unused eslint-disable directive (no problems were reported from 'foo').",
1350 line: 2,
1351 column: 1,
1352 fix: {
1353 range: [22, 45],
1354 text: " "
1355 },
1356 severity: 2,
1357 nodeType: null
1358 },
1359 {
1360 ruleId: "foo",
1361 line: 4,
1362 column: 1
1363 }
1364 ]
1365 );
1366 });
1367
1368 it("Adds a problem for // eslint-disable-line", () => {
1369 assert.deepStrictEqual(
1370 applyDisableDirectives({
1371 directives: [{
1372 parentComment: createParentComment([0, 22]),
1373 type: "disable-line",
1374 line: 1,
1375 column: 1,
1376 ruleId: null,
1377 justification: "justification"
1378 }],
1379 problems: [],
1380 reportUnusedDisableDirectives: "error"
1381 }),
1382 [
1383 {
1384 ruleId: null,
1385 message: "Unused eslint-disable directive (no problems were reported).",
1386 line: 1,
1387 column: 1,
1388 fix: {
1389 range: [0, 22],
1390 text: " "
1391 },
1392 severity: 2,
1393 nodeType: null
1394 }
1395 ]
1396 );
1397 });
1398
1399
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"
1406 }),
1407 [{ line: 1, column: 10, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
1408 );
1409 });
1410
1411 it("Adds a problem for // eslint-disable-next-line", () => {
1412 assert.deepStrictEqual(
1413 applyDisableDirectives({
1414 directives: [{
1415 parentComment: createParentComment([0, 27]),
1416 type: "disable-next-line",
1417 line: 1,
1418 column: 2,
1419 ruleId: null,
1420 justification: "justification"
1421 }],
1422 problems: [],
1423 reportUnusedDisableDirectives: "error"
1424 }),
1425 [
1426 {
1427 ruleId: null,
1428 message: "Unused eslint-disable directive (no problems were reported).",
1429 line: 1,
1430 column: 2,
1431 fix: {
1432 range: [0, 27],
1433 text: " "
1434 },
1435 severity: 2,
1436 nodeType: null
1437 }
1438 ]
1439 );
1440 });
1441
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"
1448 }),
1449 [{ line: 2, column: 10, ruleId: "foo", suppressions: [{ kind: "directive", justification: "justification" }] }]
1450 );
1451 });
1452
1453 it("adds two problems for /* eslint-disable */ // eslint-disable-line", () => {
1454 assert.deepStrictEqual(
1455 applyDisableDirectives({
1456 directives: [
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 }
1459 ],
1460 problems: [],
1461 reportUnusedDisableDirectives: "error"
1462 }),
1463 [
1464 {
1465 ruleId: null,
1466 message: "Unused eslint-disable directive (no problems were reported).",
1467 line: 1,
1468 column: 1,
1469 fix: {
1470 range: [0, 20],
1471 text: " "
1472 },
1473 severity: 2,
1474 nodeType: null
1475 },
1476 {
1477 ruleId: null,
1478 message: "Unused eslint-disable directive (no problems were reported).",
1479 line: 1,
1480 column: 22,
1481 fix: {
1482 range: [20, 43],
1483 text: " "
1484 },
1485 severity: 2,
1486 nodeType: null
1487 }
1488 ]
1489 );
1490 });
1491
1492 it("Does not add problems when reportUnusedDisableDirectives: \"off\" is used", () => {
1493 assert.deepStrictEqual(
1494 applyDisableDirectives({
1495 directives: [{
1496 parentComment: createParentComment([0, 27]),
1497 type: "disable-next-line",
1498 line: 1,
1499 column: 1,
1500 ruleId: null,
1501 justification: "justification"
1502 }],
1503 problems: [],
1504 reportUnusedDisableDirectives: "off"
1505 }),
1506 []
1507 );
1508 });
1509 });
1510
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"]);
1514
1515 assert.deepStrictEqual(
1516 applyDisableDirectives({
1517 directives: [
1518 {
1519 parentComment,
1520 ruleId: "used",
1521 type: "disable",
1522 line: 1,
1523 column: 18,
1524 justification: "j1"
1525 },
1526 {
1527 parentComment,
1528 ruleId: "unused",
1529 type: "disable",
1530 line: 1,
1531 column: 22,
1532 justification: "j2"
1533 }
1534 ],
1535 problems: [{ line: 2, column: 1, ruleId: "used" }],
1536 reportUnusedDisableDirectives: "error"
1537 }),
1538 [
1539 {
1540 ruleId: null,
1541 message: "Unused eslint-disable directive (no problems were reported from 'unused').",
1542 line: 1,
1543 column: 22,
1544 fix: {
1545 range: [22, 30],
1546 text: ""
1547 },
1548 severity: 2,
1549 nodeType: null
1550 },
1551 {
1552 line: 2,
1553 column: 1,
1554 ruleId: "used",
1555 suppressions: [{ kind: "directive", justification: "j1" }]
1556 }
1557 ]
1558 );
1559 });
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"]);
1562
1563 assert.deepStrictEqual(
1564 applyDisableDirectives({
1565 directives: [
1566 {
1567 parentComment,
1568 ruleId: "used",
1569 type: "disable",
1570 line: 1,
1571 column: 18,
1572 justification: "j1"
1573 },
1574 {
1575 parentComment,
1576 ruleId: "unused",
1577 type: "disable",
1578 line: 1,
1579 column: 24,
1580 justification: "j2"
1581 }
1582 ],
1583 problems: [{ line: 2, column: 1, ruleId: "used" }],
1584 reportUnusedDisableDirectives: "error"
1585 }),
1586 [
1587 {
1588 ruleId: null,
1589 message: "Unused eslint-disable directive (no problems were reported from 'unused').",
1590 line: 1,
1591 column: 24,
1592 fix: {
1593 range: [23, 32],
1594 text: ""
1595 },
1596 severity: 2,
1597 nodeType: null
1598 },
1599 {
1600 line: 2,
1601 column: 1,
1602 ruleId: "used",
1603 suppressions: [{ kind: "directive", justification: "j1" }]
1604 }
1605 ]
1606 );
1607 });
1608
1609 it("Adds a problem for /* eslint-disable unused, used */", () => {
1610 const parentComment = createParentComment([0, 32], " eslint-disable unused, used ", ["unused", "used"]);
1611
1612 assert.deepStrictEqual(
1613 applyDisableDirectives({
1614 directives: [
1615 {
1616 parentComment,
1617 ruleId: "unused",
1618 type: "disable",
1619 line: 1,
1620 column: 18,
1621 justification: "j1"
1622 },
1623 {
1624 parentComment,
1625 ruleId: "used",
1626 type: "disable",
1627 line: 1,
1628 column: 25,
1629 justification: "j2"
1630 }
1631 ],
1632 problems: [{ line: 2, column: 1, ruleId: "used" }],
1633 reportUnusedDisableDirectives: "error"
1634 }),
1635 [
1636 {
1637 ruleId: null,
1638 message: "Unused eslint-disable directive (no problems were reported from 'unused').",
1639 line: 1,
1640 column: 18,
1641 fix: {
1642 range: [18, 26],
1643 text: ""
1644 },
1645 severity: 2,
1646 nodeType: null
1647 },
1648 {
1649 line: 2,
1650 column: 1,
1651 ruleId: "used",
1652 suppressions: [{ kind: "directive", justification: "j2" }]
1653 }
1654 ]
1655 );
1656 });
1657
1658 it("Adds a problem for /* eslint-disable unused,, ,, used */", () => {
1659 const parentComment = createParentComment([0, 37], " eslint-disable unused,, ,, used ", ["unused", "used"]);
1660
1661 assert.deepStrictEqual(
1662 applyDisableDirectives({
1663 directives: [
1664 {
1665 parentComment,
1666 ruleId: "unused",
1667 type: "disable",
1668 line: 1,
1669 column: 18,
1670 justification: "j1"
1671 },
1672 {
1673 parentComment,
1674 ruleId: "used",
1675 type: "disable",
1676 line: 1,
1677 column: 29,
1678 justification: "j2"
1679 }
1680 ],
1681 problems: [{ line: 2, column: 1, ruleId: "used" }],
1682 reportUnusedDisableDirectives: "error"
1683 }),
1684 [
1685 {
1686 ruleId: null,
1687 message: "Unused eslint-disable directive (no problems were reported from 'unused').",
1688 line: 1,
1689 column: 18,
1690 fix: {
1691 range: [18, 25],
1692 text: ""
1693 },
1694 severity: 2,
1695 nodeType: null
1696 },
1697 {
1698 line: 2,
1699 column: 1,
1700 ruleId: "used",
1701 suppressions: [{ kind: "directive", justification: "j2" }]
1702 }
1703 ]
1704 );
1705 });
1706
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"]);
1709
1710 assert.deepStrictEqual(
1711 applyDisableDirectives({
1712 directives: [
1713 {
1714 parentComment,
1715 ruleId: "unused-1",
1716 type: "disable",
1717 line: 1,
1718 column: 18,
1719 justification: "j1"
1720 },
1721 {
1722 parentComment,
1723 ruleId: "unused-2",
1724 type: "disable",
1725 line: 1,
1726 column: 28,
1727 justification: "j2"
1728 },
1729 {
1730 parentComment,
1731 ruleId: "used",
1732 type: "disable",
1733 line: 1,
1734 column: 38,
1735 justification: "j3"
1736 }
1737 ],
1738 problems: [{ line: 2, column: 1, ruleId: "used" }],
1739 reportUnusedDisableDirectives: "error"
1740 }),
1741 [
1742 {
1743 ruleId: null,
1744 message: "Unused eslint-disable directive (no problems were reported from 'unused-1').",
1745 line: 1,
1746 column: 18,
1747 fix: {
1748 range: [18, 28],
1749 text: ""
1750 },
1751 severity: 2,
1752 nodeType: null
1753 },
1754 {
1755 ruleId: null,
1756 message: "Unused eslint-disable directive (no problems were reported from 'unused-2').",
1757 line: 1,
1758 column: 28,
1759 fix: {
1760 range: [26, 36],
1761 text: ""
1762 },
1763 severity: 2,
1764 nodeType: null
1765 },
1766 {
1767 line: 2,
1768 column: 1,
1769 ruleId: "used",
1770 suppressions: [{ kind: "directive", justification: "j3" }]
1771 }
1772 ]
1773 );
1774 });
1775
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"]);
1778
1779 assert.deepStrictEqual(
1780 applyDisableDirectives({
1781 directives: [
1782 {
1783 parentComment,
1784 ruleId: "unused-1",
1785 type: "disable",
1786 line: 1,
1787 column: 18,
1788 justification: "j1"
1789 },
1790 {
1791 parentComment,
1792 ruleId: "unused-2",
1793 type: "disable",
1794 line: 1,
1795 column: 28,
1796 justification: "j2"
1797 },
1798 {
1799 parentComment,
1800 ruleId: "used",
1801 type: "disable",
1802 line: 1,
1803 column: 38,
1804 justification: "j3"
1805 },
1806 {
1807 parentComment,
1808 ruleId: "unused-3",
1809 type: "disable",
1810 line: 1,
1811 column: 43,
1812 justification: "j4"
1813 }
1814 ],
1815 problems: [{ line: 2, column: 1, ruleId: "used" }],
1816 reportUnusedDisableDirectives: "error"
1817 }),
1818 [
1819 {
1820 ruleId: null,
1821 message: "Unused eslint-disable directive (no problems were reported from 'unused-1').",
1822 line: 1,
1823 column: 18,
1824 fix: {
1825 range: [18, 28],
1826 text: ""
1827 },
1828 severity: 2,
1829 nodeType: null
1830 },
1831 {
1832 ruleId: null,
1833 message: "Unused eslint-disable directive (no problems were reported from 'unused-2').",
1834 line: 1,
1835 column: 28,
1836 fix: {
1837 range: [26, 36],
1838 text: ""
1839 },
1840 severity: 2,
1841 nodeType: null
1842 },
1843 {
1844 ruleId: null,
1845 message: "Unused eslint-disable directive (no problems were reported from 'unused-3').",
1846 line: 1,
1847 column: 43,
1848 fix: {
1849 range: [42, 52],
1850 text: ""
1851 },
1852 severity: 2,
1853 nodeType: null
1854 },
1855 {
1856 line: 2,
1857 column: 1,
1858 ruleId: "used",
1859 suppressions: [{ kind: "directive", justification: "j3" }]
1860 }
1861 ]
1862 );
1863 });
1864
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"]);
1867
1868 assert.deepStrictEqual(
1869 applyDisableDirectives({
1870 directives: [
1871 {
1872 parentComment,
1873 ruleId: "unused-1",
1874 type: "disable",
1875 line: 1,
1876 column: 18,
1877 justification: "j1"
1878 },
1879 {
1880 parentComment,
1881 ruleId: "unused-2",
1882 type: "disable",
1883 line: 1,
1884 column: 28,
1885 justification: "j2"
1886 }
1887 ],
1888 problems: [],
1889 reportUnusedDisableDirectives: "error"
1890 }),
1891 [
1892 {
1893 ruleId: null,
1894 message: "Unused eslint-disable directive (no problems were reported from 'unused-1' or 'unused-2').",
1895 line: 1,
1896 column: 18,
1897 fix: {
1898 range: [0, 39],
1899 text: " "
1900 },
1901 severity: 2,
1902 nodeType: null
1903 }
1904 ]
1905 );
1906 });
1907
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"]);
1910
1911 assert.deepStrictEqual(
1912 applyDisableDirectives({
1913 directives: [
1914 {
1915 parentComment,
1916 ruleId: "unused-1",
1917 type: "disable",
1918 line: 1,
1919 column: 18
1920 },
1921 {
1922 parentComment,
1923 ruleId: "unused-2",
1924 type: "disable",
1925 line: 1,
1926 column: 28
1927 },
1928 {
1929 parentComment,
1930 ruleId: "unused-3",
1931 type: "disable",
1932 line: 1,
1933 column: 38
1934 }
1935 ],
1936 problems: [],
1937 reportUnusedDisableDirectives: "error"
1938 }),
1939 [
1940 {
1941 ruleId: null,
1942 message: "Unused eslint-disable directive (no problems were reported from 'unused-1', 'unused-2', or 'unused-3').",
1943 line: 1,
1944 column: 18,
1945 fix: {
1946 range: [0, 49],
1947 text: " "
1948 },
1949 severity: 2,
1950 nodeType: null
1951 }
1952 ]
1953 );
1954 });
1955
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({
1959 directives: [
1960 {
1961 parentComment: createParentComment([0, 29], " eslint-disable foo ", ["foo"]),
1962 ruleId: "foo",
1963 type: "disable",
1964 line: 1,
1965 column: 1,
1966 justification: "j1"
1967 },
1968 {
1969 parentComment: createParentComment([41, 81], " eslint-disable-line foo, bar", ["foo", "bar"]),
1970 ruleId: "foo",
1971 type: "disable-line",
1972 line: 2,
1973 column: 11,
1974 justification: "j2"
1975 },
1976 {
1977 parentComment: createParentComment([41, 81], " eslint-disable-line foo, bar ", ["foo", "bar"]),
1978 ruleId: "bar",
1979 type: "disable-line",
1980 line: 2,
1981 column: 11,
1982 justification: "j2"
1983 }
1984 ],
1985 problems: [
1986 { line: 2, column: 1, ruleId: "bar" },
1987 { line: 2, column: 6, ruleId: "foo" }
1988 ],
1989 reportUnusedDisableDirectives: "error"
1990 }),
1991 [
1992 {
1993 ruleId: "bar",
1994 line: 2,
1995 column: 1,
1996 suppressions: [{ kind: "directive", justification: "j2" }]
1997 },
1998 {
1999 ruleId: "foo",
2000 line: 2,
2001 column: 6,
2002 suppressions: [
2003 { kind: "directive", justification: "j1" },
2004 { kind: "directive", justification: "j2" }
2005 ]
2006 },
2007 {
2008 ruleId: null,
2009 message: "Unused eslint-disable directive (no problems were reported from 'foo').",
2010 line: 2,
2011 column: 11,
2012 fix: {
2013 range: [64, 69],
2014 text: ""
2015 },
2016 severity: 2,
2017 nodeType: null
2018 }
2019 ]
2020 );
2021 });
2022 });
2023 });