@@ -108,7 +108,7 @@ function componentRule(rule, context) {
108108 var components = new Components ( ) ;
109109
110110 // Utilities for component detection
111- context . react = {
111+ var utils = {
112112
113113 /**
114114 * Check if the node is a React ES5 component
@@ -176,9 +176,9 @@ function componentRule(rule, context) {
176176 */
177177 getParentComponent : function ( ) {
178178 return (
179- context . react . getParentES6Component ( ) ||
180- context . react . getParentES5Component ( ) ||
181- context . react . getParentStatelessComponent ( )
179+ utils . getParentES6Component ( ) ||
180+ utils . getParentES5Component ( ) ||
181+ utils . getParentStatelessComponent ( )
182182 ) ;
183183 } ,
184184
@@ -191,7 +191,7 @@ function componentRule(rule, context) {
191191 var scope = context . getScope ( ) ;
192192 while ( scope ) {
193193 var node = scope . block && scope . block . parent && scope . block . parent . parent ;
194- if ( node && context . react . isES5Component ( node ) ) {
194+ if ( node && utils . isES5Component ( node ) ) {
195195 return node ;
196196 }
197197 scope = scope . upper ;
@@ -210,7 +210,7 @@ function componentRule(rule, context) {
210210 scope = scope . upper ;
211211 }
212212 var node = scope && scope . block ;
213- if ( ! node || ! context . react . isES6Component ( node ) ) {
213+ if ( ! node || ! utils . isES6Component ( node ) ) {
214214 return null ;
215215 }
216216 return node ;
@@ -316,57 +316,57 @@ function componentRule(rule, context) {
316316 // Component detection instructions
317317 var detectionInstructions = {
318318 ClassDeclaration : function ( node ) {
319- if ( ! context . react . isES6Component ( node ) ) {
319+ if ( ! utils . isES6Component ( node ) ) {
320320 return ;
321321 }
322322 components . add ( node , 2 ) ;
323323 } ,
324324
325325 ClassProperty : function ( node ) {
326- node = context . react . getParentComponent ( ) ;
326+ node = utils . getParentComponent ( ) ;
327327 if ( ! node ) {
328328 return ;
329329 }
330330 components . add ( node , 2 ) ;
331331 } ,
332332
333333 ObjectExpression : function ( node ) {
334- if ( ! context . react . isES5Component ( node ) ) {
334+ if ( ! utils . isES5Component ( node ) ) {
335335 return ;
336336 }
337337 components . add ( node , 2 ) ;
338338 } ,
339339
340340 FunctionExpression : function ( node ) {
341- node = context . react . getParentComponent ( ) ;
341+ node = utils . getParentComponent ( ) ;
342342 if ( ! node ) {
343343 return ;
344344 }
345345 components . add ( node , 1 ) ;
346346 } ,
347347
348348 FunctionDeclaration : function ( node ) {
349- node = context . react . getParentComponent ( ) ;
349+ node = utils . getParentComponent ( ) ;
350350 if ( ! node ) {
351351 return ;
352352 }
353353 components . add ( node , 1 ) ;
354354 } ,
355355
356356 ArrowFunctionExpression : function ( node ) {
357- node = context . react . getParentComponent ( ) ;
357+ node = utils . getParentComponent ( ) ;
358358 if ( ! node ) {
359359 return ;
360360 }
361- if ( node . expression && context . react . isReturningJSX ( node ) ) {
361+ if ( node . expression && utils . isReturningJSX ( node ) ) {
362362 components . add ( node , 2 ) ;
363363 } else {
364364 components . add ( node , 1 ) ;
365365 }
366366 } ,
367367
368368 ThisExpression : function ( node ) {
369- node = context . react . getParentComponent ( ) ;
369+ node = utils . getParentComponent ( ) ;
370370 if ( ! node || ! / F u n c t i o n / . test ( node . type ) ) {
371371 return ;
372372 }
@@ -375,10 +375,10 @@ function componentRule(rule, context) {
375375 } ,
376376
377377 ReturnStatement : function ( node ) {
378- if ( ! context . react . isReturningJSX ( node ) ) {
378+ if ( ! utils . isReturningJSX ( node ) ) {
379379 return ;
380380 }
381- node = context . react . getParentComponent ( ) ;
381+ node = utils . getParentComponent ( ) ;
382382 if ( ! node ) {
383383 return ;
384384 }
@@ -387,7 +387,7 @@ function componentRule(rule, context) {
387387 } ;
388388
389389 // Update the provided rule instructions to add the component detection
390- var ruleInstructions = rule ( context , components ) ;
390+ var ruleInstructions = rule ( context , components , utils ) ;
391391 var updatedRuleInstructions = util . _extend ( { } , ruleInstructions ) ;
392392 Object . keys ( detectionInstructions ) . forEach ( function ( instruction ) {
393393 updatedRuleInstructions [ instruction ] = function ( node ) {
0 commit comments