@@ -185,7 +185,17 @@ ruleTester.run("no-constant-condition", rule, {
185185 "if (`${[a]}`) {}" ,
186186 "if (+[a]) {}" ,
187187 "if (0 - [a]) {}" ,
188- "if (1 * [a]) {}"
188+ "if (1 * [a]) {}" ,
189+
190+ // Boolean function
191+ "if (Boolean(a)) {}" ,
192+ "if (Boolean(...args)) {}" ,
193+ "if (foo.Boolean(1)) {}" ,
194+ "function foo(Boolean) { if (Boolean(1)) {} }" ,
195+ "const Boolean = () => {}; if (Boolean(1)) {}" ,
196+ { code : "if (Boolean()) {}" , globals : { Boolean : "off" } } ,
197+ "const undefined = 'lol'; if (undefined) {}" ,
198+ { code : "if (undefined) {}" , globals : { undefined : "off" } }
189199 ] ,
190200 invalid : [
191201 { code : "for(;true;);" , errors : [ { messageId : "unexpected" , type : "Literal" } ] } ,
@@ -396,6 +406,18 @@ ruleTester.run("no-constant-condition", rule, {
396406 { code : "if(new Number(foo)) {}" , errors : [ { messageId : "unexpected" } ] } ,
397407
398408 // Spreading a constant array
399- { code : "if(`${[...['a']]}`) {}" , errors : [ { messageId : "unexpected" } ] }
409+ { code : "if(`${[...['a']]}`) {}" , errors : [ { messageId : "unexpected" } ] } ,
410+
411+ /*
412+ * undefined is always falsy (except in old browsers that let you
413+ * re-assign, but that's an abscure enough edge case to not worry about)
414+ */
415+ { code : "if (undefined) {}" , errors : [ { messageId : "unexpected" } ] } ,
416+
417+ // Coercion to boolean via Boolean function
418+ { code : "if (Boolean(1)) {}" , errors : [ { messageId : "unexpected" } ] } ,
419+ { code : "if (Boolean()) {}" , errors : [ { messageId : "unexpected" } ] } ,
420+ { code : "if (Boolean([a])) {}" , errors : [ { messageId : "unexpected" } ] } ,
421+ { code : "if (Boolean(1)) { function Boolean() {}}" , errors : [ { messageId : "unexpected" } ] }
400422 ]
401423} ) ;
0 commit comments