]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-extra-boolean-cast.js
first commit
[pve-eslint.git] / eslint / tests / lib / rules / no-extra-boolean-cast.js
1 /**
2 * @fileoverview Tests for no-extra-boolean-cast rule.
3 * @author Brandon Mills
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/no-extra-boolean-cast"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Helpers
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("no-extra-boolean-cast", rule, {
22
23 valid: [
24 "Boolean(bar, !!baz);",
25 "var foo = !!bar;",
26 "function foo() { return !!bar; }",
27 "var foo = bar() ? !!baz : !!bat",
28 "for(!!foo;;) {}",
29 "for(;; !!foo) {}",
30 "var foo = Boolean(bar);",
31 "function foo() { return Boolean(bar); }",
32 "var foo = bar() ? Boolean(baz) : Boolean(bat)",
33 "for(Boolean(foo);;) {}",
34 "for(;; Boolean(foo)) {}",
35 "if (new Boolean(foo)) {}",
36 {
37 code: "var foo = bar || !!baz",
38 options: [{ enforceForLogicalOperands: true }]
39 },
40 {
41 code: "var foo = bar && !!baz",
42 options: [{ enforceForLogicalOperands: true }]
43 },
44 {
45 code: "var foo = bar || (baz && !!bat)",
46 options: [{ enforceForLogicalOperands: true }]
47 },
48 {
49 code: "function foo() { return (!!bar || baz); }",
50 options: [{ enforceForLogicalOperands: true }]
51 },
52 {
53 code: "var foo = bar() ? (!!baz && bat) : (!!bat && qux)",
54 options: [{ enforceForLogicalOperands: true }]
55 },
56 {
57 code: "for(!!(foo && bar);;) {}",
58 options: [{ enforceForLogicalOperands: true }]
59 },
60 {
61 code: "for(;; !!(foo || bar)) {}",
62 options: [{ enforceForLogicalOperands: true }]
63 },
64 {
65 code: "var foo = Boolean(bar) || baz;",
66 options: [{ enforceForLogicalOperands: true }]
67 },
68 {
69 code: "var foo = bar || Boolean(baz);",
70 options: [{ enforceForLogicalOperands: true }]
71 },
72 {
73 code: "var foo = Boolean(bar) || Boolean(baz);",
74 options: [{ enforceForLogicalOperands: true }]
75 },
76 {
77 code: "function foo() { return (Boolean(bar) || baz); }",
78 options: [{ enforceForLogicalOperands: true }]
79 },
80 {
81 code: "var foo = bar() ? Boolean(baz) || bat : Boolean(bat)",
82 options: [{ enforceForLogicalOperands: true }]
83 },
84 {
85 code: "for(Boolean(foo) || bar;;) {}",
86 options: [{ enforceForLogicalOperands: true }]
87 },
88 {
89 code: "for(;; Boolean(foo) || bar) {}",
90 options: [{ enforceForLogicalOperands: true }]
91 },
92 {
93 code: "if (new Boolean(foo) || bar) {}",
94 options: [{ enforceForLogicalOperands: true }]
95 },
96 "if (!!foo || bar) {}",
97 {
98 code: "if (!!foo || bar) {}",
99 options: [{}]
100 },
101 {
102 code: "if (!!foo || bar) {}",
103 options: [{ enforceForLogicalOperands: false }]
104 },
105 {
106 code: "if ((!!foo || bar) === baz) {}",
107 options: [{ enforceForLogicalOperands: true }]
108 }
109 ],
110
111 invalid: [
112 {
113 code: "if (!!foo) {}",
114 output: "if (foo) {}",
115 errors: [{
116 messageId: "unexpectedNegation",
117 type: "UnaryExpression",
118 column: 5,
119 endColumn: 10
120 }]
121 },
122 {
123 code: "do {} while (!!foo)",
124 output: "do {} while (foo)",
125 errors: [{
126 messageId: "unexpectedNegation",
127 type: "UnaryExpression",
128 column: 14
129 }]
130 },
131 {
132 code: "while (!!foo) {}",
133 output: "while (foo) {}",
134 errors: [{
135 messageId: "unexpectedNegation",
136 type: "UnaryExpression",
137 column: 8
138 }]
139 },
140 {
141 code: "!!foo ? bar : baz",
142 output: "foo ? bar : baz",
143 errors: [{
144 messageId: "unexpectedNegation",
145 type: "UnaryExpression",
146 column: 1
147 }]
148 },
149 {
150 code: "for (; !!foo;) {}",
151 output: "for (; foo;) {}",
152 errors: [{
153 messageId: "unexpectedNegation",
154 type: "UnaryExpression",
155 column: 8
156 }]
157 },
158 {
159 code: "!!!foo",
160 output: "!foo",
161 errors: [{
162 messageId: "unexpectedNegation",
163 type: "UnaryExpression",
164 column: 2
165 }]
166 },
167 {
168 code: "Boolean(!!foo)",
169 output: "Boolean(foo)",
170 errors: [{
171 messageId: "unexpectedNegation",
172 type: "UnaryExpression",
173 column: 9
174 }]
175 },
176 {
177 code: "new Boolean(!!foo)",
178 output: "new Boolean(foo)",
179 errors: [{
180 messageId: "unexpectedNegation",
181 type: "UnaryExpression",
182 column: 13
183 }]
184 },
185 {
186 code: "if (Boolean(foo)) {}",
187 output: "if (foo) {}",
188 errors: [{
189 messageId: "unexpectedCall",
190 type: "CallExpression"
191 }]
192 },
193 {
194 code: "do {} while (Boolean(foo))",
195 output: "do {} while (foo)",
196 errors: [{
197 messageId: "unexpectedCall",
198 type: "CallExpression"
199 }]
200 },
201 {
202 code: "while (Boolean(foo)) {}",
203 output: "while (foo) {}",
204 errors: [{
205 messageId: "unexpectedCall",
206 type: "CallExpression"
207 }]
208 },
209 {
210 code: "Boolean(foo) ? bar : baz",
211 output: "foo ? bar : baz",
212 errors: [{
213 messageId: "unexpectedCall",
214 type: "CallExpression"
215 }]
216 },
217 {
218 code: "for (; Boolean(foo);) {}",
219 output: "for (; foo;) {}",
220 errors: [{
221 messageId: "unexpectedCall",
222 type: "CallExpression"
223 }]
224 },
225 {
226 code: "!Boolean(foo)",
227 output: "!foo",
228 errors: [{
229 messageId: "unexpectedCall",
230 type: "CallExpression"
231 }]
232 },
233 {
234 code: "!Boolean(foo && bar)",
235 output: "!(foo && bar)",
236 errors: [{
237 messageId: "unexpectedCall",
238 type: "CallExpression"
239 }]
240 },
241 {
242 code: "!Boolean(foo + bar)",
243 output: "!(foo + bar)",
244 errors: [{
245 messageId: "unexpectedCall",
246 type: "CallExpression"
247 }]
248 },
249 {
250 code: "!Boolean(+foo)",
251 output: "!+foo",
252 errors: [{
253 messageId: "unexpectedCall",
254 type: "CallExpression"
255 }]
256 },
257 {
258 code: "!Boolean(foo())",
259 output: "!foo()",
260 errors: [{
261 messageId: "unexpectedCall",
262 type: "CallExpression"
263 }]
264 },
265 {
266 code: "!Boolean(foo = bar)",
267 output: "!(foo = bar)",
268 errors: [{
269 messageId: "unexpectedCall",
270 type: "CallExpression"
271 }]
272 },
273 {
274 code: "!Boolean(...foo);",
275 output: null,
276 parserOptions: { ecmaVersion: 2015 },
277 errors: [{
278 messageId: "unexpectedCall",
279 type: "CallExpression"
280 }]
281 },
282 {
283 code: "!Boolean(foo, bar());",
284 output: null,
285 errors: [{
286 messageId: "unexpectedCall",
287 type: "CallExpression"
288 }]
289 },
290 {
291 code: "!Boolean((foo, bar()));",
292 output: "!(foo, bar());",
293 errors: [{
294 messageId: "unexpectedCall",
295 type: "CallExpression"
296 }]
297 },
298 {
299 code: "!Boolean();",
300 output: "true;",
301 errors: [{
302 messageId: "unexpectedCall",
303 type: "CallExpression"
304 }]
305 },
306 {
307 code: "!(Boolean());",
308 output: "true;",
309 errors: [{
310 messageId: "unexpectedCall",
311 type: "CallExpression"
312 }]
313 },
314 {
315 code: "if (!Boolean()) { foo() }",
316 output: "if (true) { foo() }",
317 errors: [{
318 messageId: "unexpectedCall",
319 type: "CallExpression"
320 }]
321 },
322 {
323 code: "while (!Boolean()) { foo() }",
324 output: "while (true) { foo() }",
325 errors: [{
326 messageId: "unexpectedCall",
327 type: "CallExpression"
328 }]
329 },
330 {
331 code: "var foo = Boolean() ? bar() : baz()",
332 output: "var foo = false ? bar() : baz()",
333 errors: [{
334 messageId: "unexpectedCall",
335 type: "CallExpression"
336 }]
337 },
338 {
339 code: "if (Boolean()) { foo() }",
340 output: "if (false) { foo() }",
341 errors: [{
342 messageId: "unexpectedCall",
343 type: "CallExpression"
344 }]
345 },
346 {
347 code: "while (Boolean()) { foo() }",
348 output: "while (false) { foo() }",
349 errors: [{
350 messageId: "unexpectedCall",
351 type: "CallExpression"
352 }]
353 },
354 {
355 code: "Boolean(Boolean(foo))",
356 output: "Boolean(foo)",
357 errors: [{
358 messageId: "unexpectedCall",
359 type: "CallExpression"
360 }]
361 },
362 {
363 code: "Boolean(!!foo, bar)",
364 output: "Boolean(foo, bar)",
365 errors: [{
366 messageId: "unexpectedNegation",
367 type: "UnaryExpression"
368 }]
369 },
370
371
372 // Adjacent tokens tests
373 {
374 code: "function *foo() { yield!!a ? b : c }",
375 output: "function *foo() { yield a ? b : c }",
376 parserOptions: { ecmaVersion: 2015 },
377 errors: [{
378 messageId: "unexpectedNegation",
379 type: "UnaryExpression"
380 }]
381 },
382 {
383 code: "function *foo() { yield!! a ? b : c }",
384 output: "function *foo() { yield a ? b : c }",
385 parserOptions: { ecmaVersion: 2015 },
386 errors: [{
387 messageId: "unexpectedNegation",
388 type: "UnaryExpression"
389 }]
390 },
391 {
392 code: "function *foo() { yield! !a ? b : c }",
393 output: "function *foo() { yield a ? b : c }",
394 parserOptions: { ecmaVersion: 2015 },
395 errors: [{
396 messageId: "unexpectedNegation",
397 type: "UnaryExpression"
398 }]
399 },
400 {
401 code: "function *foo() { yield !!a ? b : c }",
402 output: "function *foo() { yield a ? b : c }",
403 parserOptions: { ecmaVersion: 2015 },
404 errors: [{
405 messageId: "unexpectedNegation",
406 type: "UnaryExpression"
407 }]
408 },
409 {
410 code: "function *foo() { yield(!!a) ? b : c }",
411 output: "function *foo() { yield(a) ? b : c }",
412 parserOptions: { ecmaVersion: 2015 },
413 errors: [{
414 messageId: "unexpectedNegation",
415 type: "UnaryExpression"
416 }]
417 },
418 {
419 code: "function *foo() { yield/**/!!a ? b : c }",
420 output: "function *foo() { yield/**/a ? b : c }",
421 parserOptions: { ecmaVersion: 2015 },
422 errors: [{
423 messageId: "unexpectedNegation",
424 type: "UnaryExpression"
425 }]
426 },
427 {
428 code: "x=!!a ? b : c ",
429 output: "x=a ? b : c ",
430 errors: [{
431 messageId: "unexpectedNegation",
432 type: "UnaryExpression"
433 }]
434 },
435 {
436 code: "void!Boolean()",
437 output: "void true",
438 errors: [{
439 messageId: "unexpectedCall",
440 type: "CallExpression"
441 }]
442 },
443 {
444 code: "void! Boolean()",
445 output: "void true",
446 errors: [{
447 messageId: "unexpectedCall",
448 type: "CallExpression"
449 }]
450 },
451 {
452 code: "typeof!Boolean()",
453 output: "typeof true",
454 errors: [{
455 messageId: "unexpectedCall",
456 type: "CallExpression"
457 }]
458 },
459 {
460 code: "(!Boolean())",
461 output: "(true)",
462 errors: [{
463 messageId: "unexpectedCall",
464 type: "CallExpression"
465 }]
466 },
467 {
468 code: "+!Boolean()",
469 output: "+true",
470 errors: [{
471 messageId: "unexpectedCall",
472 type: "CallExpression"
473 }]
474 },
475 {
476 code: "void !Boolean()",
477 output: "void true",
478 errors: [{
479 messageId: "unexpectedCall",
480 type: "CallExpression"
481 }]
482 },
483 {
484 code: "void(!Boolean())",
485 output: "void(true)",
486 errors: [{
487 messageId: "unexpectedCall",
488 type: "CallExpression"
489 }]
490 },
491 {
492 code: "void/**/!Boolean()",
493 output: "void/**/true",
494 errors: [{
495 messageId: "unexpectedCall",
496 type: "CallExpression"
497 }]
498 },
499
500 // Comments tests
501 {
502 code: "!/**/!!foo",
503 output: "!/**/foo",
504 errors: [{
505 messageId: "unexpectedNegation",
506 type: "UnaryExpression"
507 }]
508 },
509 {
510 code: "!!/**/!foo",
511 output: null,
512 errors: [{
513 messageId: "unexpectedNegation",
514 type: "UnaryExpression"
515 }]
516 },
517 {
518 code: "!!!/**/foo",
519 output: null,
520 errors: [{
521 messageId: "unexpectedNegation",
522 type: "UnaryExpression"
523 }]
524 },
525 {
526 code: "!!!foo/**/",
527 output: "!foo/**/",
528 errors: [{
529 messageId: "unexpectedNegation",
530 type: "UnaryExpression"
531 }]
532 },
533 {
534 code: "if(!/**/!foo);",
535 output: null,
536 errors: [{
537 messageId: "unexpectedNegation",
538 type: "UnaryExpression"
539 }]
540 },
541 {
542 code: "(!!/**/foo ? 1 : 2)",
543 output: null,
544 errors: [{
545 messageId: "unexpectedNegation",
546 type: "UnaryExpression"
547 }]
548 },
549 {
550 code: "!/**/Boolean(foo)",
551 output: "!/**/foo",
552 errors: [{
553 messageId: "unexpectedCall",
554 type: "CallExpression"
555 }]
556 },
557 {
558 code: "!Boolean/**/(foo)",
559 output: null,
560 errors: [{
561 messageId: "unexpectedCall",
562 type: "CallExpression"
563 }]
564 },
565 {
566 code: "!Boolean(/**/foo)",
567 output: null,
568 errors: [{
569 messageId: "unexpectedCall",
570 type: "CallExpression"
571 }]
572 },
573 {
574 code: "!Boolean(foo/**/)",
575 output: null,
576 errors: [{
577 messageId: "unexpectedCall",
578 type: "CallExpression"
579 }]
580 },
581 {
582 code: "!Boolean(foo)/**/",
583 output: "!foo/**/",
584 errors: [{
585 messageId: "unexpectedCall",
586 type: "CallExpression"
587 }]
588 },
589 {
590 code: "if(Boolean/**/(foo));",
591 output: null,
592 errors: [{
593 messageId: "unexpectedCall",
594 type: "CallExpression"
595 }]
596 },
597 {
598 code: "(Boolean(foo/**/) ? 1 : 2)",
599 output: null,
600 errors: [{
601 messageId: "unexpectedCall",
602 type: "CallExpression"
603 }]
604 },
605 {
606 code: "/**/!Boolean()",
607 output: "/**/true",
608 errors: [{
609 messageId: "unexpectedCall",
610 type: "CallExpression"
611 }]
612 },
613 {
614 code: "!/**/Boolean()",
615 output: null,
616 errors: [{
617 messageId: "unexpectedCall",
618 type: "CallExpression"
619 }]
620 },
621 {
622 code: "!Boolean/**/()",
623 output: null,
624 errors: [{
625 messageId: "unexpectedCall",
626 type: "CallExpression"
627 }]
628 },
629 {
630 code: "!Boolean(/**/)",
631 output: null,
632 errors: [{
633 messageId: "unexpectedCall",
634 type: "CallExpression"
635 }]
636 },
637 {
638 code: "!Boolean()/**/",
639 output: "true/**/",
640 errors: [{
641 messageId: "unexpectedCall",
642 type: "CallExpression"
643 }]
644 },
645 {
646 code: "if(!/**/Boolean());",
647 output: null,
648 errors: [{
649 messageId: "unexpectedCall",
650 type: "CallExpression"
651 }]
652 },
653 {
654 code: "(!Boolean(/**/) ? 1 : 2)",
655 output: null,
656 errors: [{
657 messageId: "unexpectedCall",
658 type: "CallExpression"
659 }]
660 },
661 {
662 code: "if(/**/Boolean());",
663 output: "if(/**/false);",
664 errors: [{
665 messageId: "unexpectedCall",
666 type: "CallExpression"
667 }]
668 },
669 {
670 code: "if(Boolean/**/());",
671 output: null,
672 errors: [{
673 messageId: "unexpectedCall",
674 type: "CallExpression"
675 }]
676 },
677 {
678 code: "if(Boolean(/**/));",
679 output: null,
680 errors: [{
681 messageId: "unexpectedCall",
682 type: "CallExpression"
683 }]
684 },
685 {
686 code: "if(Boolean()/**/);",
687 output: "if(false/**/);",
688 errors: [{
689 messageId: "unexpectedCall",
690 type: "CallExpression"
691 }]
692 },
693 {
694 code: "(Boolean/**/() ? 1 : 2)",
695 output: null,
696 errors: [{
697 messageId: "unexpectedCall",
698 type: "CallExpression"
699 }]
700 },
701
702
703 // In Logical context
704 {
705 code: "if (!!foo || bar) {}",
706 output: "if (foo || bar) {}",
707 options: [{ enforceForLogicalOperands: true }],
708 errors: [{
709 messageId: "unexpectedNegation",
710 type: "UnaryExpression",
711 column: 5,
712 endColumn: 10
713 }]
714 },
715 {
716 code: "if (!!foo && bar) {}",
717 output: "if (foo && bar) {}",
718 options: [{ enforceForLogicalOperands: true }],
719 errors: [{
720 messageId: "unexpectedNegation",
721 type: "UnaryExpression",
722 column: 5,
723 endColumn: 10
724 }]
725 },
726
727 {
728 code: "if ((!!foo || bar) && bat) {}",
729 output: "if ((foo || bar) && bat) {}",
730 options: [{ enforceForLogicalOperands: true }],
731 errors: [{
732 messageId: "unexpectedNegation",
733 type: "UnaryExpression",
734 column: 6,
735 endColumn: 11
736 }]
737 },
738 {
739 code: "if (foo && !!bar) {}",
740 output: "if (foo && bar) {}",
741 options: [{ enforceForLogicalOperands: true }],
742 errors: [{
743 messageId: "unexpectedNegation",
744 type: "UnaryExpression",
745 column: 12,
746 endColumn: 17
747 }]
748 },
749 {
750 code: "do {} while (!!foo || bar)",
751 output: "do {} while (foo || bar)",
752 options: [{ enforceForLogicalOperands: true }],
753 errors: [{
754 messageId: "unexpectedNegation",
755 type: "UnaryExpression",
756 column: 14
757 }]
758 },
759 {
760 code: "while (!!foo || bar) {}",
761 output: "while (foo || bar) {}",
762 options: [{ enforceForLogicalOperands: true }],
763 errors: [{
764 messageId: "unexpectedNegation",
765 type: "UnaryExpression",
766 column: 8
767 }]
768 },
769 {
770 code: "!!foo && bat ? bar : baz",
771 output: "foo && bat ? bar : baz",
772 options: [{ enforceForLogicalOperands: true }],
773 errors: [{
774 messageId: "unexpectedNegation",
775 type: "UnaryExpression",
776 column: 1
777 }]
778 },
779 {
780 code: "for (; !!foo || bar;) {}",
781 output: "for (; foo || bar;) {}",
782 options: [{ enforceForLogicalOperands: true }],
783 errors: [{
784 messageId: "unexpectedNegation",
785 type: "UnaryExpression",
786 column: 8
787 }]
788 },
789 {
790 code: "!!!foo || bar",
791 output: "!foo || bar",
792 options: [{ enforceForLogicalOperands: true }],
793 errors: [{
794 messageId: "unexpectedNegation",
795 type: "UnaryExpression",
796 column: 2
797 }]
798 },
799 {
800 code: "Boolean(!!foo || bar)",
801 output: "Boolean(foo || bar)",
802 options: [{ enforceForLogicalOperands: true }],
803 errors: [{
804 messageId: "unexpectedNegation",
805 type: "UnaryExpression",
806 column: 9
807 }]
808 },
809 {
810 code: "new Boolean(!!foo || bar)",
811 output: "new Boolean(foo || bar)",
812 options: [{ enforceForLogicalOperands: true }],
813 errors: [{
814 messageId: "unexpectedNegation",
815 type: "UnaryExpression",
816 column: 13
817 }]
818 },
819 {
820 code: "if (Boolean(foo) || bar) {}",
821 output: "if (foo || bar) {}",
822 options: [{ enforceForLogicalOperands: true }],
823 errors: [{
824 messageId: "unexpectedCall",
825 type: "CallExpression"
826 }]
827 },
828 {
829 code: "do {} while (Boolean(foo) || bar)",
830 output: "do {} while (foo || bar)",
831 options: [{ enforceForLogicalOperands: true }],
832 errors: [{
833 messageId: "unexpectedCall",
834 type: "CallExpression"
835 }]
836 },
837 {
838 code: "while (Boolean(foo) || bar) {}",
839 output: "while (foo || bar) {}",
840 options: [{ enforceForLogicalOperands: true }],
841 errors: [{
842 messageId: "unexpectedCall",
843 type: "CallExpression"
844 }]
845 },
846 {
847 code: "Boolean(foo) || bat ? bar : baz",
848 output: "foo || bat ? bar : baz",
849 options: [{ enforceForLogicalOperands: true }],
850 errors: [{
851 messageId: "unexpectedCall",
852 type: "CallExpression"
853 }]
854 },
855 {
856 code: "for (; Boolean(foo) || bar;) {}",
857 output: "for (; foo || bar;) {}",
858 options: [{ enforceForLogicalOperands: true }],
859 errors: [{
860 messageId: "unexpectedCall",
861 type: "CallExpression"
862 }]
863 },
864 {
865 code: "!Boolean(foo) || bar",
866 output: "!foo || bar",
867 options: [{ enforceForLogicalOperands: true }],
868 errors: [{
869 messageId: "unexpectedCall",
870 type: "CallExpression"
871 }]
872 },
873 {
874 code: "!Boolean(foo && bar) || bat",
875 output: "!(foo && bar) || bat",
876 options: [{ enforceForLogicalOperands: true }],
877 errors: [{
878 messageId: "unexpectedCall",
879 type: "CallExpression"
880 }]
881 },
882 {
883 code: "!Boolean(foo + bar) || bat",
884 output: "!(foo + bar) || bat",
885 options: [{ enforceForLogicalOperands: true }],
886 errors: [{
887 messageId: "unexpectedCall",
888 type: "CallExpression"
889 }]
890 },
891 {
892 code: "!Boolean(+foo) || bar",
893 output: "!+foo || bar",
894 options: [{ enforceForLogicalOperands: true }],
895 errors: [{
896 messageId: "unexpectedCall",
897 type: "CallExpression"
898 }]
899 },
900 {
901 code: "!Boolean(foo()) || bar",
902 output: "!foo() || bar",
903 options: [{ enforceForLogicalOperands: true }],
904 errors: [{
905 messageId: "unexpectedCall",
906 type: "CallExpression"
907 }]
908 },
909 {
910 code: "!Boolean(foo() || bar)",
911 output: "!(foo() || bar)",
912 options: [{ enforceForLogicalOperands: true }],
913 errors: [{
914 messageId: "unexpectedCall",
915 type: "CallExpression"
916 }]
917 },
918 {
919 code: "!Boolean(foo = bar) || bat",
920 output: "!(foo = bar) || bat",
921 options: [{ enforceForLogicalOperands: true }],
922 errors: [{
923 messageId: "unexpectedCall",
924 type: "CallExpression"
925 }]
926 },
927 {
928 code: "!Boolean(...foo) || bar;",
929 output: null,
930 options: [{ enforceForLogicalOperands: true }],
931 parserOptions: { ecmaVersion: 2015 },
932 errors: [{
933 messageId: "unexpectedCall",
934 type: "CallExpression"
935 }]
936 },
937 {
938 code: "!Boolean(foo, bar()) || bar;",
939 output: null,
940 options: [{ enforceForLogicalOperands: true }],
941 errors: [{
942 messageId: "unexpectedCall",
943 type: "CallExpression"
944 }]
945 },
946 {
947 code: "!Boolean((foo, bar()) || bat);",
948 output: "!((foo, bar()) || bat);",
949 options: [{ enforceForLogicalOperands: true }],
950 errors: [{
951 messageId: "unexpectedCall",
952 type: "CallExpression"
953 }]
954 },
955 {
956 code: "!Boolean() || bar;",
957 output: "true || bar;",
958 options: [{ enforceForLogicalOperands: true }],
959 errors: [{
960 messageId: "unexpectedCall",
961 type: "CallExpression"
962 }]
963 },
964 {
965 code: "!(Boolean()) || bar;",
966 output: "true || bar;",
967 options: [{ enforceForLogicalOperands: true }],
968 errors: [{
969 messageId: "unexpectedCall",
970 type: "CallExpression"
971 }]
972 },
973 {
974 code: "if (!Boolean() || bar) { foo() }",
975 output: "if (true || bar) { foo() }",
976 options: [{ enforceForLogicalOperands: true }],
977 errors: [{
978 messageId: "unexpectedCall",
979 type: "CallExpression"
980 }]
981 },
982 {
983 code: "while (!Boolean() || bar) { foo() }",
984 output: "while (true || bar) { foo() }",
985 options: [{ enforceForLogicalOperands: true }],
986 errors: [{
987 messageId: "unexpectedCall",
988 type: "CallExpression"
989 }]
990 },
991 {
992 code: "var foo = Boolean() || bar ? bar() : baz()",
993 output: "var foo = false || bar ? bar() : baz()",
994 options: [{ enforceForLogicalOperands: true }],
995 errors: [{
996 messageId: "unexpectedCall",
997 type: "CallExpression"
998 }]
999 },
1000 {
1001 code: "if (Boolean() || bar) { foo() }",
1002 output: "if (false || bar) { foo() }",
1003 options: [{ enforceForLogicalOperands: true }],
1004 errors: [{
1005 messageId: "unexpectedCall",
1006 type: "CallExpression"
1007 }]
1008 },
1009 {
1010 code: "while (Boolean() || bar) { foo() }",
1011 output: "while (false || bar) { foo() }",
1012 options: [{ enforceForLogicalOperands: true }],
1013 errors: [{
1014 messageId: "unexpectedCall",
1015 type: "CallExpression"
1016 }]
1017 },
1018
1019
1020 // Adjacent tokens tests
1021 {
1022 code: "function *foo() { yield(!!a || d) ? b : c }",
1023 output: "function *foo() { yield(a || d) ? b : c }",
1024 options: [{ enforceForLogicalOperands: true }],
1025 parserOptions: { ecmaVersion: 2015 },
1026 errors: [{
1027 messageId: "unexpectedNegation",
1028 type: "UnaryExpression"
1029 }]
1030 },
1031 {
1032 code: "function *foo() { yield(!! a || d) ? b : c }",
1033 output: "function *foo() { yield(a || d) ? b : c }",
1034 options: [{ enforceForLogicalOperands: true }],
1035 parserOptions: { ecmaVersion: 2015 },
1036 errors: [{
1037 messageId: "unexpectedNegation",
1038 type: "UnaryExpression"
1039 }]
1040 },
1041 {
1042 code: "function *foo() { yield(! !a || d) ? b : c }",
1043 output: "function *foo() { yield(a || d) ? b : c }",
1044 options: [{ enforceForLogicalOperands: true }],
1045 parserOptions: { ecmaVersion: 2015 },
1046 errors: [{
1047 messageId: "unexpectedNegation",
1048 type: "UnaryExpression"
1049 }]
1050 },
1051 {
1052 code: "function *foo() { yield (!!a || d) ? b : c }",
1053 output: "function *foo() { yield (a || d) ? b : c }",
1054 options: [{ enforceForLogicalOperands: true }],
1055 parserOptions: { ecmaVersion: 2015 },
1056 errors: [{
1057 messageId: "unexpectedNegation",
1058 type: "UnaryExpression"
1059 }]
1060 },
1061 {
1062 code: "function *foo() { yield/**/(!!a || d) ? b : c }",
1063 output: "function *foo() { yield/**/(a || d) ? b : c }",
1064 options: [{ enforceForLogicalOperands: true }],
1065 parserOptions: { ecmaVersion: 2015 },
1066 errors: [{
1067 messageId: "unexpectedNegation",
1068 type: "UnaryExpression"
1069 }]
1070 },
1071 {
1072 code: "x=!!a || d ? b : c ",
1073 output: "x=a || d ? b : c ",
1074 options: [{ enforceForLogicalOperands: true }],
1075 errors: [{
1076 messageId: "unexpectedNegation",
1077 type: "UnaryExpression"
1078 }]
1079 },
1080 {
1081 code: "void(!Boolean() || bar)",
1082 output: "void(true || bar)",
1083 options: [{ enforceForLogicalOperands: true }],
1084 errors: [{
1085 messageId: "unexpectedCall",
1086 type: "CallExpression"
1087 }]
1088 },
1089 {
1090 code: "void(! Boolean() || bar)",
1091 output: "void(true || bar)",
1092 options: [{ enforceForLogicalOperands: true }],
1093 errors: [{
1094 messageId: "unexpectedCall",
1095 type: "CallExpression"
1096 }]
1097 },
1098 {
1099 code: "typeof(!Boolean() || bar)",
1100 output: "typeof(true || bar)",
1101 options: [{ enforceForLogicalOperands: true }],
1102 errors: [{
1103 messageId: "unexpectedCall",
1104 type: "CallExpression"
1105 }]
1106 },
1107 {
1108 code: "(!Boolean() || bar)",
1109 output: "(true || bar)",
1110 options: [{ enforceForLogicalOperands: true }],
1111 errors: [{
1112 messageId: "unexpectedCall",
1113 type: "CallExpression"
1114 }]
1115 },
1116 {
1117 code: "void/**/(!Boolean() || bar)",
1118 output: "void/**/(true || bar)",
1119 options: [{ enforceForLogicalOperands: true }],
1120 errors: [{
1121 messageId: "unexpectedCall",
1122 type: "CallExpression"
1123 }]
1124 },
1125
1126 // Comments tests
1127 {
1128 code: "!/**/(!!foo || bar)",
1129 output: "!/**/(foo || bar)",
1130 options: [{ enforceForLogicalOperands: true }],
1131 errors: [{
1132 messageId: "unexpectedNegation",
1133 type: "UnaryExpression"
1134 }]
1135 },
1136 {
1137 code: "!!/**/!foo || bar",
1138 output: null,
1139 options: [{ enforceForLogicalOperands: true }],
1140 errors: [{
1141 messageId: "unexpectedNegation",
1142 type: "UnaryExpression"
1143 }]
1144 },
1145 {
1146 code: "!!!/**/foo || bar",
1147 output: null,
1148 options: [{ enforceForLogicalOperands: true }],
1149 errors: [{
1150 messageId: "unexpectedNegation",
1151 type: "UnaryExpression"
1152 }]
1153 },
1154 {
1155 code: "!(!!foo || bar)/**/",
1156 output: "!(foo || bar)/**/",
1157 options: [{ enforceForLogicalOperands: true }],
1158 errors: [{
1159 messageId: "unexpectedNegation",
1160 type: "UnaryExpression"
1161 }]
1162 },
1163 {
1164 code: "if(!/**/!foo || bar);",
1165 output: null,
1166 options: [{ enforceForLogicalOperands: true }],
1167 errors: [{
1168 messageId: "unexpectedNegation",
1169 type: "UnaryExpression"
1170 }]
1171 },
1172 {
1173 code: "(!!/**/foo || bar ? 1 : 2)",
1174 output: null,
1175 options: [{ enforceForLogicalOperands: true }],
1176 errors: [{
1177 messageId: "unexpectedNegation",
1178 type: "UnaryExpression"
1179 }]
1180 },
1181 {
1182 code: "!/**/(Boolean(foo) || bar)",
1183 output: "!/**/(foo || bar)",
1184 options: [{ enforceForLogicalOperands: true }],
1185 errors: [{
1186 messageId: "unexpectedCall",
1187 type: "CallExpression"
1188 }]
1189 },
1190 {
1191 code: "!Boolean/**/(foo) || bar",
1192 output: null,
1193 options: [{ enforceForLogicalOperands: true }],
1194 errors: [{
1195 messageId: "unexpectedCall",
1196 type: "CallExpression"
1197 }]
1198 },
1199 {
1200 code: "!Boolean(/**/foo) || bar",
1201 output: null,
1202 options: [{ enforceForLogicalOperands: true }],
1203 errors: [{
1204 messageId: "unexpectedCall",
1205 type: "CallExpression"
1206 }]
1207 },
1208 {
1209 code: "!Boolean(foo/**/) || bar",
1210 output: null,
1211 options: [{ enforceForLogicalOperands: true }],
1212 errors: [{
1213 messageId: "unexpectedCall",
1214 type: "CallExpression"
1215 }]
1216 },
1217 {
1218 code: "!(Boolean(foo)|| bar)/**/",
1219 output: "!(foo|| bar)/**/",
1220 options: [{ enforceForLogicalOperands: true }],
1221 errors: [{
1222 messageId: "unexpectedCall",
1223 type: "CallExpression"
1224 }]
1225 },
1226 {
1227 code: "if(Boolean/**/(foo) || bar);",
1228 output: null,
1229 options: [{ enforceForLogicalOperands: true }],
1230 errors: [{
1231 messageId: "unexpectedCall",
1232 type: "CallExpression"
1233 }]
1234 },
1235 {
1236 code: "(Boolean(foo/**/)|| bar ? 1 : 2)",
1237 output: null,
1238 options: [{ enforceForLogicalOperands: true }],
1239 errors: [{
1240 messageId: "unexpectedCall",
1241 type: "CallExpression"
1242 }]
1243 },
1244 {
1245 code: "/**/!Boolean()|| bar",
1246 output: "/**/true|| bar",
1247 options: [{ enforceForLogicalOperands: true }],
1248 errors: [{
1249 messageId: "unexpectedCall",
1250 type: "CallExpression"
1251 }]
1252 },
1253 {
1254 code: "!/**/Boolean()|| bar",
1255 output: null,
1256 options: [{ enforceForLogicalOperands: true }],
1257 errors: [{
1258 messageId: "unexpectedCall",
1259 type: "CallExpression"
1260 }]
1261 },
1262 {
1263 code: "!Boolean/**/()|| bar",
1264 output: null,
1265 options: [{ enforceForLogicalOperands: true }],
1266 errors: [{
1267 messageId: "unexpectedCall",
1268 type: "CallExpression"
1269 }]
1270 },
1271 {
1272 code: "!Boolean(/**/)|| bar",
1273 output: null,
1274 options: [{ enforceForLogicalOperands: true }],
1275 errors: [{
1276 messageId: "unexpectedCall",
1277 type: "CallExpression"
1278 }]
1279 },
1280 {
1281 code: "(!Boolean()|| bar)/**/",
1282 output: "(true|| bar)/**/",
1283 options: [{ enforceForLogicalOperands: true }],
1284 errors: [{
1285 messageId: "unexpectedCall",
1286 type: "CallExpression"
1287 }]
1288 },
1289 {
1290 code: "if(!/**/Boolean()|| bar);",
1291 output: null,
1292 options: [{ enforceForLogicalOperands: true }],
1293 errors: [{
1294 messageId: "unexpectedCall",
1295 type: "CallExpression"
1296 }]
1297 },
1298 {
1299 code: "(!Boolean(/**/) || bar ? 1 : 2)",
1300 output: null,
1301 options: [{ enforceForLogicalOperands: true }],
1302 errors: [{
1303 messageId: "unexpectedCall",
1304 type: "CallExpression"
1305 }]
1306 },
1307 {
1308 code: "if(/**/Boolean()|| bar);",
1309 output: "if(/**/false|| bar);",
1310 options: [{ enforceForLogicalOperands: true }],
1311 errors: [{
1312 messageId: "unexpectedCall",
1313 type: "CallExpression"
1314 }]
1315 },
1316 {
1317 code: "if(Boolean/**/()|| bar);",
1318 output: null,
1319 options: [{ enforceForLogicalOperands: true }],
1320 errors: [{
1321 messageId: "unexpectedCall",
1322 type: "CallExpression"
1323 }]
1324 },
1325 {
1326 code: "if(Boolean(/**/)|| bar);",
1327 output: null,
1328 options: [{ enforceForLogicalOperands: true }],
1329 errors: [{
1330 messageId: "unexpectedCall",
1331 type: "CallExpression"
1332 }]
1333 },
1334 {
1335 code: "if(Boolean()|| bar/**/);",
1336 output: "if(false|| bar/**/);",
1337 options: [{ enforceForLogicalOperands: true }],
1338 errors: [{
1339 messageId: "unexpectedCall",
1340 type: "CallExpression"
1341 }]
1342 },
1343 {
1344 code: "(Boolean/**/()|| bar ? 1 : 2)",
1345 output: null,
1346 options: [{ enforceForLogicalOperands: true }],
1347 errors: [{
1348 messageId: "unexpectedCall",
1349 type: "CallExpression"
1350 }]
1351 },
1352 {
1353 code: "if (a && !!(b ? c : d)){}",
1354 output: "if (a && (b ? c : d)){}",
1355
1356 options: [{ enforceForLogicalOperands: true }],
1357 errors: [{
1358 messageId: "unexpectedNegation",
1359 type: "UnaryExpression",
1360 column: 10,
1361 endColumn: 23
1362 }]
1363 },
1364 {
1365 code: "function *foo() { yield!!a || d ? b : c }",
1366 output: "function *foo() { yield a || d ? b : c }",
1367 options: [{ enforceForLogicalOperands: true }],
1368 parserOptions: { ecmaVersion: 6 },
1369 errors: [{
1370 messageId: "unexpectedNegation",
1371 type: "UnaryExpression",
1372 column: 24,
1373 endColumn: 27
1374 }]
1375 },
1376
1377 // test parentheses in autofix
1378 {
1379 code: "Boolean(!!(a, b))",
1380 output: "Boolean((a, b))",
1381 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1382 },
1383 {
1384 code: "Boolean(Boolean((a, b)))",
1385 output: "Boolean((a, b))",
1386 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1387 },
1388 {
1389 code: "Boolean((!!(a, b)))",
1390 output: "Boolean((a, b))",
1391 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1392 },
1393 {
1394 code: "Boolean((Boolean((a, b))))",
1395 output: "Boolean((a, b))",
1396 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1397 },
1398 {
1399 code: "Boolean(!(!(a, b)))",
1400 output: "Boolean((a, b))",
1401 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1402 },
1403 {
1404 code: "Boolean((!(!(a, b))))",
1405 output: "Boolean((a, b))",
1406 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1407 },
1408 {
1409 code: "Boolean(!!(a = b))",
1410 output: "Boolean(a = b)",
1411 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1412 },
1413 {
1414 code: "Boolean((!!(a = b)))",
1415 output: "Boolean((a = b))",
1416 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1417 },
1418 {
1419 code: "Boolean(Boolean(a = b))",
1420 output: "Boolean(a = b)",
1421 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1422 },
1423 {
1424 code: "Boolean(Boolean((a += b)))",
1425 output: "Boolean(a += b)",
1426 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1427 },
1428 {
1429 code: "Boolean(!!(a === b))",
1430 output: "Boolean(a === b)",
1431 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1432 },
1433 {
1434 code: "Boolean(!!((a !== b)))",
1435 output: "Boolean(a !== b)",
1436 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1437 },
1438 {
1439 code: "Boolean(!!a.b)",
1440 output: "Boolean(a.b)",
1441 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1442 },
1443 {
1444 code: "Boolean(Boolean((a)))",
1445 output: "Boolean(a)",
1446 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1447 },
1448 {
1449 code: "Boolean((!!(a)))",
1450 output: "Boolean((a))",
1451 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1452 },
1453
1454 {
1455 code: "new Boolean(!!(a, b))",
1456 output: "new Boolean((a, b))",
1457 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1458 },
1459 {
1460 code: "new Boolean(Boolean((a, b)))",
1461 output: "new Boolean((a, b))",
1462 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1463 },
1464 {
1465 code: "new Boolean((!!(a, b)))",
1466 output: "new Boolean((a, b))",
1467 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1468 },
1469 {
1470 code: "new Boolean((Boolean((a, b))))",
1471 output: "new Boolean((a, b))",
1472 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1473 },
1474 {
1475 code: "new Boolean(!(!(a, b)))",
1476 output: "new Boolean((a, b))",
1477 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1478 },
1479 {
1480 code: "new Boolean((!(!(a, b))))",
1481 output: "new Boolean((a, b))",
1482 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1483 },
1484 {
1485 code: "new Boolean(!!(a = b))",
1486 output: "new Boolean(a = b)",
1487 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1488 },
1489 {
1490 code: "new Boolean((!!(a = b)))",
1491 output: "new Boolean((a = b))",
1492 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1493 },
1494 {
1495 code: "new Boolean(Boolean(a = b))",
1496 output: "new Boolean(a = b)",
1497 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1498 },
1499 {
1500 code: "new Boolean(Boolean((a += b)))",
1501 output: "new Boolean(a += b)",
1502 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1503 },
1504 {
1505 code: "new Boolean(!!(a === b))",
1506 output: "new Boolean(a === b)",
1507 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1508 },
1509 {
1510 code: "new Boolean(!!((a !== b)))",
1511 output: "new Boolean(a !== b)",
1512 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1513 },
1514 {
1515 code: "new Boolean(!!a.b)",
1516 output: "new Boolean(a.b)",
1517 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1518 },
1519 {
1520 code: "new Boolean(Boolean((a)))",
1521 output: "new Boolean(a)",
1522 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1523 },
1524 {
1525 code: "new Boolean((!!(a)))",
1526 output: "new Boolean((a))",
1527 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1528 },
1529 {
1530 code: "if (!!(a, b));",
1531 output: "if (a, b);",
1532 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1533 },
1534 {
1535 code: "if (Boolean((a, b)));",
1536 output: "if (a, b);",
1537 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1538 },
1539 {
1540 code: "if (!(!(a, b)));",
1541 output: "if (a, b);",
1542 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1543 },
1544 {
1545 code: "if (!!(a = b));",
1546 output: "if (a = b);",
1547 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1548 },
1549 {
1550 code: "if (Boolean(a = b));",
1551 output: "if (a = b);",
1552 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1553 },
1554 {
1555 code: "if (!!(a > b));",
1556 output: "if (a > b);",
1557 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1558 },
1559 {
1560 code: "if (Boolean(a === b));",
1561 output: "if (a === b);",
1562 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1563 },
1564 {
1565 code: "if (!!f(a));",
1566 output: "if (f(a));",
1567 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1568 },
1569 {
1570 code: "if (Boolean(f(a)));",
1571 output: "if (f(a));",
1572 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1573 },
1574 {
1575 code: "if (!!(f(a)));",
1576 output: "if (f(a));",
1577 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1578 },
1579 {
1580 code: "if ((!!f(a)));",
1581 output: "if ((f(a)));",
1582 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1583 },
1584 {
1585 code: "if ((Boolean(f(a))));",
1586 output: "if ((f(a)));",
1587 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1588 },
1589 {
1590 code: "if (!!a);",
1591 output: "if (a);",
1592 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1593 },
1594 {
1595 code: "if (Boolean(a));",
1596 output: "if (a);",
1597 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1598 },
1599 {
1600 code: "while (!!(a, b));",
1601 output: "while (a, b);",
1602 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1603 },
1604 {
1605 code: "while (Boolean((a, b)));",
1606 output: "while (a, b);",
1607 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1608 },
1609 {
1610 code: "while (!(!(a, b)));",
1611 output: "while (a, b);",
1612 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1613 },
1614 {
1615 code: "while (!!(a = b));",
1616 output: "while (a = b);",
1617 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1618 },
1619 {
1620 code: "while (Boolean(a = b));",
1621 output: "while (a = b);",
1622 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1623 },
1624 {
1625 code: "while (!!(a > b));",
1626 output: "while (a > b);",
1627 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1628 },
1629 {
1630 code: "while (Boolean(a === b));",
1631 output: "while (a === b);",
1632 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1633 },
1634 {
1635 code: "while (!!f(a));",
1636 output: "while (f(a));",
1637 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1638 },
1639 {
1640 code: "while (Boolean(f(a)));",
1641 output: "while (f(a));",
1642 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1643 },
1644 {
1645 code: "while (!!(f(a)));",
1646 output: "while (f(a));",
1647 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1648 },
1649 {
1650 code: "while ((!!f(a)));",
1651 output: "while ((f(a)));",
1652 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1653 },
1654 {
1655 code: "while ((Boolean(f(a))));",
1656 output: "while ((f(a)));",
1657 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1658 },
1659 {
1660 code: "while (!!a);",
1661 output: "while (a);",
1662 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1663 },
1664 {
1665 code: "while (Boolean(a));",
1666 output: "while (a);",
1667 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1668 },
1669 {
1670 code: "do {} while (!!(a, b));",
1671 output: "do {} while (a, b);",
1672 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1673 },
1674 {
1675 code: "do {} while (Boolean((a, b)));",
1676 output: "do {} while (a, b);",
1677 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1678 },
1679 {
1680 code: "do {} while (!(!(a, b)));",
1681 output: "do {} while (a, b);",
1682 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1683 },
1684 {
1685 code: "do {} while (!!(a = b));",
1686 output: "do {} while (a = b);",
1687 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1688 },
1689 {
1690 code: "do {} while (Boolean(a = b));",
1691 output: "do {} while (a = b);",
1692 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1693 },
1694 {
1695 code: "do {} while (!!(a > b));",
1696 output: "do {} while (a > b);",
1697 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1698 },
1699 {
1700 code: "do {} while (Boolean(a === b));",
1701 output: "do {} while (a === b);",
1702 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1703 },
1704 {
1705 code: "do {} while (!!f(a));",
1706 output: "do {} while (f(a));",
1707 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1708 },
1709 {
1710 code: "do {} while (Boolean(f(a)));",
1711 output: "do {} while (f(a));",
1712 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1713 },
1714 {
1715 code: "do {} while (!!(f(a)));",
1716 output: "do {} while (f(a));",
1717 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1718 },
1719 {
1720 code: "do {} while ((!!f(a)));",
1721 output: "do {} while ((f(a)));",
1722 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1723 },
1724 {
1725 code: "do {} while ((Boolean(f(a))));",
1726 output: "do {} while ((f(a)));",
1727 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1728 },
1729 {
1730 code: "do {} while (!!a);",
1731 output: "do {} while (a);",
1732 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1733 },
1734 {
1735 code: "do {} while (Boolean(a));",
1736 output: "do {} while (a);",
1737 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1738 },
1739 {
1740 code: "for (; !!(a, b););",
1741 output: "for (; a, b;);",
1742 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1743 },
1744 {
1745 code: "for (; Boolean((a, b)););",
1746 output: "for (; a, b;);",
1747 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1748 },
1749 {
1750 code: "for (; !(!(a, b)););",
1751 output: "for (; a, b;);",
1752 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1753 },
1754 {
1755 code: "for (; !!(a = b););",
1756 output: "for (; a = b;);",
1757 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1758 },
1759 {
1760 code: "for (; Boolean(a = b););",
1761 output: "for (; a = b;);",
1762 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1763 },
1764 {
1765 code: "for (; !!(a > b););",
1766 output: "for (; a > b;);",
1767 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1768 },
1769 {
1770 code: "for (; Boolean(a === b););",
1771 output: "for (; a === b;);",
1772 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1773 },
1774 {
1775 code: "for (; !!f(a););",
1776 output: "for (; f(a););",
1777 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1778 },
1779 {
1780 code: "for (; Boolean(f(a)););",
1781 output: "for (; f(a););",
1782 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1783 },
1784 {
1785 code: "for (; !!(f(a)););",
1786 output: "for (; f(a););",
1787 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1788 },
1789 {
1790 code: "for (; (!!f(a)););",
1791 output: "for (; (f(a)););",
1792 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1793 },
1794 {
1795 code: "for (; (Boolean(f(a))););",
1796 output: "for (; (f(a)););",
1797 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1798 },
1799 {
1800 code: "for (; !!a;);",
1801 output: "for (; a;);",
1802 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1803 },
1804 {
1805 code: "for (; Boolean(a););",
1806 output: "for (; a;);",
1807 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1808 },
1809 {
1810 code: "!!(a, b) ? c : d",
1811 output: "(a, b) ? c : d",
1812 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1813 },
1814 {
1815 code: "(!!(a, b)) ? c : d",
1816 output: "(a, b) ? c : d",
1817 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1818 },
1819 {
1820 code: "Boolean((a, b)) ? c : d",
1821 output: "(a, b) ? c : d",
1822 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1823 },
1824 {
1825 code: "!!(a = b) ? c : d",
1826 output: "(a = b) ? c : d",
1827 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1828 },
1829 {
1830 code: "Boolean(a -= b) ? c : d",
1831 output: "(a -= b) ? c : d",
1832 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1833 },
1834 {
1835 code: "(Boolean((a *= b))) ? c : d",
1836 output: "(a *= b) ? c : d",
1837 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1838 },
1839 {
1840 code: "!!(a ? b : c) ? d : e",
1841 output: "(a ? b : c) ? d : e",
1842 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1843 },
1844 {
1845 code: "Boolean(a ? b : c) ? d : e",
1846 output: "(a ? b : c) ? d : e",
1847 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1848 },
1849 {
1850 code: "!!(a || b) ? c : d",
1851 output: "a || b ? c : d",
1852 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1853 },
1854 {
1855 code: "Boolean(a && b) ? c : d",
1856 output: "a && b ? c : d",
1857 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1858 },
1859 {
1860 code: "!!(a === b) ? c : d",
1861 output: "a === b ? c : d",
1862 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1863 },
1864 {
1865 code: "Boolean(a < b) ? c : d",
1866 output: "a < b ? c : d",
1867 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1868 },
1869 {
1870 code: "!!((a !== b)) ? c : d",
1871 output: "a !== b ? c : d",
1872 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1873 },
1874 {
1875 code: "Boolean((a >= b)) ? c : d",
1876 output: "a >= b ? c : d",
1877 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1878 },
1879 {
1880 code: "!!+a ? b : c",
1881 output: "+a ? b : c",
1882 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1883 },
1884 {
1885 code: "!!+(a) ? b : c",
1886 output: "+(a) ? b : c",
1887 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1888 },
1889 {
1890 code: "Boolean(!a) ? b : c",
1891 output: "!a ? b : c",
1892 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1893 },
1894 {
1895 code: "!!f(a) ? b : c",
1896 output: "f(a) ? b : c",
1897 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1898 },
1899 {
1900 code: "(!!f(a)) ? b : c",
1901 output: "(f(a)) ? b : c",
1902 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1903 },
1904 {
1905 code: "Boolean(a.b) ? c : d",
1906 output: "a.b ? c : d",
1907 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1908 },
1909 {
1910 code: "!!a ? b : c",
1911 output: "a ? b : c",
1912 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1913 },
1914 {
1915 code: "Boolean(a) ? b : c",
1916 output: "a ? b : c",
1917 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1918 },
1919 {
1920 code: "!!!(a, b)",
1921 output: "!(a, b)",
1922 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1923 },
1924 {
1925 code: "!Boolean((a, b))",
1926 output: "!(a, b)",
1927 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1928 },
1929 {
1930 code: "!!!(a = b)",
1931 output: "!(a = b)",
1932 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1933 },
1934 {
1935 code: "!!(!(a += b))",
1936 output: "!(a += b)",
1937 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1938 },
1939 {
1940 code: "!(!!(a += b))",
1941 output: "!(a += b)",
1942 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1943 },
1944 {
1945 code: "!Boolean(a -= b)",
1946 output: "!(a -= b)",
1947 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1948 },
1949 {
1950 code: "!Boolean((a -= b))",
1951 output: "!(a -= b)",
1952 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1953 },
1954 {
1955 code: "!(Boolean(a -= b))",
1956 output: "!(a -= b)",
1957 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1958 },
1959 {
1960 code: "!!!(a || b)",
1961 output: "!(a || b)",
1962 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1963 },
1964 {
1965 code: "!Boolean(a || b)",
1966 output: "!(a || b)",
1967 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1968 },
1969 {
1970 code: "!!!(a && b)",
1971 output: "!(a && b)",
1972 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1973 },
1974 {
1975 code: "!Boolean(a && b)",
1976 output: "!(a && b)",
1977 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1978 },
1979 {
1980 code: "!!!(a != b)",
1981 output: "!(a != b)",
1982 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1983 },
1984 {
1985 code: "!!!(a === b)",
1986 output: "!(a === b)",
1987 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1988 },
1989 {
1990 code: "var x = !Boolean(a > b)",
1991 output: "var x = !(a > b)",
1992 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
1993 },
1994 {
1995 code: "!!!(a - b)",
1996 output: "!(a - b)",
1997 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
1998 },
1999 {
2000 code: "!!!(a ** b)",
2001 output: "!(a ** b)",
2002 parserOptions: { ecmaVersion: 2016 },
2003 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
2004 },
2005 {
2006 code: "!Boolean(a ** b)",
2007 output: "!(a ** b)",
2008 parserOptions: { ecmaVersion: 2016 },
2009 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
2010 },
2011 {
2012 code: "async function f() { !!!(await a) }",
2013 output: "async function f() { !await a }",
2014 parserOptions: { ecmaVersion: 2017 },
2015 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
2016 },
2017 {
2018 code: "async function f() { !Boolean(await a) }",
2019 output: "async function f() { !await a }",
2020 parserOptions: { ecmaVersion: 2017 },
2021 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
2022 },
2023 {
2024 code: "!!!!a",
2025 output: "!!a", // Reports 2 errors. After the first fix, the second error will disappear.
2026 errors: [
2027 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2028 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2029 ]
2030 },
2031 {
2032 code: "!!(!(!a))",
2033 output: "!!a", // Reports 2 errors. After the first fix, the second error will disappear.
2034 errors: [
2035 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2036 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2037 ]
2038 },
2039 {
2040 code: "!Boolean(!a)",
2041 output: "!!a",
2042 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
2043 },
2044 {
2045 code: "!Boolean((!a))",
2046 output: "!!a",
2047 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
2048 },
2049 {
2050 code: "!Boolean(!(a))",
2051 output: "!!(a)",
2052 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
2053 },
2054 {
2055 code: "!(Boolean(!a))",
2056 output: "!(!a)",
2057 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
2058 },
2059 {
2060 code: "!!!+a",
2061 output: "!+a",
2062 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
2063 },
2064 {
2065 code: "!!!(+a)",
2066 output: "!+a",
2067 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
2068 },
2069 {
2070 code: "!!(!+a)",
2071 output: "!+a",
2072 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
2073 },
2074 {
2075 code: "!(!!+a)",
2076 output: "!(+a)",
2077 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
2078 },
2079 {
2080 code: "!Boolean((-a))",
2081 output: "!-a",
2082 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
2083 },
2084 {
2085 code: "!Boolean(-(a))",
2086 output: "!-(a)",
2087 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
2088 },
2089 {
2090 code: "!!!(--a)",
2091 output: "!--a",
2092 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
2093 },
2094 {
2095 code: "!Boolean(a++)",
2096 output: "!a++",
2097 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
2098 },
2099 {
2100 code: "!!!f(a)",
2101 output: "!f(a)",
2102 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
2103 },
2104 {
2105 code: "!!!(f(a))",
2106 output: "!f(a)",
2107 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
2108 },
2109 {
2110 code: "!!!a",
2111 output: "!a",
2112 errors: [{ messageId: "unexpectedNegation", type: "UnaryExpression" }]
2113 },
2114 {
2115 code: "!Boolean(a)",
2116 output: "!a",
2117 errors: [{ messageId: "unexpectedCall", type: "CallExpression" }]
2118 },
2119 {
2120 code: "if (!!(a, b) || !!(c, d)) {}",
2121 output: "if ((a, b) || (c, d)) {}",
2122 options: [{ enforceForLogicalOperands: true }],
2123 errors: [
2124 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2125 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2126 ]
2127 },
2128 {
2129 code: "if (Boolean((a, b)) || Boolean((c, d))) {}",
2130 output: "if ((a, b) || (c, d)) {}",
2131 options: [{ enforceForLogicalOperands: true }],
2132 errors: [
2133 { messageId: "unexpectedCall", type: "CallExpression" },
2134 { messageId: "unexpectedCall", type: "CallExpression" }
2135 ]
2136 },
2137 {
2138 code: "if ((!!((a, b))) || (!!((c, d)))) {}",
2139 output: "if ((a, b) || (c, d)) {}",
2140 options: [{ enforceForLogicalOperands: true }],
2141 errors: [
2142 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2143 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2144 ]
2145 },
2146 {
2147 code: "if (!!(a, b) && !!(c, d)) {}",
2148 output: "if ((a, b) && (c, d)) {}",
2149 options: [{ enforceForLogicalOperands: true }],
2150 errors: [
2151 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2152 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2153 ]
2154 },
2155 {
2156 code: "if (Boolean((a, b)) && Boolean((c, d))) {}",
2157 output: "if ((a, b) && (c, d)) {}",
2158 options: [{ enforceForLogicalOperands: true }],
2159 errors: [
2160 { messageId: "unexpectedCall", type: "CallExpression" },
2161 { messageId: "unexpectedCall", type: "CallExpression" }
2162 ]
2163 },
2164 {
2165 code: "if ((!!((a, b))) && (!!((c, d)))) {}",
2166 output: "if ((a, b) && (c, d)) {}",
2167 options: [{ enforceForLogicalOperands: true }],
2168 errors: [
2169 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2170 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2171 ]
2172 },
2173 {
2174 code: "if (!!(a = b) || !!(c = d)) {}",
2175 output: "if ((a = b) || (c = d)) {}",
2176 options: [{ enforceForLogicalOperands: true }],
2177 errors: [
2178 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2179 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2180 ]
2181 },
2182 {
2183 code: "if (Boolean(a /= b) || Boolean(c /= d)) {}",
2184 output: "if ((a /= b) || (c /= d)) {}",
2185 options: [{ enforceForLogicalOperands: true }],
2186 errors: [
2187 { messageId: "unexpectedCall", type: "CallExpression" },
2188 { messageId: "unexpectedCall", type: "CallExpression" }
2189 ]
2190 },
2191 {
2192 code: "if (!!(a >>= b) && !!(c >>= d)) {}",
2193 output: "if ((a >>= b) && (c >>= d)) {}",
2194 options: [{ enforceForLogicalOperands: true }],
2195 errors: [
2196 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2197 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2198 ]
2199 },
2200 {
2201 code: "if (Boolean(a **= b) && Boolean(c **= d)) {}",
2202 output: "if ((a **= b) && (c **= d)) {}",
2203 options: [{ enforceForLogicalOperands: true }],
2204 parserOptions: { ecmaVersion: 2016 },
2205 errors: [
2206 { messageId: "unexpectedCall", type: "CallExpression" },
2207 { messageId: "unexpectedCall", type: "CallExpression" }
2208 ]
2209 },
2210 {
2211 code: "if (!!(a ? b : c) || !!(d ? e : f)) {}",
2212 output: "if ((a ? b : c) || (d ? e : f)) {}",
2213 options: [{ enforceForLogicalOperands: true }],
2214 errors: [
2215 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2216 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2217 ]
2218 },
2219 {
2220 code: "if (Boolean(a ? b : c) || Boolean(d ? e : f)) {}",
2221 output: "if ((a ? b : c) || (d ? e : f)) {}",
2222 options: [{ enforceForLogicalOperands: true }],
2223 errors: [
2224 { messageId: "unexpectedCall", type: "CallExpression" },
2225 { messageId: "unexpectedCall", type: "CallExpression" }
2226 ]
2227 },
2228 {
2229 code: "if (!!(a ? b : c) && !!(d ? e : f)) {}",
2230 output: "if ((a ? b : c) && (d ? e : f)) {}",
2231 options: [{ enforceForLogicalOperands: true }],
2232 errors: [
2233 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2234 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2235 ]
2236 },
2237 {
2238 code: "if (Boolean(a ? b : c) && Boolean(d ? e : f)) {}",
2239 output: "if ((a ? b : c) && (d ? e : f)) {}",
2240 options: [{ enforceForLogicalOperands: true }],
2241 errors: [
2242 { messageId: "unexpectedCall", type: "CallExpression" },
2243 { messageId: "unexpectedCall", type: "CallExpression" }
2244 ]
2245 },
2246 {
2247 code: "if (!!(a || b) || !!(c || d)) {}",
2248 output: "if (a || b || (c || d)) {}",
2249 options: [{ enforceForLogicalOperands: true }],
2250 errors: [
2251 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2252 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2253 ]
2254 },
2255 {
2256 code: "if (Boolean(a || b) || Boolean(c || d)) {}",
2257 output: "if (a || b || (c || d)) {}",
2258 options: [{ enforceForLogicalOperands: true }],
2259 errors: [
2260 { messageId: "unexpectedCall", type: "CallExpression" },
2261 { messageId: "unexpectedCall", type: "CallExpression" }
2262 ]
2263 },
2264 {
2265 code: "if (!!(a || b) && !!(c || d)) {}",
2266 output: "if ((a || b) && (c || d)) {}",
2267 options: [{ enforceForLogicalOperands: true }],
2268 errors: [
2269 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2270 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2271 ]
2272 },
2273 {
2274 code: "if (Boolean(a || b) && Boolean(c || d)) {}",
2275 output: "if ((a || b) && (c || d)) {}",
2276 options: [{ enforceForLogicalOperands: true }],
2277 errors: [
2278 { messageId: "unexpectedCall", type: "CallExpression" },
2279 { messageId: "unexpectedCall", type: "CallExpression" }
2280 ]
2281 },
2282 {
2283 code: "if (!!(a && b) || !!(c && d)) {}",
2284 output: "if (a && b || c && d) {}",
2285 options: [{ enforceForLogicalOperands: true }],
2286 errors: [
2287 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2288 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2289 ]
2290 },
2291 {
2292 code: "if (Boolean(a && b) || Boolean(c && d)) {}",
2293 output: "if (a && b || c && d) {}",
2294 options: [{ enforceForLogicalOperands: true }],
2295 errors: [
2296 { messageId: "unexpectedCall", type: "CallExpression" },
2297 { messageId: "unexpectedCall", type: "CallExpression" }
2298 ]
2299 },
2300 {
2301 code: "if (!!(a && b) && !!(c && d)) {}",
2302 output: "if (a && b && (c && d)) {}",
2303 options: [{ enforceForLogicalOperands: true }],
2304 errors: [
2305 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2306 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2307 ]
2308 },
2309 {
2310 code: "if (Boolean(a && b) && Boolean(c && d)) {}",
2311 output: "if (a && b && (c && d)) {}",
2312 options: [{ enforceForLogicalOperands: true }],
2313 errors: [
2314 { messageId: "unexpectedCall", type: "CallExpression" },
2315 { messageId: "unexpectedCall", type: "CallExpression" }
2316 ]
2317 },
2318 {
2319 code: "if (!!(a !== b) || !!(c !== d)) {}",
2320 output: "if (a !== b || c !== d) {}",
2321 options: [{ enforceForLogicalOperands: true }],
2322 errors: [
2323 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2324 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2325 ]
2326 },
2327 {
2328 code: "if (Boolean(a != b) || Boolean(c != d)) {}",
2329 output: "if (a != b || c != d) {}",
2330 options: [{ enforceForLogicalOperands: true }],
2331 errors: [
2332 { messageId: "unexpectedCall", type: "CallExpression" },
2333 { messageId: "unexpectedCall", type: "CallExpression" }
2334 ]
2335 },
2336 {
2337 code: "if (!!(a === b) && !!(c === d)) {}",
2338 output: "if (a === b && c === d) {}",
2339 options: [{ enforceForLogicalOperands: true }],
2340 errors: [
2341 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2342 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2343 ]
2344 },
2345 {
2346 code: "if (!!(a > b) || !!(c < d)) {}",
2347 output: "if (a > b || c < d) {}",
2348 options: [{ enforceForLogicalOperands: true }],
2349 errors: [
2350 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2351 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2352 ]
2353 },
2354 {
2355 code: "if (Boolean(!a) || Boolean(+b)) {}",
2356 output: "if (!a || +b) {}",
2357 options: [{ enforceForLogicalOperands: true }],
2358 errors: [
2359 { messageId: "unexpectedCall", type: "CallExpression" },
2360 { messageId: "unexpectedCall", type: "CallExpression" }
2361 ]
2362 },
2363 {
2364 code: "if (!!f(a) && !!b.c) {}",
2365 output: "if (f(a) && b.c) {}",
2366 options: [{ enforceForLogicalOperands: true }],
2367 errors: [
2368 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2369 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2370 ]
2371 },
2372 {
2373 code: "if (Boolean(a) || !!b) {}",
2374 output: "if (a || b) {}",
2375 options: [{ enforceForLogicalOperands: true }],
2376 errors: [
2377 { messageId: "unexpectedCall", type: "CallExpression" },
2378 { messageId: "unexpectedNegation", type: "UnaryExpression" }
2379 ]
2380 },
2381 {
2382 code: "if (!!a && Boolean(b)) {}",
2383 output: "if (a && b) {}",
2384 options: [{ enforceForLogicalOperands: true }],
2385 errors: [
2386 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2387 { messageId: "unexpectedCall", type: "CallExpression" }
2388 ]
2389 },
2390 {
2391 code: "if ((!!a) || (Boolean(b))) {}",
2392 output: "if ((a) || (b)) {}",
2393 options: [{ enforceForLogicalOperands: true }],
2394 errors: [
2395 { messageId: "unexpectedNegation", type: "UnaryExpression" },
2396 { messageId: "unexpectedCall", type: "CallExpression" }
2397 ]
2398 }
2399 ]
2400 });