@@ -26,7 +26,33 @@ eslintTester.addRuleTest("lib/rules/no-shadow", {
2626{ code :"var a=3; var b = (x) => { a++; return x + a; }; setTimeout(() => { b(a); }, 0);" , ecmaFeatures :{ arrowFunctions :true } } ,
2727{ code :"class A {}" , ecmaFeatures :{ classes :true } } ,
2828{ code :"class A { constructor() { var a; } }" , ecmaFeatures :{ classes :true } } ,
29- { code :"(function() { var A = class A {}; })()" , ecmaFeatures :{ classes :true } }
29+ { code :"(function() { var A = class A {}; })()" , ecmaFeatures :{ classes :true } } ,
30+ { code :"{ var a; } let a;" , ecmaFeatures :{ blockBindings :true } } , // this case reports `no-redeclare`, not shadowing.
31+ { code :"{ let a; } let a;" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
32+ { code :"{ let a; } var a;" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
33+ { code :"{ let a; } function a() {}" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
34+ { code :"{ const a = 0; } const a = 1;" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
35+ { code :"{ const a = 0; } var a;" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
36+ { code :"{ const a = 0; } function a() {}" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
37+ { code :"function foo() { let a; } let a;" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
38+ { code :"function foo() { let a; } var a;" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
39+ { code :"function foo() { let a; } function a() {}" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
40+ { code :"function foo() { var a; } let a;" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
41+ { code :"function foo() { var a; } var a;" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
42+ { code :"function foo() { var a; } function a() {}" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
43+ { code :"function foo(a) { } let a;" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
44+ { code :"function foo(a) { } var a;" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
45+ { code :"function foo(a) { } function a() {}" , options :[ { hoist :"never" } ] , ecmaFeatures :{ blockBindings :true } } ,
46+ { code :"{ let a; } let a;" , ecmaFeatures :{ blockBindings :true } } ,
47+ { code :"{ let a; } var a;" , ecmaFeatures :{ blockBindings :true } } ,
48+ { code :"{ const a = 0; } const a = 1;" , ecmaFeatures :{ blockBindings :true } } ,
49+ { code :"{ const a = 0; } var a;" , ecmaFeatures :{ blockBindings :true } } ,
50+ { code :"function foo() { let a; } let a;" , ecmaFeatures :{ blockBindings :true } } ,
51+ { code :"function foo() { let a; } var a;" , ecmaFeatures :{ blockBindings :true } } ,
52+ { code :"function foo() { var a; } let a;" , ecmaFeatures :{ blockBindings :true } } ,
53+ { code :"function foo() { var a; } var a;" , ecmaFeatures :{ blockBindings :true } } ,
54+ { code :"function foo(a) { } let a;" , ecmaFeatures :{ blockBindings :true } } ,
55+ { code :"function foo(a) { } var a;" , ecmaFeatures :{ blockBindings :true } }
3056] ,
3157invalid :[
3258{
@@ -90,6 +116,121 @@ eslintTester.addRuleTest("lib/rules/no-shadow", {
90116ecmaFeatures :{ blockBindings :true } ,
91117errors :[ { message :"x is already declared in the upper scope." , type :"Identifier" } ]
92118} ,
119+ {
120+ code :"{ let a; } function a() {}" ,
121+ ecmaFeatures :{ blockBindings :true } ,
122+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
123+ } ,
124+ {
125+ code :"{ const a = 0; } function a() {}" ,
126+ ecmaFeatures :{ blockBindings :true } ,
127+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
128+ } ,
129+ {
130+ code :"function foo() { let a; } function a() {}" ,
131+ ecmaFeatures :{ blockBindings :true } ,
132+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
133+ } ,
134+ {
135+ code :"function foo() { var a; } function a() {}" ,
136+ ecmaFeatures :{ blockBindings :true } ,
137+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
138+ } ,
139+ {
140+ code :"function foo(a) { } function a() {}" ,
141+ ecmaFeatures :{ blockBindings :true } ,
142+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
143+ } ,
144+ {
145+ code :"{ let a; } let a;" ,
146+ options :[ { hoist :"all" } ] ,
147+ ecmaFeatures :{ blockBindings :true } ,
148+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
149+ } ,
150+ {
151+ code :"{ let a; } var a;" ,
152+ options :[ { hoist :"all" } ] ,
153+ ecmaFeatures :{ blockBindings :true } ,
154+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
155+ } ,
156+ {
157+ code :"{ let a; } function a() {}" ,
158+ options :[ { hoist :"all" } ] ,
159+ ecmaFeatures :{ blockBindings :true } ,
160+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
161+ } ,
162+ {
163+ code :"{ const a = 0; } const a = 1;" ,
164+ options :[ { hoist :"all" } ] ,
165+ ecmaFeatures :{ blockBindings :true } ,
166+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
167+ } ,
168+ {
169+ code :"{ const a = 0; } var a;" ,
170+ options :[ { hoist :"all" } ] ,
171+ ecmaFeatures :{ blockBindings :true } ,
172+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
173+ } ,
174+ {
175+ code :"{ const a = 0; } function a() {}" ,
176+ options :[ { hoist :"all" } ] ,
177+ ecmaFeatures :{ blockBindings :true } ,
178+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
179+ } ,
180+ {
181+ code :"function foo() { let a; } let a;" ,
182+ options :[ { hoist :"all" } ] ,
183+ ecmaFeatures :{ blockBindings :true } ,
184+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
185+ } ,
186+ {
187+ code :"function foo() { let a; } var a;" ,
188+ options :[ { hoist :"all" } ] ,
189+ ecmaFeatures :{ blockBindings :true } ,
190+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
191+ } ,
192+ {
193+ code :"function foo() { let a; } function a() {}" ,
194+ options :[ { hoist :"all" } ] ,
195+ ecmaFeatures :{ blockBindings :true } ,
196+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
197+ } ,
198+ {
199+ code :"function foo() { var a; } let a;" ,
200+ options :[ { hoist :"all" } ] ,
201+ ecmaFeatures :{ blockBindings :true } ,
202+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
203+ } ,
204+ {
205+ code :"function foo() { var a; } var a;" ,
206+ options :[ { hoist :"all" } ] ,
207+ ecmaFeatures :{ blockBindings :true } ,
208+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
209+ } ,
210+ {
211+ code :"function foo() { var a; } function a() {}" ,
212+ options :[ { hoist :"all" } ] ,
213+ ecmaFeatures :{ blockBindings :true } ,
214+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
215+ } ,
216+ {
217+ code :"function foo(a) { } let a;" ,
218+ options :[ { hoist :"all" } ] ,
219+ ecmaFeatures :{ blockBindings :true } ,
220+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
221+ } ,
222+ {
223+ code :"function foo(a) { } var a;" ,
224+ options :[ { hoist :"all" } ] ,
225+ ecmaFeatures :{ blockBindings :true } ,
226+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
227+ } ,
228+ {
229+ code :"function foo(a) { } function a() {}" ,
230+ options :[ { hoist :"all" } ] ,
231+ ecmaFeatures :{ blockBindings :true } ,
232+ errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]
233+ } ,
93234{
94235code :"(function a() { function a(){} })()" ,
95236errors :[ { message :"a is already declared in the upper scope." , type :"Identifier" } ]