@@ -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,22 @@ function componentRule(rule, context) {
562
561
return undefined ;
563
562
}
564
563
564
+ // case: { f() { return ... } }
565
+ if ( node . parent . type === 'Property' && node . parent . method && ! node . parent . computed ) {
566
+ if ( ! isFirstLetterCapitalized ( node . parent . key . name ) ) {
567
+ return undefined ;
568
+ }
569
+ return utils . isReturningJSX ( node ) ? node : undefined ;
570
+ }
571
+
572
+ // case: { f: () => ... }
573
+ if ( node . parent . type === 'Property' && ! node . id && ! node . parent . computed ) {
574
+ if ( ! isFirstLetterCapitalized ( node . parent . key . name ) ) {
575
+ return undefined ;
576
+ }
577
+ return utils . isReturningJSX ( node ) ? node : undefined ;
578
+ }
579
+
565
580
// Case like `React.memo(() => <></>)` or `React.forwardRef(...)`
566
581
const pragmaComponentWrapper = utils . getPragmaComponentWrapper ( node ) ;
567
582
if ( pragmaComponentWrapper && utils . isReturningJSXOrNull ( node ) ) {
@@ -576,10 +591,6 @@ function componentRule(rule, context) {
576
591
return undefined ;
577
592
}
578
593
579
- if ( isMethod && ! isFirstLetterCapitalized ( node . parent . key . name ) ) {
580
- return utils . isReturningJSX ( node ) ? node : undefined ;
581
- }
582
-
583
594
if ( node . id ) {
584
595
return isFirstLetterCapitalized ( node . id . name ) ? node : undefined ;
585
596
}
@@ -853,13 +864,8 @@ function componentRule(rule, context) {
853
864
return ;
854
865
}
855
866
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 ) ;
867
+ const component = utils . getStatelessComponent ( node ) ;
868
+ if ( ! component ) {
863
869
return ;
864
870
}
865
871
components . add ( component , 2 ) ;
@@ -871,7 +877,7 @@ function componentRule(rule, context) {
871
877
return ;
872
878
}
873
879
874
- node = utils . getParentComponent ( ) ;
880
+ node = utils . getStatelessComponent ( node ) ;
875
881
if ( ! node ) {
876
882
return ;
877
883
}
@@ -884,13 +890,8 @@ function componentRule(rule, context) {
884
890
return ;
885
891
}
886
892
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 ) ;
893
+ const component = utils . getStatelessComponent ( node ) ;
894
+ if ( ! component ) {
894
895
return ;
895
896
}
896
897
components . add ( component , 2 ) ;
0 commit comments