@@ -99,7 +99,7 @@ Components.prototype.length = function () {
99
99
return length ;
100
100
} ;
101
101
102
- function componentRule ( rule , context ) {
102
+ function componentRule ( rule , context , _node ) {
103
103
const sourceCode = context . getSourceCode ( ) ;
104
104
const components = new Components ( ) ;
105
105
@@ -165,11 +165,11 @@ function componentRule(rule, context) {
165
165
*
166
166
* @returns {ASTNode } component node, null if we are not in a component
167
167
*/
168
- getParentComponent : function ( ) {
168
+ getParentComponent : function ( _n ) {
169
169
return (
170
- utils . getParentES6Component ( )
171
- || utils . getParentES5Component ( )
172
- || utils . getParentStatelessComponent ( )
170
+ utils . getParentES6Component ( _n )
171
+ || utils . getParentES5Component ( _n )
172
+ || utils . getParentStatelessComponent ( _n )
173
173
) ;
174
174
} ,
175
175
@@ -178,9 +178,9 @@ function componentRule(rule, context) {
178
178
*
179
179
* @returns {ASTNode } component node, null if we are not in a component
180
180
*/
181
- getParentES5Component : function ( ) {
181
+ getParentES5Component : function ( _n ) {
182
182
// eslint-disable-next-line react/destructuring-assignment
183
- let scope = context . getScope ( ) ;
183
+ let scope = ( context . sourceCode || context ) . getScope ( _n ) ;
184
184
while ( scope ) {
185
185
const node = scope . block && scope . block . parent && scope . block . parent . parent ;
186
186
if ( node && utils . isES5Component ( node ) ) {
@@ -196,8 +196,8 @@ function componentRule(rule, context) {
196
196
*
197
197
* @returns {ASTNode } component node, null if we are not in a component
198
198
*/
199
- getParentES6Component : function ( ) {
200
- let scope = context . getScope ( ) ;
199
+ getParentES6Component : function ( _n ) {
200
+ let scope = ( context . sourceCode || context ) . getScope ( _n ) ;
201
201
while ( scope && scope . type !== 'class' ) {
202
202
scope = scope . upper ;
203
203
}
@@ -213,9 +213,9 @@ function componentRule(rule, context) {
213
213
*
214
214
* @returns {ASTNode } component node, null if we are not in a component
215
215
*/
216
- getParentStatelessComponent : function ( ) {
216
+ getParentStatelessComponent : function ( _n ) {
217
217
// eslint-disable-next-line react/destructuring-assignment
218
- let scope = context . getScope ( ) ;
218
+ let scope = ( context . sourceCode || context ) . getScope ( _n ) ;
219
219
while ( scope ) {
220
220
const node = scope . block ;
221
221
// Ignore non functions
@@ -263,7 +263,7 @@ function componentRule(rule, context) {
263
263
return null ;
264
264
}
265
265
let variableInScope ;
266
- const { variables } = context . getScope ( ) ;
266
+ const { variables } = ( context . sourceCode || context ) . getScope ( _node ) ;
267
267
for ( i = 0 , j = variables . length ; i < j ; i ++ ) { // eslint-disable-line no-plusplus
268
268
if ( variables [ i ] . name === variableName ) {
269
269
variableInScope = variables [ i ] ;
@@ -323,8 +323,8 @@ function componentRule(rule, context) {
323
323
components . add ( node , 2 ) ;
324
324
} ,
325
325
326
- ClassProperty : function ( ) {
327
- const node = utils . getParentComponent ( ) ;
326
+ ClassProperty : function ( _n ) {
327
+ const node = utils . getParentComponent ( _n ) ;
328
328
if ( ! node ) {
329
329
return ;
330
330
}
@@ -338,24 +338,24 @@ function componentRule(rule, context) {
338
338
components . add ( node , 2 ) ;
339
339
} ,
340
340
341
- FunctionExpression : function ( ) {
342
- const node = utils . getParentComponent ( ) ;
341
+ FunctionExpression : function ( _n ) {
342
+ const node = utils . getParentComponent ( _n ) ;
343
343
if ( ! node ) {
344
344
return ;
345
345
}
346
346
components . add ( node , 1 ) ;
347
347
} ,
348
348
349
- FunctionDeclaration : function ( ) {
350
- const node = utils . getParentComponent ( ) ;
349
+ FunctionDeclaration : function ( _n ) {
350
+ const node = utils . getParentComponent ( _n ) ;
351
351
if ( ! node ) {
352
352
return ;
353
353
}
354
354
components . add ( node , 1 ) ;
355
355
} ,
356
356
357
- ArrowFunctionExpression : function ( ) {
358
- const node = utils . getParentComponent ( ) ;
357
+ ArrowFunctionExpression : function ( _n ) {
358
+ const node = utils . getParentComponent ( _n ) ;
359
359
if ( ! node ) {
360
360
return ;
361
361
}
@@ -366,8 +366,8 @@ function componentRule(rule, context) {
366
366
}
367
367
} ,
368
368
369
- ThisExpression : function ( ) {
370
- const node = utils . getParentComponent ( ) ;
369
+ ThisExpression : function ( _n ) {
370
+ const node = utils . getParentComponent ( _n ) ;
371
371
if ( ! node || ! / F u n c t i o n / . test ( node . type ) ) {
372
372
return ;
373
373
}
@@ -379,7 +379,7 @@ function componentRule(rule, context) {
379
379
if ( ! utils . isReturningJSX ( node ) ) {
380
380
return ;
381
381
}
382
- const parentNode = utils . getParentComponent ( ) ;
382
+ const parentNode = utils . getParentComponent ( node ) ;
383
383
if ( ! parentNode ) {
384
384
return ;
385
385
}
0 commit comments