2 * @fileoverview Tests for no-extra-boolean-cast rule.
3 * @author Brandon Mills
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/no-extra-boolean-cast"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("no-extra-boolean-cast", rule
, {
24 "Boolean(bar, !!baz);",
26 "function foo() { return !!bar; }",
27 "var foo = bar() ? !!baz : !!bat",
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)) {}",
37 code
: "var foo = bar || !!baz",
38 options
: [{ enforceForLogicalOperands
: true }]
41 code
: "var foo = bar && !!baz",
42 options
: [{ enforceForLogicalOperands
: true }]
45 code
: "var foo = bar || (baz && !!bat)",
46 options
: [{ enforceForLogicalOperands
: true }]
49 code
: "function foo() { return (!!bar || baz); }",
50 options
: [{ enforceForLogicalOperands
: true }]
53 code
: "var foo = bar() ? (!!baz && bat) : (!!bat && qux)",
54 options
: [{ enforceForLogicalOperands
: true }]
57 code
: "for(!!(foo && bar);;) {}",
58 options
: [{ enforceForLogicalOperands
: true }]
61 code
: "for(;; !!(foo || bar)) {}",
62 options
: [{ enforceForLogicalOperands
: true }]
65 code
: "var foo = Boolean(bar) || baz;",
66 options
: [{ enforceForLogicalOperands
: true }]
69 code
: "var foo = bar || Boolean(baz);",
70 options
: [{ enforceForLogicalOperands
: true }]
73 code
: "var foo = Boolean(bar) || Boolean(baz);",
74 options
: [{ enforceForLogicalOperands
: true }]
77 code
: "function foo() { return (Boolean(bar) || baz); }",
78 options
: [{ enforceForLogicalOperands
: true }]
81 code
: "var foo = bar() ? Boolean(baz) || bat : Boolean(bat)",
82 options
: [{ enforceForLogicalOperands
: true }]
85 code
: "for(Boolean(foo) || bar;;) {}",
86 options
: [{ enforceForLogicalOperands
: true }]
89 code
: "for(;; Boolean(foo) || bar) {}",
90 options
: [{ enforceForLogicalOperands
: true }]
93 code
: "if (new Boolean(foo) || bar) {}",
94 options
: [{ enforceForLogicalOperands
: true }]
96 "if (!!foo || bar) {}",
98 code
: "if (!!foo || bar) {}",
102 code
: "if (!!foo || bar) {}",
103 options
: [{ enforceForLogicalOperands
: false }]
106 code
: "if ((!!foo || bar) === baz) {}",
107 options
: [{ enforceForLogicalOperands
: true }]
113 code
: "if (!!foo) {}",
114 output
: "if (foo) {}",
116 messageId
: "unexpectedNegation",
117 type
: "UnaryExpression",
123 code
: "do {} while (!!foo)",
124 output
: "do {} while (foo)",
126 messageId
: "unexpectedNegation",
127 type
: "UnaryExpression",
132 code
: "while (!!foo) {}",
133 output
: "while (foo) {}",
135 messageId
: "unexpectedNegation",
136 type
: "UnaryExpression",
141 code
: "!!foo ? bar : baz",
142 output
: "foo ? bar : baz",
144 messageId
: "unexpectedNegation",
145 type
: "UnaryExpression",
150 code
: "for (; !!foo;) {}",
151 output
: "for (; foo;) {}",
153 messageId
: "unexpectedNegation",
154 type
: "UnaryExpression",
162 messageId
: "unexpectedNegation",
163 type
: "UnaryExpression",
168 code
: "Boolean(!!foo)",
169 output
: "Boolean(foo)",
171 messageId
: "unexpectedNegation",
172 type
: "UnaryExpression",
177 code
: "new Boolean(!!foo)",
178 output
: "new Boolean(foo)",
180 messageId
: "unexpectedNegation",
181 type
: "UnaryExpression",
186 code
: "if (Boolean(foo)) {}",
187 output
: "if (foo) {}",
189 messageId
: "unexpectedCall",
190 type
: "CallExpression"
194 code
: "do {} while (Boolean(foo))",
195 output
: "do {} while (foo)",
197 messageId
: "unexpectedCall",
198 type
: "CallExpression"
202 code
: "while (Boolean(foo)) {}",
203 output
: "while (foo) {}",
205 messageId
: "unexpectedCall",
206 type
: "CallExpression"
210 code
: "Boolean(foo) ? bar : baz",
211 output
: "foo ? bar : baz",
213 messageId
: "unexpectedCall",
214 type
: "CallExpression"
218 code
: "for (; Boolean(foo);) {}",
219 output
: "for (; foo;) {}",
221 messageId
: "unexpectedCall",
222 type
: "CallExpression"
226 code
: "!Boolean(foo)",
229 messageId
: "unexpectedCall",
230 type
: "CallExpression"
234 code
: "!Boolean(foo && bar)",
235 output
: "!(foo && bar)",
237 messageId
: "unexpectedCall",
238 type
: "CallExpression"
242 code
: "!Boolean(foo + bar)",
243 output
: "!(foo + bar)",
245 messageId
: "unexpectedCall",
246 type
: "CallExpression"
250 code
: "!Boolean(+foo)",
253 messageId
: "unexpectedCall",
254 type
: "CallExpression"
258 code
: "!Boolean(foo())",
261 messageId
: "unexpectedCall",
262 type
: "CallExpression"
266 code
: "!Boolean(foo = bar)",
267 output
: "!(foo = bar)",
269 messageId
: "unexpectedCall",
270 type
: "CallExpression"
274 code
: "!Boolean(...foo);",
276 parserOptions
: { ecmaVersion
: 2015 },
278 messageId
: "unexpectedCall",
279 type
: "CallExpression"
283 code
: "!Boolean(foo, bar());",
286 messageId
: "unexpectedCall",
287 type
: "CallExpression"
291 code
: "!Boolean((foo, bar()));",
292 output
: "!(foo, bar());",
294 messageId
: "unexpectedCall",
295 type
: "CallExpression"
302 messageId
: "unexpectedCall",
303 type
: "CallExpression"
307 code
: "!(Boolean());",
310 messageId
: "unexpectedCall",
311 type
: "CallExpression"
315 code
: "if (!Boolean()) { foo() }",
316 output
: "if (true) { foo() }",
318 messageId
: "unexpectedCall",
319 type
: "CallExpression"
323 code
: "while (!Boolean()) { foo() }",
324 output
: "while (true) { foo() }",
326 messageId
: "unexpectedCall",
327 type
: "CallExpression"
331 code
: "var foo = Boolean() ? bar() : baz()",
332 output
: "var foo = false ? bar() : baz()",
334 messageId
: "unexpectedCall",
335 type
: "CallExpression"
339 code
: "if (Boolean()) { foo() }",
340 output
: "if (false) { foo() }",
342 messageId
: "unexpectedCall",
343 type
: "CallExpression"
347 code
: "while (Boolean()) { foo() }",
348 output
: "while (false) { foo() }",
350 messageId
: "unexpectedCall",
351 type
: "CallExpression"
355 code
: "Boolean(Boolean(foo))",
356 output
: "Boolean(foo)",
358 messageId
: "unexpectedCall",
359 type
: "CallExpression"
363 code
: "Boolean(!!foo, bar)",
364 output
: "Boolean(foo, bar)",
366 messageId
: "unexpectedNegation",
367 type
: "UnaryExpression"
372 // Adjacent tokens tests
374 code
: "function *foo() { yield!!a ? b : c }",
375 output
: "function *foo() { yield a ? b : c }",
376 parserOptions
: { ecmaVersion
: 2015 },
378 messageId
: "unexpectedNegation",
379 type
: "UnaryExpression"
383 code
: "function *foo() { yield!! a ? b : c }",
384 output
: "function *foo() { yield a ? b : c }",
385 parserOptions
: { ecmaVersion
: 2015 },
387 messageId
: "unexpectedNegation",
388 type
: "UnaryExpression"
392 code
: "function *foo() { yield! !a ? b : c }",
393 output
: "function *foo() { yield a ? b : c }",
394 parserOptions
: { ecmaVersion
: 2015 },
396 messageId
: "unexpectedNegation",
397 type
: "UnaryExpression"
401 code
: "function *foo() { yield !!a ? b : c }",
402 output
: "function *foo() { yield a ? b : c }",
403 parserOptions
: { ecmaVersion
: 2015 },
405 messageId
: "unexpectedNegation",
406 type
: "UnaryExpression"
410 code
: "function *foo() { yield(!!a) ? b : c }",
411 output
: "function *foo() { yield(a) ? b : c }",
412 parserOptions
: { ecmaVersion
: 2015 },
414 messageId
: "unexpectedNegation",
415 type
: "UnaryExpression"
419 code
: "function *foo() { yield/**/!!a ? b : c }",
420 output
: "function *foo() { yield/**/a ? b : c }",
421 parserOptions
: { ecmaVersion
: 2015 },
423 messageId
: "unexpectedNegation",
424 type
: "UnaryExpression"
428 code
: "x=!!a ? b : c ",
429 output
: "x=a ? b : c ",
431 messageId
: "unexpectedNegation",
432 type
: "UnaryExpression"
436 code
: "void!Boolean()",
439 messageId
: "unexpectedCall",
440 type
: "CallExpression"
444 code
: "void! Boolean()",
447 messageId
: "unexpectedCall",
448 type
: "CallExpression"
452 code
: "typeof!Boolean()",
453 output
: "typeof true",
455 messageId
: "unexpectedCall",
456 type
: "CallExpression"
460 code
: "(!Boolean())",
463 messageId
: "unexpectedCall",
464 type
: "CallExpression"
471 messageId
: "unexpectedCall",
472 type
: "CallExpression"
476 code
: "void !Boolean()",
479 messageId
: "unexpectedCall",
480 type
: "CallExpression"
484 code
: "void(!Boolean())",
485 output
: "void(true)",
487 messageId
: "unexpectedCall",
488 type
: "CallExpression"
492 code
: "void/**/!Boolean()",
493 output
: "void/**/true",
495 messageId
: "unexpectedCall",
496 type
: "CallExpression"
505 messageId
: "unexpectedNegation",
506 type
: "UnaryExpression"
513 messageId
: "unexpectedNegation",
514 type
: "UnaryExpression"
521 messageId
: "unexpectedNegation",
522 type
: "UnaryExpression"
529 messageId
: "unexpectedNegation",
530 type
: "UnaryExpression"
534 code
: "if(!/**/!foo);",
537 messageId
: "unexpectedNegation",
538 type
: "UnaryExpression"
542 code
: "(!!/**/foo ? 1 : 2)",
545 messageId
: "unexpectedNegation",
546 type
: "UnaryExpression"
550 code
: "!/**/Boolean(foo)",
553 messageId
: "unexpectedCall",
554 type
: "CallExpression"
558 code
: "!Boolean/**/(foo)",
561 messageId
: "unexpectedCall",
562 type
: "CallExpression"
566 code
: "!Boolean(/**/foo)",
569 messageId
: "unexpectedCall",
570 type
: "CallExpression"
574 code
: "!Boolean(foo/**/)",
577 messageId
: "unexpectedCall",
578 type
: "CallExpression"
582 code
: "!Boolean(foo)/**/",
585 messageId
: "unexpectedCall",
586 type
: "CallExpression"
590 code
: "if(Boolean/**/(foo));",
593 messageId
: "unexpectedCall",
594 type
: "CallExpression"
598 code
: "(Boolean(foo/**/) ? 1 : 2)",
601 messageId
: "unexpectedCall",
602 type
: "CallExpression"
606 code
: "/**/!Boolean()",
609 messageId
: "unexpectedCall",
610 type
: "CallExpression"
614 code
: "!/**/Boolean()",
617 messageId
: "unexpectedCall",
618 type
: "CallExpression"
622 code
: "!Boolean/**/()",
625 messageId
: "unexpectedCall",
626 type
: "CallExpression"
630 code
: "!Boolean(/**/)",
633 messageId
: "unexpectedCall",
634 type
: "CallExpression"
638 code
: "!Boolean()/**/",
641 messageId
: "unexpectedCall",
642 type
: "CallExpression"
646 code
: "if(!/**/Boolean());",
649 messageId
: "unexpectedCall",
650 type
: "CallExpression"
654 code
: "(!Boolean(/**/) ? 1 : 2)",
657 messageId
: "unexpectedCall",
658 type
: "CallExpression"
662 code
: "if(/**/Boolean());",
663 output
: "if(/**/false);",
665 messageId
: "unexpectedCall",
666 type
: "CallExpression"
670 code
: "if(Boolean/**/());",
673 messageId
: "unexpectedCall",
674 type
: "CallExpression"
678 code
: "if(Boolean(/**/));",
681 messageId
: "unexpectedCall",
682 type
: "CallExpression"
686 code
: "if(Boolean()/**/);",
687 output
: "if(false/**/);",
689 messageId
: "unexpectedCall",
690 type
: "CallExpression"
694 code
: "(Boolean/**/() ? 1 : 2)",
697 messageId
: "unexpectedCall",
698 type
: "CallExpression"
703 // In Logical context
705 code
: "if (!!foo || bar) {}",
706 output
: "if (foo || bar) {}",
707 options
: [{ enforceForLogicalOperands
: true }],
709 messageId
: "unexpectedNegation",
710 type
: "UnaryExpression",
716 code
: "if (!!foo && bar) {}",
717 output
: "if (foo && bar) {}",
718 options
: [{ enforceForLogicalOperands
: true }],
720 messageId
: "unexpectedNegation",
721 type
: "UnaryExpression",
728 code
: "if ((!!foo || bar) && bat) {}",
729 output
: "if ((foo || bar) && bat) {}",
730 options
: [{ enforceForLogicalOperands
: true }],
732 messageId
: "unexpectedNegation",
733 type
: "UnaryExpression",
739 code
: "if (foo && !!bar) {}",
740 output
: "if (foo && bar) {}",
741 options
: [{ enforceForLogicalOperands
: true }],
743 messageId
: "unexpectedNegation",
744 type
: "UnaryExpression",
750 code
: "do {} while (!!foo || bar)",
751 output
: "do {} while (foo || bar)",
752 options
: [{ enforceForLogicalOperands
: true }],
754 messageId
: "unexpectedNegation",
755 type
: "UnaryExpression",
760 code
: "while (!!foo || bar) {}",
761 output
: "while (foo || bar) {}",
762 options
: [{ enforceForLogicalOperands
: true }],
764 messageId
: "unexpectedNegation",
765 type
: "UnaryExpression",
770 code
: "!!foo && bat ? bar : baz",
771 output
: "foo && bat ? bar : baz",
772 options
: [{ enforceForLogicalOperands
: true }],
774 messageId
: "unexpectedNegation",
775 type
: "UnaryExpression",
780 code
: "for (; !!foo || bar;) {}",
781 output
: "for (; foo || bar;) {}",
782 options
: [{ enforceForLogicalOperands
: true }],
784 messageId
: "unexpectedNegation",
785 type
: "UnaryExpression",
790 code
: "!!!foo || bar",
791 output
: "!foo || bar",
792 options
: [{ enforceForLogicalOperands
: true }],
794 messageId
: "unexpectedNegation",
795 type
: "UnaryExpression",
800 code
: "Boolean(!!foo || bar)",
801 output
: "Boolean(foo || bar)",
802 options
: [{ enforceForLogicalOperands
: true }],
804 messageId
: "unexpectedNegation",
805 type
: "UnaryExpression",
810 code
: "new Boolean(!!foo || bar)",
811 output
: "new Boolean(foo || bar)",
812 options
: [{ enforceForLogicalOperands
: true }],
814 messageId
: "unexpectedNegation",
815 type
: "UnaryExpression",
820 code
: "if (Boolean(foo) || bar) {}",
821 output
: "if (foo || bar) {}",
822 options
: [{ enforceForLogicalOperands
: true }],
824 messageId
: "unexpectedCall",
825 type
: "CallExpression"
829 code
: "do {} while (Boolean(foo) || bar)",
830 output
: "do {} while (foo || bar)",
831 options
: [{ enforceForLogicalOperands
: true }],
833 messageId
: "unexpectedCall",
834 type
: "CallExpression"
838 code
: "while (Boolean(foo) || bar) {}",
839 output
: "while (foo || bar) {}",
840 options
: [{ enforceForLogicalOperands
: true }],
842 messageId
: "unexpectedCall",
843 type
: "CallExpression"
847 code
: "Boolean(foo) || bat ? bar : baz",
848 output
: "foo || bat ? bar : baz",
849 options
: [{ enforceForLogicalOperands
: true }],
851 messageId
: "unexpectedCall",
852 type
: "CallExpression"
856 code
: "for (; Boolean(foo) || bar;) {}",
857 output
: "for (; foo || bar;) {}",
858 options
: [{ enforceForLogicalOperands
: true }],
860 messageId
: "unexpectedCall",
861 type
: "CallExpression"
865 code
: "!Boolean(foo) || bar",
866 output
: "!foo || bar",
867 options
: [{ enforceForLogicalOperands
: true }],
869 messageId
: "unexpectedCall",
870 type
: "CallExpression"
874 code
: "!Boolean(foo && bar) || bat",
875 output
: "!(foo && bar) || bat",
876 options
: [{ enforceForLogicalOperands
: true }],
878 messageId
: "unexpectedCall",
879 type
: "CallExpression"
883 code
: "!Boolean(foo + bar) || bat",
884 output
: "!(foo + bar) || bat",
885 options
: [{ enforceForLogicalOperands
: true }],
887 messageId
: "unexpectedCall",
888 type
: "CallExpression"
892 code
: "!Boolean(+foo) || bar",
893 output
: "!+foo || bar",
894 options
: [{ enforceForLogicalOperands
: true }],
896 messageId
: "unexpectedCall",
897 type
: "CallExpression"
901 code
: "!Boolean(foo()) || bar",
902 output
: "!foo() || bar",
903 options
: [{ enforceForLogicalOperands
: true }],
905 messageId
: "unexpectedCall",
906 type
: "CallExpression"
910 code
: "!Boolean(foo() || bar)",
911 output
: "!(foo() || bar)",
912 options
: [{ enforceForLogicalOperands
: true }],
914 messageId
: "unexpectedCall",
915 type
: "CallExpression"
919 code
: "!Boolean(foo = bar) || bat",
920 output
: "!(foo = bar) || bat",
921 options
: [{ enforceForLogicalOperands
: true }],
923 messageId
: "unexpectedCall",
924 type
: "CallExpression"
928 code
: "!Boolean(...foo) || bar;",
930 options
: [{ enforceForLogicalOperands
: true }],
931 parserOptions
: { ecmaVersion
: 2015 },
933 messageId
: "unexpectedCall",
934 type
: "CallExpression"
938 code
: "!Boolean(foo, bar()) || bar;",
940 options
: [{ enforceForLogicalOperands
: true }],
942 messageId
: "unexpectedCall",
943 type
: "CallExpression"
947 code
: "!Boolean((foo, bar()) || bat);",
948 output
: "!((foo, bar()) || bat);",
949 options
: [{ enforceForLogicalOperands
: true }],
951 messageId
: "unexpectedCall",
952 type
: "CallExpression"
956 code
: "!Boolean() || bar;",
957 output
: "true || bar;",
958 options
: [{ enforceForLogicalOperands
: true }],
960 messageId
: "unexpectedCall",
961 type
: "CallExpression"
965 code
: "!(Boolean()) || bar;",
966 output
: "true || bar;",
967 options
: [{ enforceForLogicalOperands
: true }],
969 messageId
: "unexpectedCall",
970 type
: "CallExpression"
974 code
: "if (!Boolean() || bar) { foo() }",
975 output
: "if (true || bar) { foo() }",
976 options
: [{ enforceForLogicalOperands
: true }],
978 messageId
: "unexpectedCall",
979 type
: "CallExpression"
983 code
: "while (!Boolean() || bar) { foo() }",
984 output
: "while (true || bar) { foo() }",
985 options
: [{ enforceForLogicalOperands
: true }],
987 messageId
: "unexpectedCall",
988 type
: "CallExpression"
992 code
: "var foo = Boolean() || bar ? bar() : baz()",
993 output
: "var foo = false || bar ? bar() : baz()",
994 options
: [{ enforceForLogicalOperands
: true }],
996 messageId
: "unexpectedCall",
997 type
: "CallExpression"
1001 code
: "if (Boolean() || bar) { foo() }",
1002 output
: "if (false || bar) { foo() }",
1003 options
: [{ enforceForLogicalOperands
: true }],
1005 messageId
: "unexpectedCall",
1006 type
: "CallExpression"
1010 code
: "while (Boolean() || bar) { foo() }",
1011 output
: "while (false || bar) { foo() }",
1012 options
: [{ enforceForLogicalOperands
: true }],
1014 messageId
: "unexpectedCall",
1015 type
: "CallExpression"
1020 // Adjacent tokens tests
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 },
1027 messageId
: "unexpectedNegation",
1028 type
: "UnaryExpression"
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 },
1037 messageId
: "unexpectedNegation",
1038 type
: "UnaryExpression"
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 },
1047 messageId
: "unexpectedNegation",
1048 type
: "UnaryExpression"
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 },
1057 messageId
: "unexpectedNegation",
1058 type
: "UnaryExpression"
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 },
1067 messageId
: "unexpectedNegation",
1068 type
: "UnaryExpression"
1072 code
: "x=!!a || d ? b : c ",
1073 output
: "x=a || d ? b : c ",
1074 options
: [{ enforceForLogicalOperands
: true }],
1076 messageId
: "unexpectedNegation",
1077 type
: "UnaryExpression"
1081 code
: "void(!Boolean() || bar)",
1082 output
: "void(true || bar)",
1083 options
: [{ enforceForLogicalOperands
: true }],
1085 messageId
: "unexpectedCall",
1086 type
: "CallExpression"
1090 code
: "void(! Boolean() || bar)",
1091 output
: "void(true || bar)",
1092 options
: [{ enforceForLogicalOperands
: true }],
1094 messageId
: "unexpectedCall",
1095 type
: "CallExpression"
1099 code
: "typeof(!Boolean() || bar)",
1100 output
: "typeof(true || bar)",
1101 options
: [{ enforceForLogicalOperands
: true }],
1103 messageId
: "unexpectedCall",
1104 type
: "CallExpression"
1108 code
: "(!Boolean() || bar)",
1109 output
: "(true || bar)",
1110 options
: [{ enforceForLogicalOperands
: true }],
1112 messageId
: "unexpectedCall",
1113 type
: "CallExpression"
1117 code
: "void/**/(!Boolean() || bar)",
1118 output
: "void/**/(true || bar)",
1119 options
: [{ enforceForLogicalOperands
: true }],
1121 messageId
: "unexpectedCall",
1122 type
: "CallExpression"
1128 code
: "!/**/(!!foo || bar)",
1129 output
: "!/**/(foo || bar)",
1130 options
: [{ enforceForLogicalOperands
: true }],
1132 messageId
: "unexpectedNegation",
1133 type
: "UnaryExpression"
1137 code
: "!!/**/!foo || bar",
1139 options
: [{ enforceForLogicalOperands
: true }],
1141 messageId
: "unexpectedNegation",
1142 type
: "UnaryExpression"
1146 code
: "!!!/**/foo || bar",
1148 options
: [{ enforceForLogicalOperands
: true }],
1150 messageId
: "unexpectedNegation",
1151 type
: "UnaryExpression"
1155 code
: "!(!!foo || bar)/**/",
1156 output
: "!(foo || bar)/**/",
1157 options
: [{ enforceForLogicalOperands
: true }],
1159 messageId
: "unexpectedNegation",
1160 type
: "UnaryExpression"
1164 code
: "if(!/**/!foo || bar);",
1166 options
: [{ enforceForLogicalOperands
: true }],
1168 messageId
: "unexpectedNegation",
1169 type
: "UnaryExpression"
1173 code
: "(!!/**/foo || bar ? 1 : 2)",
1175 options
: [{ enforceForLogicalOperands
: true }],
1177 messageId
: "unexpectedNegation",
1178 type
: "UnaryExpression"
1182 code
: "!/**/(Boolean(foo) || bar)",
1183 output
: "!/**/(foo || bar)",
1184 options
: [{ enforceForLogicalOperands
: true }],
1186 messageId
: "unexpectedCall",
1187 type
: "CallExpression"
1191 code
: "!Boolean/**/(foo) || bar",
1193 options
: [{ enforceForLogicalOperands
: true }],
1195 messageId
: "unexpectedCall",
1196 type
: "CallExpression"
1200 code
: "!Boolean(/**/foo) || bar",
1202 options
: [{ enforceForLogicalOperands
: true }],
1204 messageId
: "unexpectedCall",
1205 type
: "CallExpression"
1209 code
: "!Boolean(foo/**/) || bar",
1211 options
: [{ enforceForLogicalOperands
: true }],
1213 messageId
: "unexpectedCall",
1214 type
: "CallExpression"
1218 code
: "!(Boolean(foo)|| bar)/**/",
1219 output
: "!(foo|| bar)/**/",
1220 options
: [{ enforceForLogicalOperands
: true }],
1222 messageId
: "unexpectedCall",
1223 type
: "CallExpression"
1227 code
: "if(Boolean/**/(foo) || bar);",
1229 options
: [{ enforceForLogicalOperands
: true }],
1231 messageId
: "unexpectedCall",
1232 type
: "CallExpression"
1236 code
: "(Boolean(foo/**/)|| bar ? 1 : 2)",
1238 options
: [{ enforceForLogicalOperands
: true }],
1240 messageId
: "unexpectedCall",
1241 type
: "CallExpression"
1245 code
: "/**/!Boolean()|| bar",
1246 output
: "/**/true|| bar",
1247 options
: [{ enforceForLogicalOperands
: true }],
1249 messageId
: "unexpectedCall",
1250 type
: "CallExpression"
1254 code
: "!/**/Boolean()|| bar",
1256 options
: [{ enforceForLogicalOperands
: true }],
1258 messageId
: "unexpectedCall",
1259 type
: "CallExpression"
1263 code
: "!Boolean/**/()|| bar",
1265 options
: [{ enforceForLogicalOperands
: true }],
1267 messageId
: "unexpectedCall",
1268 type
: "CallExpression"
1272 code
: "!Boolean(/**/)|| bar",
1274 options
: [{ enforceForLogicalOperands
: true }],
1276 messageId
: "unexpectedCall",
1277 type
: "CallExpression"
1281 code
: "(!Boolean()|| bar)/**/",
1282 output
: "(true|| bar)/**/",
1283 options
: [{ enforceForLogicalOperands
: true }],
1285 messageId
: "unexpectedCall",
1286 type
: "CallExpression"
1290 code
: "if(!/**/Boolean()|| bar);",
1292 options
: [{ enforceForLogicalOperands
: true }],
1294 messageId
: "unexpectedCall",
1295 type
: "CallExpression"
1299 code
: "(!Boolean(/**/) || bar ? 1 : 2)",
1301 options
: [{ enforceForLogicalOperands
: true }],
1303 messageId
: "unexpectedCall",
1304 type
: "CallExpression"
1308 code
: "if(/**/Boolean()|| bar);",
1309 output
: "if(/**/false|| bar);",
1310 options
: [{ enforceForLogicalOperands
: true }],
1312 messageId
: "unexpectedCall",
1313 type
: "CallExpression"
1317 code
: "if(Boolean/**/()|| bar);",
1319 options
: [{ enforceForLogicalOperands
: true }],
1321 messageId
: "unexpectedCall",
1322 type
: "CallExpression"
1326 code
: "if(Boolean(/**/)|| bar);",
1328 options
: [{ enforceForLogicalOperands
: true }],
1330 messageId
: "unexpectedCall",
1331 type
: "CallExpression"
1335 code
: "if(Boolean()|| bar/**/);",
1336 output
: "if(false|| bar/**/);",
1337 options
: [{ enforceForLogicalOperands
: true }],
1339 messageId
: "unexpectedCall",
1340 type
: "CallExpression"
1344 code
: "(Boolean/**/()|| bar ? 1 : 2)",
1346 options
: [{ enforceForLogicalOperands
: true }],
1348 messageId
: "unexpectedCall",
1349 type
: "CallExpression"
1353 code
: "if (a && !!(b ? c : d)){}",
1354 output
: "if (a && (b ? c : d)){}",
1356 options
: [{ enforceForLogicalOperands
: true }],
1358 messageId
: "unexpectedNegation",
1359 type
: "UnaryExpression",
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 },
1370 messageId
: "unexpectedNegation",
1371 type
: "UnaryExpression",
1377 // test parentheses in autofix
1379 code
: "Boolean(!!(a, b))",
1380 output
: "Boolean((a, b))",
1381 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1384 code
: "Boolean(Boolean((a, b)))",
1385 output
: "Boolean((a, b))",
1386 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1389 code
: "Boolean((!!(a, b)))",
1390 output
: "Boolean((a, b))",
1391 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1394 code
: "Boolean((Boolean((a, b))))",
1395 output
: "Boolean((a, b))",
1396 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1399 code
: "Boolean(!(!(a, b)))",
1400 output
: "Boolean((a, b))",
1401 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1404 code
: "Boolean((!(!(a, b))))",
1405 output
: "Boolean((a, b))",
1406 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1409 code
: "Boolean(!!(a = b))",
1410 output
: "Boolean(a = b)",
1411 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1414 code
: "Boolean((!!(a = b)))",
1415 output
: "Boolean((a = b))",
1416 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1419 code
: "Boolean(Boolean(a = b))",
1420 output
: "Boolean(a = b)",
1421 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1424 code
: "Boolean(Boolean((a += b)))",
1425 output
: "Boolean(a += b)",
1426 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1429 code
: "Boolean(!!(a === b))",
1430 output
: "Boolean(a === b)",
1431 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1434 code
: "Boolean(!!((a !== b)))",
1435 output
: "Boolean(a !== b)",
1436 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1439 code
: "Boolean(!!a.b)",
1440 output
: "Boolean(a.b)",
1441 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1444 code
: "Boolean(Boolean((a)))",
1445 output
: "Boolean(a)",
1446 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1449 code
: "Boolean((!!(a)))",
1450 output
: "Boolean((a))",
1451 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1455 code
: "new Boolean(!!(a, b))",
1456 output
: "new Boolean((a, b))",
1457 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1460 code
: "new Boolean(Boolean((a, b)))",
1461 output
: "new Boolean((a, b))",
1462 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1465 code
: "new Boolean((!!(a, b)))",
1466 output
: "new Boolean((a, b))",
1467 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1470 code
: "new Boolean((Boolean((a, b))))",
1471 output
: "new Boolean((a, b))",
1472 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1475 code
: "new Boolean(!(!(a, b)))",
1476 output
: "new Boolean((a, b))",
1477 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1480 code
: "new Boolean((!(!(a, b))))",
1481 output
: "new Boolean((a, b))",
1482 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1485 code
: "new Boolean(!!(a = b))",
1486 output
: "new Boolean(a = b)",
1487 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1490 code
: "new Boolean((!!(a = b)))",
1491 output
: "new Boolean((a = b))",
1492 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1495 code
: "new Boolean(Boolean(a = b))",
1496 output
: "new Boolean(a = b)",
1497 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1500 code
: "new Boolean(Boolean((a += b)))",
1501 output
: "new Boolean(a += b)",
1502 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1505 code
: "new Boolean(!!(a === b))",
1506 output
: "new Boolean(a === b)",
1507 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1510 code
: "new Boolean(!!((a !== b)))",
1511 output
: "new Boolean(a !== b)",
1512 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1515 code
: "new Boolean(!!a.b)",
1516 output
: "new Boolean(a.b)",
1517 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1520 code
: "new Boolean(Boolean((a)))",
1521 output
: "new Boolean(a)",
1522 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1525 code
: "new Boolean((!!(a)))",
1526 output
: "new Boolean((a))",
1527 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1530 code
: "if (!!(a, b));",
1531 output
: "if (a, b);",
1532 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1535 code
: "if (Boolean((a, b)));",
1536 output
: "if (a, b);",
1537 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1540 code
: "if (!(!(a, b)));",
1541 output
: "if (a, b);",
1542 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1545 code
: "if (!!(a = b));",
1546 output
: "if (a = b);",
1547 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1550 code
: "if (Boolean(a = b));",
1551 output
: "if (a = b);",
1552 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1555 code
: "if (!!(a > b));",
1556 output
: "if (a > b);",
1557 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1560 code
: "if (Boolean(a === b));",
1561 output
: "if (a === b);",
1562 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1565 code
: "if (!!f(a));",
1566 output
: "if (f(a));",
1567 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1570 code
: "if (Boolean(f(a)));",
1571 output
: "if (f(a));",
1572 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1575 code
: "if (!!(f(a)));",
1576 output
: "if (f(a));",
1577 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1580 code
: "if ((!!f(a)));",
1581 output
: "if ((f(a)));",
1582 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1585 code
: "if ((Boolean(f(a))));",
1586 output
: "if ((f(a)));",
1587 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1592 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1595 code
: "if (Boolean(a));",
1597 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1600 code
: "while (!!(a, b));",
1601 output
: "while (a, b);",
1602 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1605 code
: "while (Boolean((a, b)));",
1606 output
: "while (a, b);",
1607 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1610 code
: "while (!(!(a, b)));",
1611 output
: "while (a, b);",
1612 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1615 code
: "while (!!(a = b));",
1616 output
: "while (a = b);",
1617 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1620 code
: "while (Boolean(a = b));",
1621 output
: "while (a = b);",
1622 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1625 code
: "while (!!(a > b));",
1626 output
: "while (a > b);",
1627 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1630 code
: "while (Boolean(a === b));",
1631 output
: "while (a === b);",
1632 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1635 code
: "while (!!f(a));",
1636 output
: "while (f(a));",
1637 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1640 code
: "while (Boolean(f(a)));",
1641 output
: "while (f(a));",
1642 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1645 code
: "while (!!(f(a)));",
1646 output
: "while (f(a));",
1647 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1650 code
: "while ((!!f(a)));",
1651 output
: "while ((f(a)));",
1652 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1655 code
: "while ((Boolean(f(a))));",
1656 output
: "while ((f(a)));",
1657 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1660 code
: "while (!!a);",
1661 output
: "while (a);",
1662 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1665 code
: "while (Boolean(a));",
1666 output
: "while (a);",
1667 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1670 code
: "do {} while (!!(a, b));",
1671 output
: "do {} while (a, b);",
1672 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1675 code
: "do {} while (Boolean((a, b)));",
1676 output
: "do {} while (a, b);",
1677 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1680 code
: "do {} while (!(!(a, b)));",
1681 output
: "do {} while (a, b);",
1682 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1685 code
: "do {} while (!!(a = b));",
1686 output
: "do {} while (a = b);",
1687 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1690 code
: "do {} while (Boolean(a = b));",
1691 output
: "do {} while (a = b);",
1692 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1695 code
: "do {} while (!!(a > b));",
1696 output
: "do {} while (a > b);",
1697 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1700 code
: "do {} while (Boolean(a === b));",
1701 output
: "do {} while (a === b);",
1702 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1705 code
: "do {} while (!!f(a));",
1706 output
: "do {} while (f(a));",
1707 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1710 code
: "do {} while (Boolean(f(a)));",
1711 output
: "do {} while (f(a));",
1712 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1715 code
: "do {} while (!!(f(a)));",
1716 output
: "do {} while (f(a));",
1717 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1720 code
: "do {} while ((!!f(a)));",
1721 output
: "do {} while ((f(a)));",
1722 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1725 code
: "do {} while ((Boolean(f(a))));",
1726 output
: "do {} while ((f(a)));",
1727 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1730 code
: "do {} while (!!a);",
1731 output
: "do {} while (a);",
1732 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1735 code
: "do {} while (Boolean(a));",
1736 output
: "do {} while (a);",
1737 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1740 code
: "for (; !!(a, b););",
1741 output
: "for (; a, b;);",
1742 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1745 code
: "for (; Boolean((a, b)););",
1746 output
: "for (; a, b;);",
1747 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1750 code
: "for (; !(!(a, b)););",
1751 output
: "for (; a, b;);",
1752 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1755 code
: "for (; !!(a = b););",
1756 output
: "for (; a = b;);",
1757 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1760 code
: "for (; Boolean(a = b););",
1761 output
: "for (; a = b;);",
1762 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1765 code
: "for (; !!(a > b););",
1766 output
: "for (; a > b;);",
1767 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1770 code
: "for (; Boolean(a === b););",
1771 output
: "for (; a === b;);",
1772 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1775 code
: "for (; !!f(a););",
1776 output
: "for (; f(a););",
1777 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1780 code
: "for (; Boolean(f(a)););",
1781 output
: "for (; f(a););",
1782 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1785 code
: "for (; !!(f(a)););",
1786 output
: "for (; f(a););",
1787 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1790 code
: "for (; (!!f(a)););",
1791 output
: "for (; (f(a)););",
1792 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1795 code
: "for (; (Boolean(f(a))););",
1796 output
: "for (; (f(a)););",
1797 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1800 code
: "for (; !!a;);",
1801 output
: "for (; a;);",
1802 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1805 code
: "for (; Boolean(a););",
1806 output
: "for (; a;);",
1807 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1810 code
: "!!(a, b) ? c : d",
1811 output
: "(a, b) ? c : d",
1812 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1815 code
: "(!!(a, b)) ? c : d",
1816 output
: "(a, b) ? c : d",
1817 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1820 code
: "Boolean((a, b)) ? c : d",
1821 output
: "(a, b) ? c : d",
1822 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1825 code
: "!!(a = b) ? c : d",
1826 output
: "(a = b) ? c : d",
1827 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1830 code
: "Boolean(a -= b) ? c : d",
1831 output
: "(a -= b) ? c : d",
1832 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1835 code
: "(Boolean((a *= b))) ? c : d",
1836 output
: "(a *= b) ? c : d",
1837 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1840 code
: "!!(a ? b : c) ? d : e",
1841 output
: "(a ? b : c) ? d : e",
1842 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1845 code
: "Boolean(a ? b : c) ? d : e",
1846 output
: "(a ? b : c) ? d : e",
1847 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1850 code
: "!!(a || b) ? c : d",
1851 output
: "a || b ? c : d",
1852 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1855 code
: "Boolean(a && b) ? c : d",
1856 output
: "a && b ? c : d",
1857 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1860 code
: "!!(a === b) ? c : d",
1861 output
: "a === b ? c : d",
1862 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1865 code
: "Boolean(a < b) ? c : d",
1866 output
: "a < b ? c : d",
1867 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1870 code
: "!!((a !== b)) ? c : d",
1871 output
: "a !== b ? c : d",
1872 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1875 code
: "Boolean((a >= b)) ? c : d",
1876 output
: "a >= b ? c : d",
1877 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1880 code
: "!!+a ? b : c",
1881 output
: "+a ? b : c",
1882 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1885 code
: "!!+(a) ? b : c",
1886 output
: "+(a) ? b : c",
1887 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1890 code
: "Boolean(!a) ? b : c",
1891 output
: "!a ? b : c",
1892 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1895 code
: "!!f(a) ? b : c",
1896 output
: "f(a) ? b : c",
1897 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1900 code
: "(!!f(a)) ? b : c",
1901 output
: "(f(a)) ? b : c",
1902 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1905 code
: "Boolean(a.b) ? c : d",
1906 output
: "a.b ? c : d",
1907 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1910 code
: "!!a ? b : c",
1911 output
: "a ? b : c",
1912 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1915 code
: "Boolean(a) ? b : c",
1916 output
: "a ? b : c",
1917 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1922 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1925 code
: "!Boolean((a, b))",
1927 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1932 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1935 code
: "!!(!(a += b))",
1936 output
: "!(a += b)",
1937 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1940 code
: "!(!!(a += b))",
1941 output
: "!(a += b)",
1942 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1945 code
: "!Boolean(a -= b)",
1946 output
: "!(a -= b)",
1947 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1950 code
: "!Boolean((a -= b))",
1951 output
: "!(a -= b)",
1952 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1955 code
: "!(Boolean(a -= b))",
1956 output
: "!(a -= b)",
1957 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1960 code
: "!!!(a || b)",
1961 output
: "!(a || b)",
1962 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1965 code
: "!Boolean(a || b)",
1966 output
: "!(a || b)",
1967 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1970 code
: "!!!(a && b)",
1971 output
: "!(a && b)",
1972 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1975 code
: "!Boolean(a && b)",
1976 output
: "!(a && b)",
1977 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1980 code
: "!!!(a != b)",
1981 output
: "!(a != b)",
1982 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1985 code
: "!!!(a === b)",
1986 output
: "!(a === b)",
1987 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
1990 code
: "var x = !Boolean(a > b)",
1991 output
: "var x = !(a > b)",
1992 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
1997 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
2000 code
: "!!!(a ** b)",
2001 output
: "!(a ** b)",
2002 parserOptions
: { ecmaVersion
: 2016 },
2003 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
2006 code
: "!Boolean(a ** b)",
2007 output
: "!(a ** b)",
2008 parserOptions
: { ecmaVersion
: 2016 },
2009 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
2012 code
: "async function f() { !!!(await a) }",
2013 output
: "async function f() { !await a }",
2014 parserOptions
: { ecmaVersion
: 2017 },
2015 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
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" }]
2025 output
: "!!a", // Reports 2 errors. After the first fix, the second error will disappear.
2027 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2028 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2033 output
: "!!a", // Reports 2 errors. After the first fix, the second error will disappear.
2035 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2036 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2040 code
: "!Boolean(!a)",
2042 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
2045 code
: "!Boolean((!a))",
2047 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
2050 code
: "!Boolean(!(a))",
2052 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
2055 code
: "!(Boolean(!a))",
2057 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
2062 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
2067 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
2072 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
2077 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
2080 code
: "!Boolean((-a))",
2082 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
2085 code
: "!Boolean(-(a))",
2087 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
2092 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
2095 code
: "!Boolean(a++)",
2097 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
2102 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
2107 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
2112 errors
: [{ messageId
: "unexpectedNegation", type
: "UnaryExpression" }]
2115 code
: "!Boolean(a)",
2117 errors
: [{ messageId
: "unexpectedCall", type
: "CallExpression" }]
2120 code
: "if (!!(a, b) || !!(c, d)) {}",
2121 output
: "if ((a, b) || (c, d)) {}",
2122 options
: [{ enforceForLogicalOperands
: true }],
2124 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2125 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2129 code
: "if (Boolean((a, b)) || Boolean((c, d))) {}",
2130 output
: "if ((a, b) || (c, d)) {}",
2131 options
: [{ enforceForLogicalOperands
: true }],
2133 { messageId
: "unexpectedCall", type
: "CallExpression" },
2134 { messageId
: "unexpectedCall", type
: "CallExpression" }
2138 code
: "if ((!!((a, b))) || (!!((c, d)))) {}",
2139 output
: "if ((a, b) || (c, d)) {}",
2140 options
: [{ enforceForLogicalOperands
: true }],
2142 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2143 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2147 code
: "if (!!(a, b) && !!(c, d)) {}",
2148 output
: "if ((a, b) && (c, d)) {}",
2149 options
: [{ enforceForLogicalOperands
: true }],
2151 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2152 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2156 code
: "if (Boolean((a, b)) && Boolean((c, d))) {}",
2157 output
: "if ((a, b) && (c, d)) {}",
2158 options
: [{ enforceForLogicalOperands
: true }],
2160 { messageId
: "unexpectedCall", type
: "CallExpression" },
2161 { messageId
: "unexpectedCall", type
: "CallExpression" }
2165 code
: "if ((!!((a, b))) && (!!((c, d)))) {}",
2166 output
: "if ((a, b) && (c, d)) {}",
2167 options
: [{ enforceForLogicalOperands
: true }],
2169 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2170 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2174 code
: "if (!!(a = b) || !!(c = d)) {}",
2175 output
: "if ((a = b) || (c = d)) {}",
2176 options
: [{ enforceForLogicalOperands
: true }],
2178 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2179 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2183 code
: "if (Boolean(a /= b) || Boolean(c /= d)) {}",
2184 output
: "if ((a /= b) || (c /= d)) {}",
2185 options
: [{ enforceForLogicalOperands
: true }],
2187 { messageId
: "unexpectedCall", type
: "CallExpression" },
2188 { messageId
: "unexpectedCall", type
: "CallExpression" }
2192 code
: "if (!!(a >>= b) && !!(c >>= d)) {}",
2193 output
: "if ((a >>= b) && (c >>= d)) {}",
2194 options
: [{ enforceForLogicalOperands
: true }],
2196 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2197 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2201 code
: "if (Boolean(a **= b) && Boolean(c **= d)) {}",
2202 output
: "if ((a **= b) && (c **= d)) {}",
2203 options
: [{ enforceForLogicalOperands
: true }],
2204 parserOptions
: { ecmaVersion
: 2016 },
2206 { messageId
: "unexpectedCall", type
: "CallExpression" },
2207 { messageId
: "unexpectedCall", type
: "CallExpression" }
2211 code
: "if (!!(a ? b : c) || !!(d ? e : f)) {}",
2212 output
: "if ((a ? b : c) || (d ? e : f)) {}",
2213 options
: [{ enforceForLogicalOperands
: true }],
2215 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2216 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2220 code
: "if (Boolean(a ? b : c) || Boolean(d ? e : f)) {}",
2221 output
: "if ((a ? b : c) || (d ? e : f)) {}",
2222 options
: [{ enforceForLogicalOperands
: true }],
2224 { messageId
: "unexpectedCall", type
: "CallExpression" },
2225 { messageId
: "unexpectedCall", type
: "CallExpression" }
2229 code
: "if (!!(a ? b : c) && !!(d ? e : f)) {}",
2230 output
: "if ((a ? b : c) && (d ? e : f)) {}",
2231 options
: [{ enforceForLogicalOperands
: true }],
2233 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2234 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2238 code
: "if (Boolean(a ? b : c) && Boolean(d ? e : f)) {}",
2239 output
: "if ((a ? b : c) && (d ? e : f)) {}",
2240 options
: [{ enforceForLogicalOperands
: true }],
2242 { messageId
: "unexpectedCall", type
: "CallExpression" },
2243 { messageId
: "unexpectedCall", type
: "CallExpression" }
2247 code
: "if (!!(a || b) || !!(c || d)) {}",
2248 output
: "if (a || b || (c || d)) {}",
2249 options
: [{ enforceForLogicalOperands
: true }],
2251 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2252 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2256 code
: "if (Boolean(a || b) || Boolean(c || d)) {}",
2257 output
: "if (a || b || (c || d)) {}",
2258 options
: [{ enforceForLogicalOperands
: true }],
2260 { messageId
: "unexpectedCall", type
: "CallExpression" },
2261 { messageId
: "unexpectedCall", type
: "CallExpression" }
2265 code
: "if (!!(a || b) && !!(c || d)) {}",
2266 output
: "if ((a || b) && (c || d)) {}",
2267 options
: [{ enforceForLogicalOperands
: true }],
2269 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2270 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2274 code
: "if (Boolean(a || b) && Boolean(c || d)) {}",
2275 output
: "if ((a || b) && (c || d)) {}",
2276 options
: [{ enforceForLogicalOperands
: true }],
2278 { messageId
: "unexpectedCall", type
: "CallExpression" },
2279 { messageId
: "unexpectedCall", type
: "CallExpression" }
2283 code
: "if (!!(a && b) || !!(c && d)) {}",
2284 output
: "if (a && b || c && d) {}",
2285 options
: [{ enforceForLogicalOperands
: true }],
2287 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2288 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2292 code
: "if (Boolean(a && b) || Boolean(c && d)) {}",
2293 output
: "if (a && b || c && d) {}",
2294 options
: [{ enforceForLogicalOperands
: true }],
2296 { messageId
: "unexpectedCall", type
: "CallExpression" },
2297 { messageId
: "unexpectedCall", type
: "CallExpression" }
2301 code
: "if (!!(a && b) && !!(c && d)) {}",
2302 output
: "if (a && b && (c && d)) {}",
2303 options
: [{ enforceForLogicalOperands
: true }],
2305 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2306 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2310 code
: "if (Boolean(a && b) && Boolean(c && d)) {}",
2311 output
: "if (a && b && (c && d)) {}",
2312 options
: [{ enforceForLogicalOperands
: true }],
2314 { messageId
: "unexpectedCall", type
: "CallExpression" },
2315 { messageId
: "unexpectedCall", type
: "CallExpression" }
2319 code
: "if (!!(a !== b) || !!(c !== d)) {}",
2320 output
: "if (a !== b || c !== d) {}",
2321 options
: [{ enforceForLogicalOperands
: true }],
2323 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2324 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2328 code
: "if (Boolean(a != b) || Boolean(c != d)) {}",
2329 output
: "if (a != b || c != d) {}",
2330 options
: [{ enforceForLogicalOperands
: true }],
2332 { messageId
: "unexpectedCall", type
: "CallExpression" },
2333 { messageId
: "unexpectedCall", type
: "CallExpression" }
2337 code
: "if (!!(a === b) && !!(c === d)) {}",
2338 output
: "if (a === b && c === d) {}",
2339 options
: [{ enforceForLogicalOperands
: true }],
2341 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2342 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2346 code
: "if (!!(a > b) || !!(c < d)) {}",
2347 output
: "if (a > b || c < d) {}",
2348 options
: [{ enforceForLogicalOperands
: true }],
2350 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2351 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2355 code
: "if (Boolean(!a) || Boolean(+b)) {}",
2356 output
: "if (!a || +b) {}",
2357 options
: [{ enforceForLogicalOperands
: true }],
2359 { messageId
: "unexpectedCall", type
: "CallExpression" },
2360 { messageId
: "unexpectedCall", type
: "CallExpression" }
2364 code
: "if (!!f(a) && !!b.c) {}",
2365 output
: "if (f(a) && b.c) {}",
2366 options
: [{ enforceForLogicalOperands
: true }],
2368 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2369 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2373 code
: "if (Boolean(a) || !!b) {}",
2374 output
: "if (a || b) {}",
2375 options
: [{ enforceForLogicalOperands
: true }],
2377 { messageId
: "unexpectedCall", type
: "CallExpression" },
2378 { messageId
: "unexpectedNegation", type
: "UnaryExpression" }
2382 code
: "if (!!a && Boolean(b)) {}",
2383 output
: "if (a && b) {}",
2384 options
: [{ enforceForLogicalOperands
: true }],
2386 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2387 { messageId
: "unexpectedCall", type
: "CallExpression" }
2391 code
: "if ((!!a) || (Boolean(b))) {}",
2392 output
: "if ((a) || (b)) {}",
2393 options
: [{ enforceForLogicalOperands
: true }],
2395 { messageId
: "unexpectedNegation", type
: "UnaryExpression" },
2396 { messageId
: "unexpectedCall", type
: "CallExpression" }