]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/id-blacklist.js
upgrade to v7.0.0
[pve-eslint.git] / eslint / tests / lib / rules / id-blacklist.js
1 /**
2 * @fileoverview Tests for id-blacklist rule.
3 * @author Keith Cirkel
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/id-blacklist"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20 const error = { messageId: "blacklisted", type: "Identifier" };
21
22 ruleTester.run("id-blacklist", rule, {
23 valid: [
24 {
25 code: "foo = \"bar\"",
26 options: ["bar"]
27 },
28 {
29 code: "bar = \"bar\"",
30 options: ["foo"]
31 },
32 {
33 code: "foo = \"bar\"",
34 options: ["f", "fo", "fooo", "bar"]
35 },
36 {
37 code: "function foo(){}",
38 options: ["bar"]
39 },
40 {
41 code: "foo()",
42 options: ["f", "fo", "fooo", "bar"]
43 },
44 {
45 code: "import { foo as bar } from 'mod'",
46 options: ["foo"],
47 parserOptions: { ecmaVersion: 6, sourceType: "module" }
48 },
49 {
50 code: "export { foo as bar } from 'mod'",
51 options: ["foo"],
52 parserOptions: { ecmaVersion: 6, sourceType: "module" }
53 },
54 {
55 code: "foo.bar()",
56 options: ["f", "fo", "fooo", "b", "ba", "baz"]
57 },
58 {
59 code: "var foo = bar.baz;",
60 options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz"]
61 },
62 {
63 code: "var foo = bar.baz.bing;",
64 options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"]
65 },
66 {
67 code: "foo.bar.baz = bing.bong.bash;",
68 options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"]
69 },
70 {
71 code: "if (foo.bar) {}",
72 options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"]
73 },
74 {
75 code: "var obj = { key: foo.bar };",
76 options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"]
77 },
78 {
79 code: "const {foo: bar} = baz",
80 options: ["foo"],
81 parserOptions: { ecmaVersion: 6 }
82 },
83 {
84 code: "const {foo: {bar: baz}} = qux",
85 options: ["foo", "bar"],
86 parserOptions: { ecmaVersion: 6 }
87 },
88 {
89 code: "function foo({ bar: baz }) {}",
90 options: ["bar"],
91 parserOptions: { ecmaVersion: 6 }
92 },
93 {
94 code: "function foo({ bar: {baz: qux} }) {}",
95 options: ["bar", "baz"],
96 parserOptions: { ecmaVersion: 6 }
97 },
98 {
99 code: "function foo({baz} = obj.qux) {}",
100 options: ["qux"],
101 parserOptions: { ecmaVersion: 6 }
102 },
103 {
104 code: "function foo({ foo: {baz} = obj.qux }) {}",
105 options: ["qux"],
106 parserOptions: { ecmaVersion: 6 }
107 },
108 {
109 code: "({a: bar = obj.baz});",
110 options: ["baz"],
111 parserOptions: { ecmaVersion: 6 }
112 },
113 {
114 code: "({foo: {a: bar = obj.baz}} = qux);",
115 options: ["baz"],
116 parserOptions: { ecmaVersion: 6 }
117 },
118 {
119 code: "var arr = [foo.bar];",
120 options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"]
121 },
122 {
123 code: "[foo.bar]",
124 options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"]
125 },
126 {
127 code: "[foo.bar.nesting]",
128 options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"]
129 },
130 {
131 code: "if (foo.bar === bar.baz) { [foo.bar] }",
132 options: ["f", "fo", "fooo", "b", "ba", "barr", "bazz", "bingg"]
133 },
134 {
135 code: "var myArray = new Array(); var myDate = new Date();",
136 options: ["array", "date", "mydate", "myarray", "new", "var"]
137 },
138 {
139 code: "foo()",
140 options: ["foo"]
141 },
142 {
143 code: "foo.bar()",
144 options: ["bar"]
145 },
146 {
147 code: "foo.bar",
148 options: ["bar"]
149 },
150 {
151 code: "({foo: obj.bar.bar.bar.baz} = {});",
152 options: ["foo", "bar"],
153 parserOptions: { ecmaVersion: 6 }
154 },
155 {
156 code: "({[obj.bar]: a = baz} = qux);",
157 options: ["bar"],
158 parserOptions: { ecmaVersion: 6 }
159 },
160
161 // references to global variables
162 {
163 code: "Number.parseInt()",
164 options: ["Number"]
165 },
166 {
167 code: "x = Number.NaN;",
168 options: ["Number"]
169 },
170 {
171 code: "var foo = undefined;",
172 options: ["undefined"]
173 },
174 {
175 code: "if (foo === undefined);",
176 options: ["undefined"]
177 },
178 {
179 code: "obj[undefined] = 5;", // creates obj["undefined"]. It should be disallowed, but the rule doesn't know values of globals and can't control computed access.
180 options: ["undefined"]
181 },
182 {
183 code: "foo = { [myGlobal]: 1 };",
184 options: ["myGlobal"],
185 parserOptions: { ecmaVersion: 6 },
186 globals: { myGlobal: "readonly" }
187 },
188 {
189 code: "({ myGlobal } = foo);", // writability doesn't affect the logic, it's always assumed that user doesn't have control over the names of globals.
190 options: ["myGlobal"],
191 parserOptions: { ecmaVersion: 6 },
192 globals: { myGlobal: "writable" }
193 },
194 {
195 code: "/* global myGlobal: readonly */ myGlobal = 5;",
196 options: ["myGlobal"]
197 },
198 {
199 code: "var foo = [Map];",
200 options: ["Map"],
201 env: { es6: true }
202 },
203 {
204 code: "var foo = { bar: window.baz };",
205 options: ["window"],
206 env: { browser: true }
207 }
208 ],
209 invalid: [
210 {
211 code: "foo = \"bar\"",
212 options: ["foo"],
213 errors: [
214 error
215 ]
216 },
217 {
218 code: "bar = \"bar\"",
219 options: ["bar"],
220 errors: [
221 error
222 ]
223 },
224 {
225 code: "foo = \"bar\"",
226 options: ["f", "fo", "foo", "bar"],
227 errors: [
228 error
229 ]
230 },
231 {
232 code: "function foo(){}",
233 options: ["f", "fo", "foo", "bar"],
234 errors: [
235 error
236 ]
237 },
238 {
239 code: "import foo from 'mod'",
240 options: ["foo"],
241 parserOptions: { ecmaVersion: 6, sourceType: "module" },
242 errors: [
243 error
244 ]
245 },
246 {
247 code: "import * as foo from 'mod'",
248 options: ["foo"],
249 parserOptions: { ecmaVersion: 6, sourceType: "module" },
250 errors: [
251 error
252 ]
253 },
254 {
255 code: "import { foo } from 'mod'",
256 options: ["foo"],
257 parserOptions: { ecmaVersion: 6, sourceType: "module" },
258 errors: [
259 error
260 ]
261 },
262 {
263 code: "import { foo as bar } from 'mod'",
264 options: ["bar"],
265 parserOptions: { ecmaVersion: 6, sourceType: "module" },
266 errors: [{
267 messageId: "blacklisted",
268 data: { name: "bar" },
269 type: "Identifier",
270 column: 17
271 }]
272 },
273 {
274 code: "import { foo as bar } from 'mod'",
275 options: ["foo", "bar"],
276 parserOptions: { ecmaVersion: 6, sourceType: "module" },
277 errors: [{
278 messageId: "blacklisted",
279 data: { name: "bar" },
280 type: "Identifier",
281 column: 17
282 }]
283 },
284 {
285 code: "import { foo as foo } from 'mod'",
286 options: ["foo"],
287 parserOptions: { ecmaVersion: 6, sourceType: "module" },
288 errors: [{
289 messageId: "blacklisted",
290 data: { name: "foo" },
291 type: "Identifier",
292 column: 17
293 }]
294 },
295 {
296 code: "import { foo, foo as bar } from 'mod'",
297 options: ["foo"],
298 parserOptions: { ecmaVersion: 6, sourceType: "module" },
299 errors: [{
300 messageId: "blacklisted",
301 data: { name: "foo" },
302 type: "Identifier",
303 column: 10
304 }]
305 },
306 {
307 code: "import { foo as bar, foo } from 'mod'",
308 options: ["foo"],
309 parserOptions: { ecmaVersion: 6, sourceType: "module" },
310 errors: [{
311 messageId: "blacklisted",
312 data: { name: "foo" },
313 type: "Identifier",
314 column: 22
315 }]
316 },
317 {
318 code: "import foo, { foo as bar } from 'mod'",
319 options: ["foo"],
320 parserOptions: { ecmaVersion: 6, sourceType: "module" },
321 errors: [{
322 messageId: "blacklisted",
323 data: { name: "foo" },
324 type: "Identifier",
325 column: 8
326 }]
327 },
328 {
329 code: "var foo; export { foo as bar };",
330 options: ["bar"],
331 parserOptions: { ecmaVersion: 6, sourceType: "module" },
332 errors: [{
333 messageId: "blacklisted",
334 data: { name: "bar" },
335 type: "Identifier",
336 column: 26
337 }]
338 },
339 {
340 code: "var foo; export { foo };",
341 options: ["foo"],
342 parserOptions: { ecmaVersion: 6, sourceType: "module" },
343 errors: [
344 {
345 messageId: "blacklisted",
346 data: { name: "foo" },
347 type: "Identifier",
348 column: 5
349 },
350 {
351 messageId: "blacklisted",
352 data: { name: "foo" },
353 type: "Identifier",
354 column: 19
355 }
356 ]
357 },
358 {
359 code: "var foo; export { foo as bar };",
360 options: ["foo"],
361 parserOptions: { ecmaVersion: 6, sourceType: "module" },
362 errors: [
363 {
364 messageId: "blacklisted",
365 data: { name: "foo" },
366 type: "Identifier",
367 column: 5
368 },
369
370 // reports each occurrence of local identifier, although it's renamed in this export specifier
371 {
372 messageId: "blacklisted",
373 data: { name: "foo" },
374 type: "Identifier",
375 column: 19
376 }
377 ]
378 },
379 {
380 code: "var foo; export { foo as foo };",
381 options: ["foo"],
382 parserOptions: { ecmaVersion: 6, sourceType: "module" },
383 errors: [
384 {
385 messageId: "blacklisted",
386 data: { name: "foo" },
387 type: "Identifier",
388 column: 5
389 },
390 {
391 messageId: "blacklisted",
392 data: { name: "foo" },
393 type: "Identifier",
394 column: 19
395 },
396 {
397 messageId: "blacklisted",
398 data: { name: "foo" },
399 type: "Identifier",
400 column: 26
401 }
402 ]
403 },
404 {
405 code: "var foo; export { foo as bar };",
406 options: ["foo", "bar"],
407 parserOptions: { ecmaVersion: 6, sourceType: "module" },
408 errors: [
409 {
410 messageId: "blacklisted",
411 data: { name: "foo" },
412 type: "Identifier",
413 column: 5
414 },
415 {
416 messageId: "blacklisted",
417 data: { name: "foo" },
418 type: "Identifier",
419 column: 19
420 },
421 {
422 messageId: "blacklisted",
423 data: { name: "bar" },
424 type: "Identifier",
425 column: 26
426 }
427 ]
428 },
429 {
430 code: "export { foo } from 'mod'",
431 options: ["foo"],
432 parserOptions: { ecmaVersion: 6, sourceType: "module" },
433 errors: [
434 error
435 ]
436 },
437 {
438 code: "export { foo as bar } from 'mod'",
439 options: ["bar"],
440 parserOptions: { ecmaVersion: 6, sourceType: "module" },
441 errors: [{
442 messageId: "blacklisted",
443 data: { name: "bar" },
444 type: "Identifier",
445 column: 17
446 }]
447 },
448 {
449 code: "export { foo as bar } from 'mod'",
450 options: ["foo", "bar"],
451 parserOptions: { ecmaVersion: 6, sourceType: "module" },
452 errors: [{
453 messageId: "blacklisted",
454 data: { name: "bar" },
455 type: "Identifier",
456 column: 17
457 }]
458 },
459 {
460 code: "export { foo as foo } from 'mod'",
461 options: ["foo"],
462 parserOptions: { ecmaVersion: 6, sourceType: "module" },
463 errors: [{
464 messageId: "blacklisted",
465 data: { name: "foo" },
466 type: "Identifier",
467 column: 17
468 }]
469 },
470 {
471 code: "export { foo, foo as bar } from 'mod'",
472 options: ["foo"],
473 parserOptions: { ecmaVersion: 6, sourceType: "module" },
474 errors: [{
475 messageId: "blacklisted",
476 data: { name: "foo" },
477 type: "Identifier",
478 column: 10
479 }]
480 },
481 {
482 code: "export { foo as bar, foo } from 'mod'",
483 options: ["foo"],
484 parserOptions: { ecmaVersion: 6, sourceType: "module" },
485 errors: [{
486 messageId: "blacklisted",
487 data: { name: "foo" },
488 type: "Identifier",
489 column: 22
490 }]
491 },
492 {
493 code: "foo.bar()",
494 options: ["f", "fo", "foo", "b", "ba", "baz"],
495 errors: [
496 error
497 ]
498 },
499 {
500 code: "foo[bar] = baz;",
501 options: ["bar"],
502 errors: [{
503 messageId: "blacklisted",
504 data: { name: "bar" },
505 type: "Identifier"
506 }]
507 },
508 {
509 code: "baz = foo[bar];",
510 options: ["bar"],
511 errors: [{
512 messageId: "blacklisted",
513 data: { name: "bar" },
514 type: "Identifier"
515 }]
516 },
517 {
518 code: "var foo = bar.baz;",
519 options: ["f", "fo", "foo", "b", "ba", "barr", "bazz"],
520 errors: [
521 error
522 ]
523 },
524 {
525 code: "var foo = bar.baz;",
526 options: ["f", "fo", "fooo", "b", "ba", "bar", "bazz"],
527 errors: [
528 error
529 ]
530 },
531 {
532 code: "if (foo.bar) {}",
533 options: ["f", "fo", "foo", "b", "ba", "barr", "bazz", "bingg"],
534 errors: [
535 error
536 ]
537 },
538 {
539 code: "var obj = { key: foo.bar };",
540 options: ["obj"],
541 errors: [
542 error
543 ]
544 },
545 {
546 code: "var obj = { key: foo.bar };",
547 options: ["key"],
548 errors: [
549 error
550 ]
551 },
552 {
553 code: "var obj = { key: foo.bar };",
554 options: ["foo"],
555 errors: [
556 error
557 ]
558 },
559 {
560 code: "var arr = [foo.bar];",
561 options: ["arr"],
562 errors: [
563 error
564 ]
565 },
566 {
567 code: "var arr = [foo.bar];",
568 options: ["foo"],
569 errors: [
570 error
571 ]
572 },
573 {
574 code: "[foo.bar]",
575 options: ["f", "fo", "foo", "b", "ba", "barr", "bazz", "bingg"],
576 errors: [
577 error
578 ]
579 },
580 {
581 code: "if (foo.bar === bar.baz) { [bing.baz] }",
582 options: ["f", "fo", "foo", "b", "ba", "barr", "bazz", "bingg"],
583 errors: [
584 error
585 ]
586 },
587 {
588 code: "if (foo.bar === bar.baz) { [foo.bar] }",
589 options: ["f", "fo", "fooo", "b", "ba", "bar", "bazz", "bingg"],
590 errors: [
591 error
592 ]
593 },
594 {
595 code: "var myArray = new Array(); var myDate = new Date();",
596 options: ["array", "date", "myDate", "myarray", "new", "var"],
597 errors: [
598 error
599 ]
600 },
601 {
602 code: "var myArray = new Array(); var myDate = new Date();",
603 options: ["array", "date", "mydate", "myArray", "new", "var"],
604 errors: [
605 error
606 ]
607 },
608 {
609 code: "foo.bar = 1",
610 options: ["bar"],
611 errors: [
612 error
613 ]
614 },
615 {
616 code: "foo.bar.baz = 1",
617 options: ["bar", "baz"],
618 errors: [
619 error
620 ]
621 },
622 {
623 code: "const {foo} = baz",
624 options: ["foo"],
625 parserOptions: { ecmaVersion: 6 },
626 errors: [
627 {
628 messageId: "blacklisted",
629 data: { name: "foo" },
630 type: "Identifier",
631 column: 8
632 }
633 ]
634 },
635 {
636 code: "const {foo: bar} = baz",
637 options: ["foo", "bar"],
638 parserOptions: { ecmaVersion: 6 },
639 errors: [
640 {
641 messageId: "blacklisted",
642 data: { name: "bar" },
643 type: "Identifier",
644 column: 13
645 }
646 ]
647 },
648 {
649 code: "const {[foo]: bar} = baz",
650 options: ["foo", "bar"],
651 parserOptions: { ecmaVersion: 6 },
652 errors: [
653 {
654 messageId: "blacklisted",
655 data: { name: "foo" },
656 type: "Identifier",
657 column: 9
658 },
659 {
660 messageId: "blacklisted",
661 data: { name: "bar" },
662 type: "Identifier",
663 column: 15
664 }
665 ]
666 },
667 {
668 code: "const {foo: {bar: baz}} = qux",
669 options: ["foo", "bar", "baz"],
670 parserOptions: { ecmaVersion: 6 },
671 errors: [
672 {
673 messageId: "blacklisted",
674 data: { name: "baz" },
675 type: "Identifier",
676 column: 19
677 }
678 ]
679 },
680 {
681 code: "const {foo: {[bar]: baz}} = qux",
682 options: ["foo", "bar", "baz"],
683 parserOptions: { ecmaVersion: 6 },
684 errors: [
685 {
686 messageId: "blacklisted",
687 data: { name: "bar" },
688 type: "Identifier",
689 column: 15
690 },
691 {
692 messageId: "blacklisted",
693 data: { name: "baz" },
694 type: "Identifier",
695 column: 21
696 }
697 ]
698 },
699 {
700 code: "const {[foo]: {[bar]: baz}} = qux",
701 options: ["foo", "bar", "baz"],
702 parserOptions: { ecmaVersion: 6 },
703 errors: [
704 {
705 messageId: "blacklisted",
706 data: { name: "foo" },
707 type: "Identifier",
708 column: 9
709 },
710 {
711 messageId: "blacklisted",
712 data: { name: "bar" },
713 type: "Identifier",
714 column: 17
715 },
716 {
717 messageId: "blacklisted",
718 data: { name: "baz" },
719 type: "Identifier",
720 column: 23
721 }
722 ]
723 },
724 {
725 code: "function foo({ bar: baz }) {}",
726 options: ["bar", "baz"],
727 parserOptions: { ecmaVersion: 6 },
728 errors: [
729 {
730 messageId: "blacklisted",
731 data: { name: "baz" },
732 type: "Identifier",
733 column: 21
734 }
735 ]
736 },
737 {
738 code: "function foo({ bar: {baz: qux} }) {}",
739 options: ["bar", "baz", "qux"],
740 parserOptions: { ecmaVersion: 6 },
741 errors: [
742 {
743 messageId: "blacklisted",
744 data: { name: "qux" },
745 type: "Identifier",
746 column: 27
747 }
748 ]
749 },
750 {
751 code: "({foo: obj.bar} = baz);",
752 options: ["foo", "bar"],
753 parserOptions: { ecmaVersion: 6 },
754 errors: [
755 {
756 messageId: "blacklisted",
757 data: { name: "bar" },
758 type: "Identifier",
759 column: 12
760 }
761 ]
762 },
763 {
764 code: "({foo: obj.bar.bar.bar.baz} = {});",
765 options: ["foo", "bar", "baz"],
766 parserOptions: { ecmaVersion: 6 },
767 errors: [
768 {
769 messageId: "blacklisted",
770 data: { name: "baz" },
771 type: "Identifier",
772 column: 24
773 }
774 ]
775 },
776 {
777 code: "({[foo]: obj.bar} = baz);",
778 options: ["foo", "bar"],
779 parserOptions: { ecmaVersion: 6 },
780 errors: [
781 {
782 messageId: "blacklisted",
783 data: { name: "foo" },
784 type: "Identifier",
785 column: 4
786 },
787 {
788 messageId: "blacklisted",
789 data: { name: "bar" },
790 type: "Identifier",
791 column: 14
792 }
793 ]
794 },
795 {
796 code: "({foo: { a: obj.bar }} = baz);",
797 options: ["bar"],
798 parserOptions: { ecmaVersion: 6 },
799 errors: [
800 {
801 messageId: "blacklisted",
802 data: { name: "bar" },
803 type: "Identifier",
804 column: 17
805 }
806 ]
807 },
808 {
809 code: "({a: obj.bar = baz} = qux);",
810 options: ["bar"],
811 parserOptions: { ecmaVersion: 6 },
812 errors: [
813 {
814 messageId: "blacklisted",
815 data: { name: "bar" },
816 type: "Identifier",
817 column: 10
818 }
819 ]
820 },
821 {
822 code: "({a: obj.bar.bar.baz = obj.qux} = obj.qux);",
823 options: ["a", "bar", "baz", "qux"],
824 parserOptions: { ecmaVersion: 6 },
825 errors: [
826 {
827 messageId: "blacklisted",
828 data: { name: "baz" },
829 type: "Identifier",
830 column: 18
831 }
832 ]
833 },
834 {
835 code: "({a: obj[bar] = obj.qux} = obj.qux);",
836 options: ["a", "bar", "baz", "qux"],
837 parserOptions: { ecmaVersion: 6 },
838 errors: [
839 {
840 messageId: "blacklisted",
841 data: { name: "bar" },
842 type: "Identifier",
843 column: 10
844 }
845 ]
846 },
847 {
848 code: "({a: [obj.bar] = baz} = qux);",
849 options: ["bar"],
850 parserOptions: { ecmaVersion: 6 },
851 errors: [
852 {
853 messageId: "blacklisted",
854 data: { name: "bar" },
855 type: "Identifier",
856 column: 11
857 }
858 ]
859 },
860 {
861 code: "({foo: { a: obj.bar = baz}} = qux);",
862 options: ["bar"],
863 parserOptions: { ecmaVersion: 6 },
864 errors: [
865 {
866 messageId: "blacklisted",
867 data: { name: "bar" },
868 type: "Identifier",
869 column: 17
870 }
871 ]
872 },
873 {
874 code: "({foo: { [a]: obj.bar }} = baz);",
875 options: ["bar"],
876 parserOptions: { ecmaVersion: 6 },
877 errors: [
878 {
879 messageId: "blacklisted",
880 data: { name: "bar" },
881 type: "Identifier",
882 column: 19
883 }
884 ]
885 },
886 {
887 code: "({...obj.bar} = baz);",
888 options: ["bar"],
889 parserOptions: { ecmaVersion: 9 },
890 errors: [
891 {
892 messageId: "blacklisted",
893 data: { name: "bar" },
894 type: "Identifier",
895 column: 10
896 }
897 ]
898 },
899 {
900 code: "([obj.bar] = baz);",
901 options: ["bar"],
902 parserOptions: { ecmaVersion: 6 },
903 errors: [
904 {
905 messageId: "blacklisted",
906 data: { name: "bar" },
907 type: "Identifier",
908 column: 7
909 }
910 ]
911 },
912 {
913 code: "const [bar] = baz;",
914 options: ["bar"],
915 parserOptions: { ecmaVersion: 6 },
916 errors: [
917 {
918 messageId: "blacklisted",
919 data: { name: "bar" },
920 type: "Identifier",
921 column: 8
922 }
923 ]
924 },
925
926 // not a reference to a global variable, because it isn't a reference to a variable
927 {
928 code: "foo.undefined = 1;",
929 options: ["undefined"],
930 errors: [
931 {
932 messageId: "blacklisted",
933 data: { name: "undefined" },
934 type: "Identifier"
935 }
936 ]
937 },
938 {
939 code: "var foo = { undefined: 1 };",
940 options: ["undefined"],
941 errors: [
942 {
943 messageId: "blacklisted",
944 data: { name: "undefined" },
945 type: "Identifier"
946 }
947 ]
948 },
949 {
950 code: "var foo = { undefined: undefined };",
951 options: ["undefined"],
952 errors: [
953 {
954 messageId: "blacklisted",
955 data: { name: "undefined" },
956 type: "Identifier",
957 column: 13
958 }
959 ]
960 },
961 {
962 code: "var foo = { Number() {} };",
963 options: ["Number"],
964 parserOptions: { ecmaVersion: 6 },
965 errors: [
966 {
967 messageId: "blacklisted",
968 data: { name: "Number" },
969 type: "Identifier"
970 }
971 ]
972 },
973 {
974 code: "class Foo { Number() {} }",
975 options: ["Number"],
976 parserOptions: { ecmaVersion: 6 },
977 errors: [
978 {
979 messageId: "blacklisted",
980 data: { name: "Number" },
981 type: "Identifier"
982 }
983 ]
984 },
985 {
986 code: "myGlobal: while(foo) { break myGlobal; } ",
987 options: ["myGlobal"],
988 globals: { myGlobal: "readonly" },
989 errors: [
990 {
991 messageId: "blacklisted",
992 data: { name: "myGlobal" },
993 type: "Identifier",
994 column: 1
995 },
996 {
997 messageId: "blacklisted",
998 data: { name: "myGlobal" },
999 type: "Identifier",
1000 column: 30
1001 }
1002 ]
1003 },
1004
1005 // globals declared in the given source code are not excluded from consideration
1006 {
1007 code: "const foo = 1; bar = foo;",
1008 options: ["foo"],
1009 parserOptions: { ecmaVersion: 6 },
1010 errors: [
1011 {
1012 messageId: "blacklisted",
1013 data: { name: "foo" },
1014 type: "Identifier",
1015 column: 7
1016 },
1017 {
1018 messageId: "blacklisted",
1019 data: { name: "foo" },
1020 type: "Identifier",
1021 column: 22
1022 }
1023 ]
1024 },
1025 {
1026 code: "let foo; foo = bar;",
1027 options: ["foo"],
1028 parserOptions: { ecmaVersion: 6 },
1029 errors: [
1030 {
1031 messageId: "blacklisted",
1032 data: { name: "foo" },
1033 type: "Identifier",
1034 column: 5
1035 },
1036 {
1037 messageId: "blacklisted",
1038 data: { name: "foo" },
1039 type: "Identifier",
1040 column: 10
1041 }
1042 ]
1043 },
1044 {
1045 code: "bar = foo; var foo;",
1046 options: ["foo"],
1047 errors: [
1048 {
1049 messageId: "blacklisted",
1050 data: { name: "foo" },
1051 type: "Identifier",
1052 column: 7
1053 },
1054 {
1055 messageId: "blacklisted",
1056 data: { name: "foo" },
1057 type: "Identifier",
1058 column: 16
1059 }
1060 ]
1061 },
1062 {
1063 code: "function foo() {} var bar = foo;",
1064 options: ["foo"],
1065 errors: [
1066 {
1067 messageId: "blacklisted",
1068 data: { name: "foo" },
1069 type: "Identifier",
1070 column: 10
1071 },
1072 {
1073 messageId: "blacklisted",
1074 data: { name: "foo" },
1075 type: "Identifier",
1076 column: 29
1077 }
1078 ]
1079 },
1080 {
1081 code: "class Foo {} var bar = Foo;",
1082 options: ["Foo"],
1083 parserOptions: { ecmaVersion: 6 },
1084 errors: [
1085 {
1086 messageId: "blacklisted",
1087 data: { name: "Foo" },
1088 type: "Identifier",
1089 column: 7
1090 },
1091 {
1092 messageId: "blacklisted",
1093 data: { name: "Foo" },
1094 type: "Identifier",
1095 column: 24
1096 }
1097 ]
1098 },
1099
1100 // redeclared globals are not excluded from consideration
1101 {
1102 code: "let undefined; undefined = 1;",
1103 options: ["undefined"],
1104 parserOptions: { ecmaVersion: 6 },
1105 errors: [
1106 {
1107 messageId: "blacklisted",
1108 data: { name: "undefined" },
1109 type: "Identifier",
1110 column: 5
1111 },
1112 {
1113 messageId: "blacklisted",
1114 data: { name: "undefined" },
1115 type: "Identifier",
1116 column: 16
1117 }
1118 ]
1119 },
1120 {
1121 code: "foo = undefined; var undefined;",
1122 options: ["undefined"],
1123 errors: [
1124 {
1125 messageId: "blacklisted",
1126 data: { name: "undefined" },
1127 type: "Identifier",
1128 column: 7
1129 },
1130 {
1131 messageId: "blacklisted",
1132 data: { name: "undefined" },
1133 type: "Identifier",
1134 column: 22
1135 }
1136 ]
1137 },
1138 {
1139 code: "function undefined(){} x = undefined;",
1140 options: ["undefined"],
1141 errors: [
1142 {
1143 messageId: "blacklisted",
1144 data: { name: "undefined" },
1145 type: "Identifier",
1146 column: 10
1147 },
1148 {
1149 messageId: "blacklisted",
1150 data: { name: "undefined" },
1151 type: "Identifier",
1152 column: 28
1153 }
1154 ]
1155 },
1156 {
1157 code: "class Number {} x = Number.NaN;",
1158 options: ["Number"],
1159 parserOptions: { ecmaVersion: 6 },
1160 errors: [
1161 {
1162 messageId: "blacklisted",
1163 data: { name: "Number" },
1164 type: "Identifier",
1165 column: 7
1166 },
1167 {
1168 messageId: "blacklisted",
1169 data: { name: "Number" },
1170 type: "Identifier",
1171 column: 21
1172 }
1173 ]
1174 },
1175
1176 /*
1177 * Assignment to a property with a blacklisted name isn't allowed, in general.
1178 * In this case, that restriction prevents creating a global variable with a blacklisted name.
1179 */
1180 {
1181 code: "/* globals myGlobal */ window.myGlobal = 5; foo = myGlobal;",
1182 options: ["myGlobal"],
1183 env: { browser: true },
1184 errors: [
1185 {
1186 messageId: "blacklisted",
1187 data: { name: "myGlobal" },
1188 type: "Identifier",
1189 column: 31
1190 }
1191 ]
1192 },
1193
1194 // disabled global variables
1195 {
1196 code: "var foo = undefined;",
1197 options: ["undefined"],
1198 globals: { undefined: "off" },
1199 errors: [
1200 {
1201 messageId: "blacklisted",
1202 data: { name: "undefined" },
1203 type: "Identifier"
1204 }
1205 ]
1206 },
1207 {
1208 code: "/* globals Number: off */ Number.parseInt()",
1209 options: ["Number"],
1210 errors: [
1211 {
1212 messageId: "blacklisted",
1213 data: { name: "Number" },
1214 type: "Identifier"
1215 }
1216 ]
1217 },
1218 {
1219 code: "var foo = [Map];", // this actually isn't a disabled global: it was never enabled because es6 environment isn't enabled
1220 options: ["Map"],
1221 errors: [
1222 {
1223 messageId: "blacklisted",
1224 data: { name: "Map" },
1225 type: "Identifier"
1226 }
1227 ]
1228 },
1229
1230 // shadowed global variables
1231 {
1232 code: "if (foo) { let undefined; bar = undefined; }",
1233 options: ["undefined"],
1234 parserOptions: { ecmaVersion: 6 },
1235 errors: [
1236 {
1237 messageId: "blacklisted",
1238 data: { name: "undefined" },
1239 type: "Identifier",
1240 column: 16
1241 },
1242 {
1243 messageId: "blacklisted",
1244 data: { name: "undefined" },
1245 type: "Identifier",
1246 column: 33
1247 }
1248 ]
1249 },
1250 {
1251 code: "function foo(Number) { var x = Number.NaN; }",
1252 options: ["Number"],
1253 errors: [
1254 {
1255 messageId: "blacklisted",
1256 data: { name: "Number" },
1257 type: "Identifier",
1258 column: 14
1259 },
1260 {
1261 messageId: "blacklisted",
1262 data: { name: "Number" },
1263 type: "Identifier",
1264 column: 32
1265 }
1266 ]
1267 },
1268 {
1269 code: "function foo() { var myGlobal; x = myGlobal; }",
1270 options: ["myGlobal"],
1271 globals: { myGlobal: "readonly" },
1272 errors: [
1273 {
1274 messageId: "blacklisted",
1275 data: { name: "myGlobal" },
1276 type: "Identifier",
1277 column: 22
1278 },
1279 {
1280 messageId: "blacklisted",
1281 data: { name: "myGlobal" },
1282 type: "Identifier",
1283 column: 36
1284 }
1285 ]
1286 },
1287 {
1288 code: "function foo(bar) { return Number.parseInt(bar); } const Number = 1;",
1289 options: ["Number"],
1290 parserOptions: { ecmaVersion: 6, sourceType: "module" },
1291 errors: [
1292 {
1293 messageId: "blacklisted",
1294 data: { name: "Number" },
1295 type: "Identifier",
1296 column: 28
1297 },
1298 {
1299 messageId: "blacklisted",
1300 data: { name: "Number" },
1301 type: "Identifier",
1302 column: 58
1303 }
1304 ]
1305 },
1306 {
1307 code: "import Number from 'myNumber'; const foo = Number.parseInt(bar);",
1308 options: ["Number"],
1309 parserOptions: { ecmaVersion: 6, sourceType: "module" },
1310 errors: [
1311 {
1312 messageId: "blacklisted",
1313 data: { name: "Number" },
1314 type: "Identifier",
1315 column: 8
1316 },
1317 {
1318 messageId: "blacklisted",
1319 data: { name: "Number" },
1320 type: "Identifier",
1321 column: 44
1322 }
1323 ]
1324 },
1325 {
1326 code: "var foo = function undefined() {};",
1327 options: ["undefined"],
1328 errors: [
1329 {
1330 messageId: "blacklisted",
1331 data: { name: "undefined" },
1332 type: "Identifier"
1333 }
1334 ]
1335 },
1336
1337 // this is a reference to a global variable, but at the same time creates a property with a blacklisted name
1338 {
1339 code: "var foo = { undefined }",
1340 options: ["undefined"],
1341 parserOptions: { ecmaVersion: 6 },
1342 errors: [
1343 {
1344 messageId: "blacklisted",
1345 data: { name: "undefined" },
1346 type: "Identifier"
1347 }
1348 ]
1349 }
1350 ]
1351 });