]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/use-isnan.js
import 8.3.0 source
[pve-eslint.git] / eslint / tests / lib / rules / use-isnan.js
1 /**
2 * @fileoverview Tests for use-isnan rule.
3 * @author James Allardice, Michael Paulukonis
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/use-isnan"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 const comparisonError = { messageId: "comparisonWithNaN", type: "BinaryExpression" };
22
23 ruleTester.run("use-isnan", rule, {
24 valid: [
25 "var x = NaN;",
26 "isNaN(NaN) === true;",
27 "isNaN(123) !== true;",
28 "Number.isNaN(NaN) === true;",
29 "Number.isNaN(123) !== true;",
30 "foo(NaN + 1);",
31 "foo(1 + NaN);",
32 "foo(NaN - 1)",
33 "foo(1 - NaN)",
34 "foo(NaN * 2)",
35 "foo(2 * NaN)",
36 "foo(NaN / 2)",
37 "foo(2 / NaN)",
38 "var x; if (x = NaN) { }",
39 "var x = Number.NaN;",
40 "isNaN(Number.NaN) === true;",
41 "Number.isNaN(Number.NaN) === true;",
42 "foo(Number.NaN + 1);",
43 "foo(1 + Number.NaN);",
44 "foo(Number.NaN - 1)",
45 "foo(1 - Number.NaN)",
46 "foo(Number.NaN * 2)",
47 "foo(2 * Number.NaN)",
48 "foo(Number.NaN / 2)",
49 "foo(2 / Number.NaN)",
50 "var x; if (x = Number.NaN) { }",
51 "x === Number[NaN];",
52
53 //------------------------------------------------------------------------------
54 // enforceForSwitchCase
55 //------------------------------------------------------------------------------
56
57 {
58 code: "switch(NaN) { case foo: break; }",
59 options: [{ enforceForSwitchCase: false }]
60 },
61 {
62 code: "switch(foo) { case NaN: break; }",
63 options: [{ enforceForSwitchCase: false }]
64 },
65 {
66 code: "switch(NaN) { case NaN: break; }",
67 options: [{ enforceForSwitchCase: false }]
68 },
69 {
70 code: "switch(foo) { case bar: break; case NaN: break; default: break; }",
71 options: [{ enforceForSwitchCase: false }]
72 },
73 {
74 code: "switch(foo) {}",
75 options: [{ enforceForSwitchCase: true }]
76 },
77 {
78 code: "switch(foo) { case bar: NaN; }",
79 options: [{ enforceForSwitchCase: true }]
80 },
81 {
82 code: "switch(foo) { default: NaN; }",
83 options: [{ enforceForSwitchCase: true }]
84 },
85 {
86 code: "switch(Nan) {}",
87 options: [{ enforceForSwitchCase: true }]
88 },
89 {
90 code: "switch('NaN') { default: break; }",
91 options: [{ enforceForSwitchCase: true }]
92 },
93 {
94 code: "switch(foo(NaN)) {}",
95 options: [{ enforceForSwitchCase: true }]
96 },
97 {
98 code: "switch(foo.NaN) {}",
99 options: [{ enforceForSwitchCase: true }]
100 },
101 {
102 code: "switch(foo) { case Nan: break }",
103 options: [{ enforceForSwitchCase: true }]
104 },
105 {
106 code: "switch(foo) { case 'NaN': break }",
107 options: [{ enforceForSwitchCase: true }]
108 },
109 {
110 code: "switch(foo) { case foo(NaN): break }",
111 options: [{ enforceForSwitchCase: true }]
112 },
113 {
114 code: "switch(foo) { case foo.NaN: break }",
115 options: [{ enforceForSwitchCase: true }]
116 },
117 {
118 code: "switch(foo) { case bar: break; case 1: break; default: break; }",
119 options: [{ enforceForSwitchCase: true }]
120 },
121 {
122 code: "switch(Number.NaN) { case foo: break; }",
123 options: [{ enforceForSwitchCase: false }]
124 },
125 {
126 code: "switch(foo) { case Number.NaN: break; }",
127 options: [{ enforceForSwitchCase: false }]
128 },
129 {
130 code: "switch(NaN) { case Number.NaN: break; }",
131 options: [{ enforceForSwitchCase: false }]
132 },
133 {
134 code: "switch(foo) { case bar: break; case Number.NaN: break; default: break; }",
135 options: [{ enforceForSwitchCase: false }]
136 },
137 {
138 code: "switch(foo) { case bar: Number.NaN; }",
139 options: [{ enforceForSwitchCase: true }]
140 },
141 {
142 code: "switch(foo) { default: Number.NaN; }",
143 options: [{ enforceForSwitchCase: true }]
144 },
145 {
146 code: "switch(Number.Nan) {}",
147 options: [{ enforceForSwitchCase: true }]
148 },
149 {
150 code: "switch('Number.NaN') { default: break; }",
151 options: [{ enforceForSwitchCase: true }]
152 },
153 {
154 code: "switch(foo(Number.NaN)) {}",
155 options: [{ enforceForSwitchCase: true }]
156 },
157 {
158 code: "switch(foo.Number.NaN) {}",
159 options: [{ enforceForSwitchCase: true }]
160 },
161 {
162 code: "switch(foo) { case Number.Nan: break }",
163 options: [{ enforceForSwitchCase: true }]
164 },
165 {
166 code: "switch(foo) { case 'Number.NaN': break }",
167 options: [{ enforceForSwitchCase: true }]
168 },
169 {
170 code: "switch(foo) { case foo(Number.NaN): break }",
171 options: [{ enforceForSwitchCase: true }]
172 },
173 {
174 code: "switch(foo) { case foo.Number.NaN: break }",
175 options: [{ enforceForSwitchCase: true }]
176 },
177
178 //------------------------------------------------------------------------------
179 // enforceForIndexOf
180 //------------------------------------------------------------------------------
181
182 "foo.indexOf(NaN)",
183 "foo.lastIndexOf(NaN)",
184 "foo.indexOf(Number.NaN)",
185 "foo.lastIndexOf(Number.NaN)",
186 {
187 code: "foo.indexOf(NaN)",
188 options: [{}]
189 },
190 {
191 code: "foo.lastIndexOf(NaN)",
192 options: [{}]
193 },
194 {
195 code: "foo.indexOf(NaN)",
196 options: [{ enforceForIndexOf: false }]
197 },
198 {
199 code: "foo.lastIndexOf(NaN)",
200 options: [{ enforceForIndexOf: false }]
201 },
202 {
203 code: "indexOf(NaN)",
204 options: [{ enforceForIndexOf: true }]
205 },
206 {
207 code: "lastIndexOf(NaN)",
208 options: [{ enforceForIndexOf: true }]
209 },
210 {
211 code: "new foo.indexOf(NaN)",
212 options: [{ enforceForIndexOf: true }]
213 },
214 {
215 code: "foo.bar(NaN)",
216 options: [{ enforceForIndexOf: true }]
217 },
218 {
219 code: "foo.IndexOf(NaN)",
220 options: [{ enforceForIndexOf: true }]
221 },
222 {
223 code: "foo[indexOf](NaN)",
224 options: [{ enforceForIndexOf: true }]
225 },
226 {
227 code: "foo[lastIndexOf](NaN)",
228 options: [{ enforceForIndexOf: true }]
229 },
230 {
231 code: "indexOf.foo(NaN)",
232 options: [{ enforceForIndexOf: true }]
233 },
234 {
235 code: "foo.indexOf()",
236 options: [{ enforceForIndexOf: true }]
237 },
238 {
239 code: "foo.lastIndexOf()",
240 options: [{ enforceForIndexOf: true }]
241 },
242 {
243 code: "foo.indexOf(a)",
244 options: [{ enforceForIndexOf: true }]
245 },
246 {
247 code: "foo.lastIndexOf(Nan)",
248 options: [{ enforceForIndexOf: true }]
249 },
250 {
251 code: "foo.indexOf(a, NaN)",
252 options: [{ enforceForIndexOf: true }]
253 },
254 {
255 code: "foo.lastIndexOf(NaN, b)",
256 options: [{ enforceForIndexOf: true }]
257 },
258 {
259 code: "foo.indexOf(a, b)",
260 options: [{ enforceForIndexOf: true }]
261 },
262 {
263 code: "foo.lastIndexOf(NaN, NaN)",
264 options: [{ enforceForIndexOf: true }]
265 },
266 {
267 code: "foo.indexOf(...NaN)",
268 options: [{ enforceForIndexOf: true }],
269 parserOptions: { ecmaVersion: 6 }
270 },
271 {
272 code: "foo.lastIndexOf(NaN())",
273 options: [{ enforceForIndexOf: true }]
274 },
275 {
276 code: "foo.indexOf(Number.NaN)",
277 options: [{}]
278 },
279 {
280 code: "foo.lastIndexOf(Number.NaN)",
281 options: [{}]
282 },
283 {
284 code: "foo.indexOf(Number.NaN)",
285 options: [{ enforceForIndexOf: false }]
286 },
287 {
288 code: "foo.lastIndexOf(Number.NaN)",
289 options: [{ enforceForIndexOf: false }]
290 },
291 {
292 code: "indexOf(Number.NaN)",
293 options: [{ enforceForIndexOf: true }]
294 },
295 {
296 code: "lastIndexOf(Number.NaN)",
297 options: [{ enforceForIndexOf: true }]
298 },
299 {
300 code: "new foo.indexOf(Number.NaN)",
301 options: [{ enforceForIndexOf: true }]
302 },
303 {
304 code: "foo.bar(Number.NaN)",
305 options: [{ enforceForIndexOf: true }]
306 },
307 {
308 code: "foo.IndexOf(Number.NaN)",
309 options: [{ enforceForIndexOf: true }]
310 },
311 {
312 code: "foo[indexOf](Number.NaN)",
313 options: [{ enforceForIndexOf: true }]
314 },
315 {
316 code: "foo[lastIndexOf](Number.NaN)",
317 options: [{ enforceForIndexOf: true }]
318 },
319 {
320 code: "indexOf.foo(Number.NaN)",
321 options: [{ enforceForIndexOf: true }]
322 },
323 {
324 code: "foo.lastIndexOf(Number.Nan)",
325 options: [{ enforceForIndexOf: true }]
326 },
327 {
328 code: "foo.indexOf(a, Number.NaN)",
329 options: [{ enforceForIndexOf: true }]
330 },
331 {
332 code: "foo.lastIndexOf(Number.NaN, b)",
333 options: [{ enforceForIndexOf: true }]
334 },
335 {
336 code: "foo.lastIndexOf(Number.NaN, NaN)",
337 options: [{ enforceForIndexOf: true }]
338 },
339 {
340 code: "foo.indexOf(...Number.NaN)",
341 options: [{ enforceForIndexOf: true }],
342 parserOptions: { ecmaVersion: 6 }
343 },
344 {
345 code: "foo.lastIndexOf(Number.NaN())",
346 options: [{ enforceForIndexOf: true }]
347 }
348 ],
349 invalid: [
350 {
351 code: "123 == NaN;",
352 errors: [comparisonError]
353 },
354 {
355 code: "123 === NaN;",
356 errors: [comparisonError]
357 },
358 {
359 code: "NaN === \"abc\";",
360 errors: [comparisonError]
361 },
362 {
363 code: "NaN == \"abc\";",
364 errors: [comparisonError]
365 },
366 {
367 code: "123 != NaN;",
368 errors: [comparisonError]
369 },
370 {
371 code: "123 !== NaN;",
372 errors: [comparisonError]
373 },
374 {
375 code: "NaN !== \"abc\";",
376 errors: [comparisonError]
377 },
378 {
379 code: "NaN != \"abc\";",
380 errors: [comparisonError]
381 },
382 {
383 code: "NaN < \"abc\";",
384 errors: [comparisonError]
385 },
386 {
387 code: "\"abc\" < NaN;",
388 errors: [comparisonError]
389 },
390 {
391 code: "NaN > \"abc\";",
392 errors: [comparisonError]
393 },
394 {
395 code: "\"abc\" > NaN;",
396 errors: [comparisonError]
397 },
398 {
399 code: "NaN <= \"abc\";",
400 errors: [comparisonError]
401 },
402 {
403 code: "\"abc\" <= NaN;",
404 errors: [comparisonError]
405 },
406 {
407 code: "NaN >= \"abc\";",
408 errors: [comparisonError]
409 },
410 {
411 code: "\"abc\" >= NaN;",
412 errors: [comparisonError]
413 },
414 {
415 code: "123 == Number.NaN;",
416 errors: [comparisonError]
417 },
418 {
419 code: "123 === Number.NaN;",
420 errors: [comparisonError]
421 },
422 {
423 code: "Number.NaN === \"abc\";",
424 errors: [comparisonError]
425 },
426 {
427 code: "Number.NaN == \"abc\";",
428 errors: [comparisonError]
429 },
430 {
431 code: "123 != Number.NaN;",
432 errors: [comparisonError]
433 },
434 {
435 code: "123 !== Number.NaN;",
436 errors: [comparisonError]
437 },
438 {
439 code: "Number.NaN !== \"abc\";",
440 errors: [comparisonError]
441 },
442 {
443 code: "Number.NaN != \"abc\";",
444 errors: [comparisonError]
445 },
446 {
447 code: "Number.NaN < \"abc\";",
448 errors: [comparisonError]
449 },
450 {
451 code: "\"abc\" < Number.NaN;",
452 errors: [comparisonError]
453 },
454 {
455 code: "Number.NaN > \"abc\";",
456 errors: [comparisonError]
457 },
458 {
459 code: "\"abc\" > Number.NaN;",
460 errors: [comparisonError]
461 },
462 {
463 code: "Number.NaN <= \"abc\";",
464 errors: [comparisonError]
465 },
466 {
467 code: "\"abc\" <= Number.NaN;",
468 errors: [comparisonError]
469 },
470 {
471 code: "Number.NaN >= \"abc\";",
472 errors: [comparisonError]
473 },
474 {
475 code: "\"abc\" >= Number.NaN;",
476 errors: [comparisonError]
477 },
478 {
479 code: "x === Number?.NaN;",
480 parserOptions: { ecmaVersion: 2020 },
481 errors: [comparisonError]
482 },
483 {
484 code: "x === Number['NaN'];",
485 errors: [comparisonError]
486 },
487
488 //------------------------------------------------------------------------------
489 // enforceForSwitchCase
490 //------------------------------------------------------------------------------
491
492 {
493 code: "switch(NaN) { case foo: break; }",
494 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
495 },
496 {
497 code: "switch(foo) { case NaN: break; }",
498 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 15 }]
499 },
500 {
501 code: "switch(NaN) { case foo: break; }",
502 options: [{}],
503 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
504 },
505 {
506 code: "switch(foo) { case NaN: break; }",
507 options: [{}],
508 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 15 }]
509 },
510 {
511 code: "switch(NaN) {}",
512 options: [{ enforceForSwitchCase: true }],
513 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
514 },
515 {
516 code: "switch(NaN) { case foo: break; }",
517 options: [{ enforceForSwitchCase: true }],
518 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
519 },
520 {
521 code: "switch(NaN) { default: break; }",
522 options: [{ enforceForSwitchCase: true }],
523 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
524 },
525 {
526 code: "switch(NaN) { case foo: break; default: break; }",
527 options: [{ enforceForSwitchCase: true }],
528 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
529 },
530 {
531 code: "switch(foo) { case NaN: }",
532 options: [{ enforceForSwitchCase: true }],
533 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 15 }]
534 },
535 {
536 code: "switch(foo) { case NaN: break; }",
537 options: [{ enforceForSwitchCase: true }],
538 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 15 }]
539 },
540 {
541 code: "switch(foo) { case (NaN): break; }",
542 options: [{ enforceForSwitchCase: true }],
543 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 15 }]
544 },
545 {
546 code: "switch(foo) { case bar: break; case NaN: break; default: break; }",
547 options: [{ enforceForSwitchCase: true }],
548 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 32 }]
549 },
550 {
551 code: "switch(foo) { case bar: case NaN: default: break; }",
552 options: [{ enforceForSwitchCase: true }],
553 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 25 }]
554 },
555 {
556 code: "switch(foo) { case bar: break; case NaN: break; case baz: break; case NaN: break; }",
557 options: [{ enforceForSwitchCase: true }],
558 errors: [
559 { messageId: "caseNaN", type: "SwitchCase", column: 32 },
560 { messageId: "caseNaN", type: "SwitchCase", column: 66 }
561 ]
562 },
563 {
564 code: "switch(NaN) { case NaN: break; }",
565 options: [{ enforceForSwitchCase: true }],
566 errors: [
567 { messageId: "switchNaN", type: "SwitchStatement", column: 1 },
568 { messageId: "caseNaN", type: "SwitchCase", column: 15 }
569 ]
570 },
571 {
572 code: "switch(Number.NaN) { case foo: break; }",
573 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
574 },
575 {
576 code: "switch(foo) { case Number.NaN: break; }",
577 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 15 }]
578 },
579 {
580 code: "switch(Number.NaN) { case foo: break; }",
581 options: [{}],
582 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
583 },
584 {
585 code: "switch(foo) { case Number.NaN: break; }",
586 options: [{}],
587 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 15 }]
588 },
589 {
590 code: "switch(Number.NaN) {}",
591 options: [{ enforceForSwitchCase: true }],
592 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
593 },
594 {
595 code: "switch(Number.NaN) { case foo: break; }",
596 options: [{ enforceForSwitchCase: true }],
597 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
598 },
599 {
600 code: "switch(Number.NaN) { default: break; }",
601 options: [{ enforceForSwitchCase: true }],
602 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
603 },
604 {
605 code: "switch(Number.NaN) { case foo: break; default: break; }",
606 options: [{ enforceForSwitchCase: true }],
607 errors: [{ messageId: "switchNaN", type: "SwitchStatement", column: 1 }]
608 },
609 {
610 code: "switch(foo) { case Number.NaN: }",
611 options: [{ enforceForSwitchCase: true }],
612 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 15 }]
613 },
614 {
615 code: "switch(foo) { case Number.NaN: break; }",
616 options: [{ enforceForSwitchCase: true }],
617 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 15 }]
618 },
619 {
620 code: "switch(foo) { case (Number.NaN): break; }",
621 options: [{ enforceForSwitchCase: true }],
622 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 15 }]
623 },
624 {
625 code: "switch(foo) { case bar: break; case Number.NaN: break; default: break; }",
626 options: [{ enforceForSwitchCase: true }],
627 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 32 }]
628 },
629 {
630 code: "switch(foo) { case bar: case Number.NaN: default: break; }",
631 options: [{ enforceForSwitchCase: true }],
632 errors: [{ messageId: "caseNaN", type: "SwitchCase", column: 25 }]
633 },
634 {
635 code: "switch(foo) { case bar: break; case NaN: break; case baz: break; case Number.NaN: break; }",
636 options: [{ enforceForSwitchCase: true }],
637 errors: [
638 { messageId: "caseNaN", type: "SwitchCase", column: 32 },
639 { messageId: "caseNaN", type: "SwitchCase", column: 66 }
640 ]
641 },
642 {
643 code: "switch(Number.NaN) { case Number.NaN: break; }",
644 options: [{ enforceForSwitchCase: true }],
645 errors: [
646 { messageId: "switchNaN", type: "SwitchStatement", column: 1 },
647 { messageId: "caseNaN", type: "SwitchCase", column: 22 }
648 ]
649 },
650
651 //------------------------------------------------------------------------------
652 // enforceForIndexOf
653 //------------------------------------------------------------------------------
654
655 {
656 code: "foo.indexOf(NaN)",
657 options: [{ enforceForIndexOf: true }],
658 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "indexOf" } }]
659 },
660 {
661 code: "foo.lastIndexOf(NaN)",
662 options: [{ enforceForIndexOf: true }],
663 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "lastIndexOf" } }]
664 },
665 {
666 code: "foo['indexOf'](NaN)",
667 options: [{ enforceForIndexOf: true }],
668 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "indexOf" } }]
669 },
670 {
671 code: "foo['lastIndexOf'](NaN)",
672 options: [{ enforceForIndexOf: true }],
673 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "lastIndexOf" } }]
674 },
675 {
676 code: "foo().indexOf(NaN)",
677 options: [{ enforceForIndexOf: true }],
678 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "indexOf" } }]
679 },
680 {
681 code: "foo.bar.lastIndexOf(NaN)",
682 options: [{ enforceForIndexOf: true }],
683 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "lastIndexOf" } }]
684 },
685 {
686 code: "foo.indexOf?.(NaN)",
687 options: [{ enforceForIndexOf: true }],
688 parserOptions: { ecmaVersion: 2020 },
689 errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }]
690 },
691 {
692 code: "foo?.indexOf(NaN)",
693 options: [{ enforceForIndexOf: true }],
694 parserOptions: { ecmaVersion: 2020 },
695 errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }]
696 },
697 {
698 code: "(foo?.indexOf)(NaN)",
699 options: [{ enforceForIndexOf: true }],
700 parserOptions: { ecmaVersion: 2020 },
701 errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }]
702 },
703 {
704 code: "foo.indexOf(Number.NaN)",
705 options: [{ enforceForIndexOf: true }],
706 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "indexOf" } }]
707 },
708 {
709 code: "foo.lastIndexOf(Number.NaN)",
710 options: [{ enforceForIndexOf: true }],
711 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "lastIndexOf" } }]
712 },
713 {
714 code: "foo['indexOf'](Number.NaN)",
715 options: [{ enforceForIndexOf: true }],
716 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "indexOf" } }]
717 },
718 {
719 code: "foo['lastIndexOf'](Number.NaN)",
720 options: [{ enforceForIndexOf: true }],
721 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "lastIndexOf" } }]
722 },
723 {
724 code: "foo().indexOf(Number.NaN)",
725 options: [{ enforceForIndexOf: true }],
726 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "indexOf" } }]
727 },
728 {
729 code: "foo.bar.lastIndexOf(Number.NaN)",
730 options: [{ enforceForIndexOf: true }],
731 errors: [{ messageId: "indexOfNaN", type: "CallExpression", data: { methodName: "lastIndexOf" } }]
732 },
733 {
734 code: "foo.indexOf?.(Number.NaN)",
735 options: [{ enforceForIndexOf: true }],
736 parserOptions: { ecmaVersion: 2020 },
737 errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }]
738 },
739 {
740 code: "foo?.indexOf(Number.NaN)",
741 options: [{ enforceForIndexOf: true }],
742 parserOptions: { ecmaVersion: 2020 },
743 errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }]
744 },
745 {
746 code: "(foo?.indexOf)(Number.NaN)",
747 options: [{ enforceForIndexOf: true }],
748 parserOptions: { ecmaVersion: 2020 },
749 errors: [{ messageId: "indexOfNaN", data: { methodName: "indexOf" } }]
750 }
751 ]
752 });