@@ -49,6 +49,9 @@ ruleTester.run("use-isnan", rule, {
4949 "foo(2 / Number.NaN)" ,
5050 "var x; if (x = Number.NaN) { }" ,
5151 "x === Number[NaN];" ,
52+ "x === (NaN, 1)" ,
53+ "x === (doStuff(), NaN, 1)" ,
54+ "x === (doStuff(), Number.NaN, 1)" ,
5255
5356 //------------------------------------------------------------------------------
5457 // enforceForSwitchCase
@@ -174,6 +177,14 @@ ruleTester.run("use-isnan", rule, {
174177 code : "switch(foo) { case foo.Number.NaN: break }" ,
175178 options : [ { enforceForSwitchCase : true } ]
176179 } ,
180+ {
181+ code : "switch((NaN, doStuff(), 1)) {}" ,
182+ options : [ { enforceForSwitchCase : true } ]
183+ } ,
184+ {
185+ code : "switch((Number.NaN, doStuff(), 1)) {}" ,
186+ options : [ { enforceForSwitchCase : true } ]
187+ } ,
177188
178189 //------------------------------------------------------------------------------
179190 // enforceForIndexOf
@@ -344,6 +355,22 @@ ruleTester.run("use-isnan", rule, {
344355 {
345356 code : "foo.lastIndexOf(Number.NaN())" ,
346357 options : [ { enforceForIndexOf : true } ]
358+ } ,
359+ {
360+ code : "foo.indexOf((NaN, 1))" ,
361+ options : [ { enforceForIndexOf : true } ]
362+ } ,
363+ {
364+ code : "foo.lastIndexOf((NaN, 1))" ,
365+ options : [ { enforceForIndexOf : true } ]
366+ } ,
367+ {
368+ code : "foo.indexOf((Number.NaN, 1))" ,
369+ options : [ { enforceForIndexOf : true } ]
370+ } ,
371+ {
372+ code : "foo.lastIndexOf((Number.NaN, 1))" ,
373+ options : [ { enforceForIndexOf : true } ]
347374 }
348375 ] ,
349376 invalid : [
@@ -747,6 +774,34 @@ ruleTester.run("use-isnan", rule, {
747774 ]
748775 } ]
749776 } ,
777+ {
778+ code : "x === (doStuff(), NaN);" ,
779+ errors : [ {
780+ ...comparisonError ,
781+ suggestions : [ ]
782+ } ]
783+ } ,
784+ {
785+ code : "x === (doStuff(), Number.NaN);" ,
786+ errors : [ {
787+ ...comparisonError ,
788+ suggestions : [ ]
789+ } ]
790+ } ,
791+ {
792+ code : "x == (doStuff(), NaN);" ,
793+ errors : [ {
794+ ...comparisonError ,
795+ suggestions : [ ]
796+ } ]
797+ } ,
798+ {
799+ code : "x == (doStuff(), Number.NaN);" ,
800+ errors : [ {
801+ ...comparisonError ,
802+ suggestions : [ ]
803+ } ]
804+ } ,
750805
751806 //------------------------------------------------------------------------------
752807 // enforceForSwitchCase
@@ -910,6 +965,20 @@ ruleTester.run("use-isnan", rule, {
910965 { messageId : "caseNaN" , type : "SwitchCase" , column : 22 }
911966 ]
912967 } ,
968+ {
969+ code : "switch((doStuff(), NaN)) {}" ,
970+ options : [ { enforceForSwitchCase : true } ] ,
971+ errors : [
972+ { messageId : "switchNaN" , type : "SwitchStatement" , column : 1 }
973+ ]
974+ } ,
975+ {
976+ code : "switch((doStuff(), Number.NaN)) {}" ,
977+ options : [ { enforceForSwitchCase : true } ] ,
978+ errors : [
979+ { messageId : "switchNaN" , type : "SwitchStatement" , column : 1 }
980+ ]
981+ } ,
913982
914983 //------------------------------------------------------------------------------
915984 // enforceForIndexOf
@@ -1010,6 +1079,30 @@ ruleTester.run("use-isnan", rule, {
10101079 options : [ { enforceForIndexOf : true } ] ,
10111080 languageOptions : { ecmaVersion : 2020 } ,
10121081 errors : [ { messageId : "indexOfNaN" , data : { methodName : "indexOf" } } ]
1082+ } ,
1083+ {
1084+ code : "foo.indexOf((1, NaN))" ,
1085+ options : [ { enforceForIndexOf : true } ] ,
1086+ languageOptions : { ecmaVersion : 2020 } ,
1087+ errors : [ { messageId : "indexOfNaN" , data : { methodName : "indexOf" } } ]
1088+ } ,
1089+ {
1090+ code : "foo.indexOf((1, Number.NaN))" ,
1091+ options : [ { enforceForIndexOf : true } ] ,
1092+ languageOptions : { ecmaVersion : 2020 } ,
1093+ errors : [ { messageId : "indexOfNaN" , data : { methodName : "indexOf" } } ]
1094+ } ,
1095+ {
1096+ code : "foo.lastIndexOf((1, NaN))" ,
1097+ options : [ { enforceForIndexOf : true } ] ,
1098+ languageOptions : { ecmaVersion : 2020 } ,
1099+ errors : [ { messageId : "indexOfNaN" , data : { methodName : "lastIndexOf" } } ]
1100+ } ,
1101+ {
1102+ code : "foo.lastIndexOf((1, Number.NaN))" ,
1103+ options : [ { enforceForIndexOf : true } ] ,
1104+ languageOptions : { ecmaVersion : 2020 } ,
1105+ errors : [ { messageId : "indexOfNaN" , data : { methodName : "lastIndexOf" } } ]
10131106 }
10141107 ]
10151108} ) ;
0 commit comments