@@ -109,7 +109,7 @@ class Components {
109
109
set ( node , props ) {
110
110
const list = Lists . get ( this ) ;
111
111
let component = list [ getId ( node ) ] ;
112
- while ( ! component ) {
112
+ while ( ! component || component . confidence < 1 ) {
113
113
node = node . parent ;
114
114
if ( ! node ) {
115
115
return ;
@@ -477,7 +477,6 @@ function componentRule(rule, context) {
477
477
}
478
478
479
479
if ( node . type === 'FunctionExpression' || node . type === 'ArrowFunctionExpression' ) {
480
- const isMethod = parent . type === 'Property' && parent . method ;
481
480
const isPropertyAssignment = parent . type === 'AssignmentExpression'
482
481
&& parent . left . type === 'MemberExpression' ;
483
482
const isModuleExportsAssignment = isPropertyAssignment
@@ -562,6 +561,18 @@ function componentRule(rule, context) {
562
561
return undefined ;
563
562
}
564
563
564
+ if (
565
+ node . parent . type === 'Property' && (
566
+ ( node . parent . method && ! node . parent . computed ) // case: { f() { return ... } }
567
+ || ( ! node . id && ! node . parent . computed ) // case: { f: () => ... }
568
+ )
569
+ ) {
570
+ if ( isFirstLetterCapitalized ( node . parent . key . name ) && utils . isReturningJSX ( node ) ) {
571
+ return node ;
572
+ }
573
+ return undefined ;
574
+ }
575
+
565
576
// Case like `React.memo(() => <></>)` or `React.forwardRef(...)`
566
577
const pragmaComponentWrapper = utils . getPragmaComponentWrapper ( node ) ;
567
578
if ( pragmaComponentWrapper && utils . isReturningJSXOrNull ( node ) ) {
@@ -576,10 +587,6 @@ function componentRule(rule, context) {
576
587
return undefined ;
577
588
}
578
589
579
- if ( isMethod && ! isFirstLetterCapitalized ( node . parent . key . name ) ) {
580
- return utils . isReturningJSX ( node ) ? node : undefined ;
581
- }
582
-
583
590
if ( node . id ) {
584
591
return isFirstLetterCapitalized ( node . id . name ) ? node : undefined ;
585
592
}
@@ -853,13 +860,8 @@ function componentRule(rule, context) {
853
860
return ;
854
861
}
855
862
856
- const component = utils . getParentComponent ( ) ;
857
- if (
858
- ! component
859
- || ( component . parent && component . parent . type === 'JSXExpressionContainer' )
860
- ) {
861
- // Ban the node if we cannot find a parent component
862
- components . add ( node , 0 ) ;
863
+ const component = utils . getStatelessComponent ( node ) ;
864
+ if ( ! component ) {
863
865
return ;
864
866
}
865
867
components . add ( component , 2 ) ;
@@ -871,7 +873,7 @@ function componentRule(rule, context) {
871
873
return ;
872
874
}
873
875
874
- node = utils . getParentComponent ( ) ;
876
+ node = utils . getStatelessComponent ( node ) ;
875
877
if ( ! node ) {
876
878
return ;
877
879
}
@@ -884,13 +886,8 @@ function componentRule(rule, context) {
884
886
return ;
885
887
}
886
888
887
- const component = utils . getParentComponent ( ) ;
888
- if (
889
- ! component
890
- || ( component . parent && component . parent . type === 'JSXExpressionContainer' )
891
- ) {
892
- // Ban the node if we cannot find a parent component
893
- components . add ( node , 0 ) ;
889
+ const component = utils . getStatelessComponent ( node ) ;
890
+ if ( ! component ) {
894
891
return ;
895
892
}
896
893
components . add ( component , 2 ) ;
0 commit comments