]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-shadow.js
import 8.23.1 source
[pve-eslint.git] / eslint / tests / lib / rules / no-shadow.js
1 /**
2 * @fileoverview Tests for no-shadow rule.
3 * @author Ilya Volodin
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/no-shadow"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("no-shadow", rule, {
22 valid: [
23 "var a=3; function b(x) { a++; return x + a; }; setTimeout(function() { b(a); }, 0);",
24 "(function() { var doSomething = function doSomething() {}; doSomething() }())",
25 "var arguments;\nfunction bar() { }",
26 { code: "var a=3; var b = (x) => { a++; return x + a; }; setTimeout(() => { b(a); }, 0);", parserOptions: { ecmaVersion: 6 } },
27 { code: "class A {}", parserOptions: { ecmaVersion: 6 } },
28 { code: "class A { constructor() { var a; } }", parserOptions: { ecmaVersion: 6 } },
29 { code: "(function() { var A = class A {}; })()", parserOptions: { ecmaVersion: 6 } },
30 { code: "{ var a; } var a;", parserOptions: { ecmaVersion: 6 } }, // this case reports `no-redeclare`, not shadowing.
31 { code: "{ let a; } let a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
32 { code: "{ let a; } var a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
33 { code: "{ let a; } function a() {}", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
34 { code: "{ const a = 0; } const a = 1;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
35 { code: "{ const a = 0; } var a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
36 { code: "{ const a = 0; } function a() {}", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
37 { code: "function foo() { let a; } let a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
38 { code: "function foo() { let a; } var a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
39 { code: "function foo() { let a; } function a() {}", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
40 { code: "function foo() { var a; } let a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
41 { code: "function foo() { var a; } var a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
42 { code: "function foo() { var a; } function a() {}", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
43 { code: "function foo(a) { } let a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
44 { code: "function foo(a) { } var a;", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
45 { code: "function foo(a) { } function a() {}", options: [{ hoist: "never" }], parserOptions: { ecmaVersion: 6 } },
46 { code: "{ let a; } let a;", parserOptions: { ecmaVersion: 6 } },
47 { code: "{ let a; } var a;", parserOptions: { ecmaVersion: 6 } },
48 { code: "{ const a = 0; } const a = 1;", parserOptions: { ecmaVersion: 6 } },
49 { code: "{ const a = 0; } var a;", parserOptions: { ecmaVersion: 6 } },
50 { code: "function foo() { let a; } let a;", parserOptions: { ecmaVersion: 6 } },
51 { code: "function foo() { let a; } var a;", parserOptions: { ecmaVersion: 6 } },
52 { code: "function foo() { var a; } let a;", parserOptions: { ecmaVersion: 6 } },
53 { code: "function foo() { var a; } var a;", parserOptions: { ecmaVersion: 6 } },
54 { code: "function foo(a) { } let a;", parserOptions: { ecmaVersion: 6 } },
55 { code: "function foo(a) { } var a;", parserOptions: { ecmaVersion: 6 } },
56 "function foo() { var Object = 0; }",
57 { code: "function foo() { var top = 0; }", env: { browser: true } },
58 { code: "var Object = 0;", options: [{ builtinGlobals: true }] },
59 { code: "var top = 0;", options: [{ builtinGlobals: true }], env: { browser: true } },
60 { code: "function foo(cb) { (function (cb) { cb(42); })(cb); }", options: [{ allow: ["cb"] }] },
61 { code: "class C { foo; foo() { let foo; } }", parserOptions: { ecmaVersion: 2022 } },
62 { code: "class C { static { var x; } static { var x; } }", parserOptions: { ecmaVersion: 2022 } },
63 { code: "class C { static { let x; } static { let x; } }", parserOptions: { ecmaVersion: 2022 } },
64 { code: "class C { static { var x; { var x; /* redeclaration */ } } }", parserOptions: { ecmaVersion: 2022 } },
65 { code: "class C { static { { var x; } { var x; /* redeclaration */ } } }", parserOptions: { ecmaVersion: 2022 } },
66 { code: "class C { static { { let x; } { let x; } } }", parserOptions: { ecmaVersion: 2022 } },
67 { code: "const a = [].find(a => a)", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
68 { code: "const a = [].find(function(a) { return a; })", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
69 { code: "const [a = [].find(a => true)] = dummy", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
70 { code: "const { a = [].find(a => true) } = dummy", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
71 { code: "function func(a = [].find(a => true)) {}", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
72 { code: "for (const a in [].find(a => true)) {}", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
73 { code: "for (const a of [].find(a => true)) {}", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
74 { code: "const a = [].map(a => true).filter(a => a === 'b')", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
75 { code: "const a = [].map(a => true).filter(a => a === 'b').find(a => a === 'c')", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
76 { code: "const { a } = (({ a }) => ({ a }))();", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
77 { code: "const person = people.find(item => {const person = item.name; return person === 'foo'})", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
78 { code: "var y = bar || foo(y => y);", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
79 { code: "var y = bar && foo(y => y);", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
80 { code: "var z = bar(foo(z => z));", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
81 { code: "var z = boo(bar(foo(z => z)));", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
82 { code: "var match = function (person) { return person.name === 'foo'; };\nconst person = [].find(match);", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
83 { code: "const a = foo(x || (a => {}))", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
84 { code: "const { a = 1 } = foo(a => {})", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
85 { code: "const person = {...people.find((person) => person.firstName.startsWith('s'))}", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 2021 } },
86 { code: "const person = { firstName: people.filter((person) => person.firstName.startsWith('s')).map((person) => person.firstName)[0]}", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 2021 } },
87 { code: "() => { const y = foo(y => y); }", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
88 { code: "const x = (x => x)()", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
89 { code: "var y = bar || (y => y)();", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
90 { code: "var y = bar && (y => y)();", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
91 { code: "var x = (x => x)((y => y)());", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
92 { code: "const { a = 1 } = (a => {})()", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
93 { code: "() => { const y = (y => y)(); }", options: [{ ignoreOnInitialization: true }], parserOptions: { ecmaVersion: 6 } },
94 { code: "const [x = y => y] = [].map(y => y)", parserOptions: { ecmaVersion: 6 } }
95 ],
96 invalid: [
97 {
98 code: "function a(x) { var b = function c() { var x = 'foo'; }; }",
99 errors: [{
100 messageId: "noShadow",
101 data: {
102 name: "x",
103 shadowedLine: 1,
104 shadowedColumn: 12
105 },
106 type: "Identifier",
107 line: 1,
108 column: 44
109 }]
110 },
111 {
112 code: "var a = (x) => { var b = () => { var x = 'foo'; }; }",
113 parserOptions: { ecmaVersion: 6 },
114 errors: [{
115 messageId: "noShadow",
116 data: {
117 name: "x",
118 shadowedLine: 1,
119 shadowedColumn: 10
120 },
121 type: "Identifier",
122 line: 1,
123 column: 38
124 }]
125 },
126 {
127 code: "function a(x) { var b = function () { var x = 'foo'; }; }",
128 errors: [{
129 messageId: "noShadow",
130 data: {
131 name: "x",
132 shadowedLine: 1,
133 shadowedColumn: 12
134 },
135 type: "Identifier",
136 line: 1,
137 column: 43
138 }]
139 },
140 {
141 code: "var x = 1; function a(x) { return ++x; }",
142 errors: [{
143 messageId: "noShadow",
144 data: {
145 name: "x",
146 shadowedLine: 1,
147 shadowedColumn: 5
148 },
149 type: "Identifier",
150 line: 1,
151 column: 23
152 }]
153 },
154 {
155 code: "var a=3; function b() { var a=10; }",
156 errors: [{
157 messageId: "noShadow",
158 data: {
159 name: "a",
160 shadowedLine: 1,
161 shadowedColumn: 5
162 },
163 type: "Identifier"
164 }]
165 },
166 {
167 code: "var a=3; function b() { var a=10; }; setTimeout(function() { b(); }, 0);",
168 errors: [{
169 messageId: "noShadow",
170 data: {
171 name: "a",
172 shadowedLine: 1,
173 shadowedColumn: 5
174 },
175 type: "Identifier"
176 }]
177 },
178 {
179 code: "var a=3; function b() { var a=10; var b=0; }; setTimeout(function() { b(); }, 0);",
180 errors: [
181 {
182 messageId: "noShadow",
183 data: {
184 name: "a",
185 shadowedLine: 1,
186 shadowedColumn: 5
187 },
188 type: "Identifier"
189 }, {
190 messageId: "noShadow",
191 data: {
192 name: "b",
193 shadowedLine: 1,
194 shadowedColumn: 19
195 },
196 type: "Identifier"
197 }
198 ]
199 },
200 {
201 code: "var x = 1; { let x = 2; }",
202 parserOptions: { ecmaVersion: 6 },
203 errors: [{
204 messageId: "noShadow",
205 data: {
206 name: "x",
207 shadowedLine: 1,
208 shadowedColumn: 5
209 },
210 type: "Identifier"
211 }]
212 },
213 {
214 code: "let x = 1; { const x = 2; }",
215 parserOptions: { ecmaVersion: 6 },
216 errors: [{
217 messageId: "noShadow",
218 data: {
219 name: "x",
220 shadowedLine: 1,
221 shadowedColumn: 5
222 },
223 type: "Identifier"
224 }]
225 },
226 {
227 code: "{ let a; } function a() {}",
228 parserOptions: { ecmaVersion: 6 },
229 errors: [{
230 messageId: "noShadow",
231 data: {
232 name: "a",
233 shadowedLine: 1,
234 shadowedColumn: 21
235 },
236 type: "Identifier"
237 }]
238 },
239 {
240 code: "{ const a = 0; } function a() {}",
241 parserOptions: { ecmaVersion: 6 },
242 errors: [{
243 messageId: "noShadow",
244 data: {
245 name: "a",
246 shadowedLine: 1,
247 shadowedColumn: 27
248 },
249 type: "Identifier"
250 }]
251 },
252 {
253 code: "function foo() { let a; } function a() {}",
254 parserOptions: { ecmaVersion: 6 },
255 errors: [{
256 messageId: "noShadow",
257 data: {
258 name: "a",
259 shadowedLine: 1,
260 shadowedColumn: 36
261 },
262 type: "Identifier"
263 }]
264 },
265 {
266 code: "function foo() { var a; } function a() {}",
267 parserOptions: { ecmaVersion: 6 },
268 errors: [{
269 messageId: "noShadow",
270 data: {
271 name: "a",
272 shadowedLine: 1,
273 shadowedColumn: 36
274 },
275 type: "Identifier"
276 }]
277 },
278 {
279 code: "function foo(a) { } function a() {}",
280 parserOptions: { ecmaVersion: 6 },
281 errors: [{
282 messageId: "noShadow",
283 data: {
284 name: "a",
285 shadowedLine: 1,
286 shadowedColumn: 30
287 },
288 type: "Identifier"
289 }]
290 },
291 {
292 code: "{ let a; } let a;",
293 options: [{ hoist: "all" }],
294 parserOptions: { ecmaVersion: 6 },
295 errors: [{
296 messageId: "noShadow",
297 data: {
298 name: "a",
299 shadowedLine: 1,
300 shadowedColumn: 16
301 },
302 type: "Identifier"
303 }]
304 },
305 {
306 code: "{ let a; } var a;",
307 options: [{ hoist: "all" }],
308 parserOptions: { ecmaVersion: 6 },
309 errors: [{
310 messageId: "noShadow",
311 data: {
312 name: "a",
313 shadowedLine: 1,
314 shadowedColumn: 16
315 },
316 type: "Identifier"
317 }]
318 },
319 {
320 code: "{ let a; } function a() {}",
321 options: [{ hoist: "all" }],
322 parserOptions: { ecmaVersion: 6 },
323 errors: [{
324 messageId: "noShadow",
325 data: {
326 name: "a",
327 shadowedLine: 1,
328 shadowedColumn: 21
329 },
330 type: "Identifier"
331 }]
332 },
333 {
334 code: "{ const a = 0; } const a = 1;",
335 options: [{ hoist: "all" }],
336 parserOptions: { ecmaVersion: 6 },
337 errors: [{
338 messageId: "noShadow",
339 data: {
340 name: "a",
341 shadowedLine: 1,
342 shadowedColumn: 24
343 },
344 type: "Identifier"
345 }]
346 },
347 {
348 code: "{ const a = 0; } var a;",
349 options: [{ hoist: "all" }],
350 parserOptions: { ecmaVersion: 6 },
351 errors: [{
352 messageId: "noShadow",
353 data: {
354 name: "a",
355 shadowedLine: 1,
356 shadowedColumn: 22
357 },
358 type: "Identifier"
359 }]
360 },
361 {
362 code: "{ const a = 0; } function a() {}",
363 options: [{ hoist: "all" }],
364 parserOptions: { ecmaVersion: 6 },
365 errors: [{
366 messageId: "noShadow",
367 data: {
368 name: "a",
369 shadowedLine: 1,
370 shadowedColumn: 27
371 },
372 type: "Identifier"
373 }]
374 },
375 {
376 code: "function foo() { let a; } let a;",
377 options: [{ hoist: "all" }],
378 parserOptions: { ecmaVersion: 6 },
379 errors: [{
380 messageId: "noShadow",
381 data: {
382 name: "a",
383 shadowedLine: 1,
384 shadowedColumn: 31
385 },
386 type: "Identifier"
387 }]
388 },
389 {
390 code: "function foo() { let a; } var a;",
391 options: [{ hoist: "all" }],
392 parserOptions: { ecmaVersion: 6 },
393 errors: [{
394 messageId: "noShadow",
395 data: {
396 name: "a",
397 shadowedLine: 1,
398 shadowedColumn: 31
399 },
400 type: "Identifier"
401 }]
402 },
403 {
404 code: "function foo() { let a; } function a() {}",
405 options: [{ hoist: "all" }],
406 parserOptions: { ecmaVersion: 6 },
407 errors: [{
408 messageId: "noShadow",
409 data: {
410 name: "a",
411 shadowedLine: 1,
412 shadowedColumn: 36
413 },
414 type: "Identifier"
415 }]
416 },
417 {
418 code: "function foo() { var a; } let a;",
419 options: [{ hoist: "all" }],
420 parserOptions: { ecmaVersion: 6 },
421 errors: [{
422 messageId: "noShadow",
423 data: {
424 name: "a",
425 shadowedLine: 1,
426 shadowedColumn: 31
427 },
428 type: "Identifier"
429 }]
430 },
431 {
432 code: "function foo() { var a; } var a;",
433 options: [{ hoist: "all" }],
434 parserOptions: { ecmaVersion: 6 },
435 errors: [{
436 messageId: "noShadow",
437 data: {
438 name: "a",
439 shadowedLine: 1,
440 shadowedColumn: 31
441 },
442 type: "Identifier"
443 }]
444 },
445 {
446 code: "function foo() { var a; } function a() {}",
447 options: [{ hoist: "all" }],
448 parserOptions: { ecmaVersion: 6 },
449 errors: [{
450 messageId: "noShadow",
451 data: {
452 name: "a",
453 shadowedLine: 1,
454 shadowedColumn: 36
455 },
456 type: "Identifier"
457 }]
458 },
459 {
460 code: "function foo(a) { } let a;",
461 options: [{ hoist: "all" }],
462 parserOptions: { ecmaVersion: 6 },
463 errors: [{
464 messageId: "noShadow",
465 data: {
466 name: "a",
467 shadowedLine: 1,
468 shadowedColumn: 25
469 },
470 type: "Identifier"
471 }]
472 },
473 {
474 code: "function foo(a) { } var a;",
475 options: [{ hoist: "all" }],
476 parserOptions: { ecmaVersion: 6 },
477 errors: [{
478 messageId: "noShadow",
479 data: {
480 name: "a",
481 shadowedLine: 1,
482 shadowedColumn: 25
483 },
484 type: "Identifier"
485 }]
486 },
487 {
488 code: "function foo(a) { } function a() {}",
489 options: [{ hoist: "all" }],
490 parserOptions: { ecmaVersion: 6 },
491 errors: [{
492 messageId: "noShadow",
493 data: {
494 name: "a",
495 shadowedLine: 1,
496 shadowedColumn: 30
497 },
498 type: "Identifier"
499 }]
500 },
501 {
502 code: "(function a() { function a(){} })()",
503 errors: [{
504 messageId: "noShadow",
505 data: {
506 name: "a",
507 shadowedLine: 1,
508 shadowedColumn: 11
509 },
510 type: "Identifier"
511 }]
512 },
513 {
514 code: "(function a() { class a{} })()",
515 parserOptions: { ecmaVersion: 6 },
516 errors: [{
517 messageId: "noShadow",
518 data: {
519 name: "a",
520 shadowedLine: 1,
521 shadowedColumn: 11
522 },
523 type: "Identifier"
524 }]
525 },
526 {
527 code: "(function a() { (function a(){}); })()",
528 errors: [{
529 messageId: "noShadow",
530 data: {
531 name: "a",
532 shadowedLine: 1,
533 shadowedColumn: 11
534 },
535 type: "Identifier"
536 }]
537 },
538 {
539 code: "(function a() { (class a{}); })()",
540 parserOptions: { ecmaVersion: 6 },
541 errors: [{
542 messageId: "noShadow",
543 data: {
544 name: "a",
545 shadowedLine: 1,
546 shadowedColumn: 11
547 },
548 type: "Identifier"
549 }]
550 },
551 {
552 code: "(function() { var a = function(a) {}; })()",
553 errors: [{
554 messageId: "noShadow",
555 data: {
556 name: "a",
557 shadowedLine: 1,
558 shadowedColumn: 19
559 },
560 type: "Identifier"
561 }]
562 },
563 {
564 code: "(function() { var a = function() { function a() {} }; })()",
565 errors: [{
566 messageId: "noShadow",
567 data: {
568 name: "a",
569 shadowedLine: 1,
570 shadowedColumn: 19
571 },
572 type: "Identifier"
573 }]
574 },
575 {
576 code: "(function() { var a = function() { class a{} }; })()",
577 parserOptions: { ecmaVersion: 6 },
578 errors: [{
579 messageId: "noShadow",
580 data: {
581 name: "a",
582 shadowedLine: 1,
583 shadowedColumn: 19
584 },
585 type: "Identifier"
586 }]
587 },
588 {
589 code: "(function() { var a = function() { (function a() {}); }; })()",
590 errors: [{
591 messageId: "noShadow",
592 data: {
593 name: "a",
594 shadowedLine: 1,
595 shadowedColumn: 19
596 },
597 type: "Identifier"
598 }]
599 },
600 {
601 code: "(function() { var a = function() { (class a{}); }; })()",
602 parserOptions: { ecmaVersion: 6 },
603 errors: [{
604 messageId: "noShadow",
605 data: {
606 name: "a",
607 shadowedLine: 1,
608 shadowedColumn: 19
609 },
610 type: "Identifier"
611 }]
612 },
613 {
614 code: "(function() { var a = class { constructor() { class a {} } }; })()",
615 parserOptions: { ecmaVersion: 6 },
616 errors: [{
617 messageId: "noShadow",
618 data: {
619 name: "a",
620 shadowedLine: 1,
621 shadowedColumn: 19
622 },
623 type: "Identifier"
624 }]
625 },
626 {
627 code: "class A { constructor() { var A; } }",
628 parserOptions: { ecmaVersion: 6 },
629 errors: [{
630 messageId: "noShadow",
631 data: {
632 name: "A",
633 shadowedLine: 1,
634 shadowedColumn: 7
635 },
636 type: "Identifier"
637 }]
638 },
639 {
640 code: "(function a() { function a(){ function a(){} } })()",
641 errors: [
642 {
643 messageId: "noShadow",
644 data: {
645 name: "a",
646 shadowedLine: 1,
647 shadowedColumn: 11
648 },
649 type: "Identifier",
650 line: 1,
651 column: 26
652 },
653 {
654 messageId: "noShadow",
655 data: {
656 name: "a",
657 shadowedLine: 1,
658 shadowedColumn: 26
659 },
660 type: "Identifier",
661 line: 1,
662 column: 40
663 }
664 ]
665 },
666 {
667 code: "function foo() { var Object = 0; }",
668 options: [{ builtinGlobals: true }],
669 errors: [{
670 messageId: "noShadowGlobal",
671 data: {
672 name: "Object"
673 },
674 type: "Identifier"
675 }]
676 },
677 {
678 code: "function foo() { var top = 0; }",
679 options: [{ builtinGlobals: true }],
680 env: { browser: true },
681 errors: [{
682 messageId: "noShadowGlobal",
683 data: {
684 name: "top"
685 },
686 type: "Identifier"
687 }]
688 },
689 {
690 code: "var Object = 0;",
691 options: [{ builtinGlobals: true }],
692 parserOptions: { ecmaVersion: 6, sourceType: "module" },
693 errors: [{
694 messageId: "noShadowGlobal",
695 data: {
696 name: "Object"
697 },
698 type: "Identifier"
699 }]
700 },
701 {
702 code: "var top = 0;",
703 options: [{ builtinGlobals: true }],
704 parserOptions: { ecmaVersion: 6, sourceType: "module" },
705 env: { browser: true },
706 errors: [{
707 messageId: "noShadowGlobal",
708 data: {
709 name: "top"
710 },
711 type: "Identifier"
712 }]
713 },
714 {
715 code: "var Object = 0;",
716 options: [{ builtinGlobals: true }],
717 parserOptions: { ecmaFeatures: { globalReturn: true } },
718 errors: [{
719 messageId: "noShadowGlobal",
720 data: {
721 name: "Object"
722 },
723 type: "Identifier"
724 }]
725 },
726 {
727 code: "var top = 0;",
728 options: [{ builtinGlobals: true }],
729 parserOptions: { ecmaFeatures: { globalReturn: true } },
730 env: { browser: true },
731 errors: [{
732 messageId: "noShadowGlobal",
733 data: {
734 name: "top"
735 },
736 type: "Identifier"
737 }]
738 },
739 {
740 code: "function foo(cb) { (function (cb) { cb(42); })(cb); }",
741 errors: [{
742 messageId: "noShadow",
743 data: {
744 name: "cb",
745 shadowedLine: 1,
746 shadowedColumn: 14
747 },
748 type: "Identifier",
749 line: 1,
750 column: 31
751 }]
752 },
753 {
754 code: "class C { static { let a; { let a; } } }",
755 parserOptions: { ecmaVersion: 2022 },
756 errors: [{
757 messageId: "noShadow",
758 data: {
759 name: "a",
760 shadowedLine: 1,
761 shadowedColumn: 24
762 },
763 type: "Identifier",
764 line: 1,
765 column: 33
766 }]
767 },
768 {
769 code: "class C { static { var C; } }",
770 parserOptions: { ecmaVersion: 2022 },
771 errors: [{
772 messageId: "noShadow",
773 data: {
774 name: "C",
775 shadowedLine: 1,
776 shadowedColumn: 7
777 },
778 type: "Identifier",
779 line: 1,
780 column: 24
781 }]
782 },
783 {
784 code: "class C { static { let C; } }",
785 parserOptions: { ecmaVersion: 2022 },
786 errors: [{
787 messageId: "noShadow",
788 data: {
789 name: "C",
790 shadowedLine: 1,
791 shadowedColumn: 7
792 },
793 type: "Identifier",
794 line: 1,
795 column: 24
796 }]
797 },
798 {
799 code: "var a; class C { static { var a; } }",
800 parserOptions: { ecmaVersion: 2022 },
801 errors: [{
802 messageId: "noShadow",
803 data: {
804 name: "a",
805 shadowedLine: 1,
806 shadowedColumn: 5
807 },
808 type: "Identifier",
809 line: 1,
810 column: 31
811 }]
812 },
813 {
814 code: "class C { static { var a; } } var a;",
815 options: [{ hoist: "all" }],
816 parserOptions: { ecmaVersion: 2022 },
817 errors: [{
818 messageId: "noShadow",
819 data: {
820 name: "a",
821 shadowedLine: 1,
822 shadowedColumn: 35
823 },
824 type: "Identifier",
825 line: 1,
826 column: 24
827 }]
828 },
829 {
830 code: "class C { static { let a; } } let a;",
831 options: [{ hoist: "all" }],
832 parserOptions: { ecmaVersion: 2022 },
833 errors: [{
834 messageId: "noShadow",
835 data: {
836 name: "a",
837 shadowedLine: 1,
838 shadowedColumn: 35
839 },
840 type: "Identifier",
841 line: 1,
842 column: 24
843 }]
844 },
845 {
846 code: "class C { static { var a; } } let a;",
847 options: [{ hoist: "all" }],
848 parserOptions: { ecmaVersion: 2022 },
849 errors: [{
850 messageId: "noShadow",
851 data: {
852 name: "a",
853 shadowedLine: 1,
854 shadowedColumn: 35
855 },
856 type: "Identifier",
857 line: 1,
858 column: 24
859 }]
860 },
861 {
862 code: "class C { static { var a; class D { static { var a; } } } }",
863 parserOptions: { ecmaVersion: 2022 },
864 errors: [{
865 messageId: "noShadow",
866 data: {
867 name: "a",
868 shadowedLine: 1,
869 shadowedColumn: 24
870 },
871 type: "Identifier",
872 line: 1,
873 column: 50
874 }]
875 },
876 {
877 code: "class C { static { let a; class D { static { let a; } } } }",
878 parserOptions: { ecmaVersion: 2022 },
879 errors: [{
880 messageId: "noShadow",
881 data: {
882 name: "a",
883 shadowedLine: 1,
884 shadowedColumn: 24
885 },
886 type: "Identifier",
887 line: 1,
888 column: 50
889 }]
890 },
891 {
892 code: "let x = foo((x,y) => {});\nlet y;",
893 options: [{ hoist: "all" }],
894 parserOptions: { ecmaVersion: 6 },
895 errors: [
896 {
897 messageId: "noShadow",
898 data: {
899 name: "x",
900 shadowedLine: 1,
901 shadowedColumn: 5
902 },
903 type: "Identifier"
904 },
905 {
906 messageId: "noShadow",
907 data: {
908 name: "y",
909 shadowedLine: 2,
910 shadowedColumn: 5
911 },
912 type: "Identifier"
913 }
914 ]
915 },
916 {
917 code: "const a = fn(()=>{ class C { fn () { const a = 42; return a } } return new C() })",
918 options: [{ ignoreOnInitialization: true }],
919 parserOptions: { ecmaVersion: 6 },
920 errors: [{
921 messageId: "noShadow",
922 data: {
923 name: "a",
924 shadowedLine: 1,
925 shadowedColumn: 7
926 },
927 type: "Identifier",
928 line: 1,
929 column: 44
930 }]
931 },
932 {
933 code: "function a() {}\nfoo(a => {});",
934 options: [{ ignoreOnInitialization: true }],
935 parserOptions: { ecmaVersion: 6 },
936 errors: [{
937 messageId: "noShadow",
938 data: {
939 name: "a",
940 shadowedLine: 1,
941 shadowedColumn: 10
942 },
943 type: "Identifier",
944 line: 2,
945 column: 5
946 }]
947 },
948 {
949 code: "const a = fn(()=>{ function C() { this.fn=function() { const a = 42; return a } } return new C() });",
950 options: [{ ignoreOnInitialization: true }],
951 parserOptions: { ecmaVersion: 6 },
952 errors: [{
953 messageId: "noShadow",
954 data: {
955 name: "a",
956 shadowedLine: 1,
957 shadowedColumn: 7
958 },
959 type: "Identifier",
960 line: 1,
961 column: 62
962 }]
963 },
964 {
965 code: "const x = foo(() => { const bar = () => { return x => {}; }; return bar; });",
966 options: [{ ignoreOnInitialization: true }],
967 parserOptions: { ecmaVersion: 6 },
968 errors: [{
969 messageId: "noShadow",
970 data: {
971 name: "x",
972 shadowedLine: 1,
973 shadowedColumn: 7
974 },
975 type: "Identifier",
976 line: 1,
977 column: 50
978 }]
979 },
980 {
981 code: "const x = foo(() => { return { bar(x) {} }; });",
982 options: [{ ignoreOnInitialization: true }],
983 parserOptions: { ecmaVersion: 6 },
984 errors: [{
985 messageId: "noShadow",
986 data: {
987 name: "x",
988 shadowedLine: 1,
989 shadowedColumn: 7
990 },
991 type: "Identifier",
992 line: 1,
993 column: 36
994 }]
995 },
996 {
997 code: "const x = () => { foo(x => x); }",
998 options: [{ ignoreOnInitialization: true }],
999 parserOptions: { ecmaVersion: 6 },
1000 errors: [{
1001 messageId: "noShadow",
1002 data: {
1003 name: "x",
1004 shadowedLine: 1,
1005 shadowedColumn: 7
1006 },
1007 type: "Identifier",
1008 line: 1,
1009 column: 23
1010 }]
1011 },
1012 {
1013 code: "const foo = () => { let x; bar(x => x); }",
1014 options: [{ ignoreOnInitialization: true }],
1015 parserOptions: { ecmaVersion: 6 },
1016 errors: [{
1017 messageId: "noShadow",
1018 data: {
1019 name: "x",
1020 shadowedLine: 1,
1021 shadowedColumn: 25
1022 },
1023 type: "Identifier",
1024 line: 1,
1025 column: 32
1026 }]
1027 },
1028 {
1029 code: "foo(() => { const x = x => x; });",
1030 options: [{ ignoreOnInitialization: true }],
1031 parserOptions: { ecmaVersion: 6 },
1032 errors: [{
1033 messageId: "noShadow",
1034 data: {
1035 name: "x",
1036 shadowedLine: 1,
1037 shadowedColumn: 19
1038 },
1039 type: "Identifier",
1040 line: 1,
1041 column: 23
1042 }]
1043 },
1044 {
1045 code: "const foo = (x) => { bar(x => {}) }",
1046 options: [{ ignoreOnInitialization: true }],
1047 parserOptions: { ecmaVersion: 6 },
1048 errors: [{
1049 messageId: "noShadow",
1050 data: {
1051 name: "x",
1052 shadowedLine: 1,
1053 shadowedColumn: 14
1054 },
1055 type: "Identifier",
1056 line: 1,
1057 column: 26
1058 }]
1059 },
1060 {
1061 code: "let x = ((x,y) => {})();\nlet y;",
1062 options: [{ hoist: "all" }],
1063 parserOptions: { ecmaVersion: 6 },
1064 errors: [
1065 {
1066 messageId: "noShadow",
1067 data: {
1068 name: "x",
1069 shadowedLine: 1,
1070 shadowedColumn: 5
1071 },
1072 type: "Identifier"
1073 },
1074 {
1075 messageId: "noShadow",
1076 data: {
1077 name: "y",
1078 shadowedLine: 2,
1079 shadowedColumn: 5
1080 },
1081 type: "Identifier"
1082 }
1083 ]
1084 },
1085 {
1086 code: "const a = (()=>{ class C { fn () { const a = 42; return a } } return new C() })()",
1087 options: [{ ignoreOnInitialization: true }],
1088 parserOptions: { ecmaVersion: 6 },
1089 errors: [{
1090 messageId: "noShadow",
1091 data: {
1092 name: "a",
1093 shadowedLine: 1,
1094 shadowedColumn: 7
1095 },
1096 type: "Identifier",
1097 line: 1,
1098 column: 42
1099 }]
1100 },
1101 {
1102 code: "const x = () => { (x => x)(); }",
1103 options: [{ ignoreOnInitialization: true }],
1104 parserOptions: { ecmaVersion: 6 },
1105 errors: [{
1106 messageId: "noShadow",
1107 data: {
1108 name: "x",
1109 shadowedLine: 1,
1110 shadowedColumn: 7
1111 },
1112 type: "Identifier",
1113 line: 1,
1114 column: 20
1115 }]
1116 }
1117 ]
1118 });