@@ -47,36 +47,6 @@ function mergeUsedPropTypes(propsList, newPropsList) {
47
47
return propsList . concat ( propsToAdd ) ;
48
48
}
49
49
50
- function isReturnsConditionalJSX ( node , property , strict ) {
51
- const returnsConditionalJSXConsequent = node [ property ]
52
- && node [ property ] . type === 'ConditionalExpression'
53
- && jsxUtil . isJSX ( node [ property ] . consequent ) ;
54
- const returnsConditionalJSXAlternate = node [ property ]
55
- && node [ property ] . type === 'ConditionalExpression'
56
- && jsxUtil . isJSX ( node [ property ] . alternate ) ;
57
- return strict
58
- ? ( returnsConditionalJSXConsequent && returnsConditionalJSXAlternate )
59
- : ( returnsConditionalJSXConsequent || returnsConditionalJSXAlternate ) ;
60
- }
61
-
62
- function isReturnsLogicalJSX ( node , property , strict ) {
63
- const returnsLogicalJSXLeft = node [ property ]
64
- && node [ property ] . type === 'LogicalExpression'
65
- && jsxUtil . isJSX ( node [ property ] . left ) ;
66
- const returnsLogicalJSXRight = node [ property ]
67
- && node [ property ] . type === 'LogicalExpression'
68
- && jsxUtil . isJSX ( node [ property ] . right ) ;
69
- return strict
70
- ? ( returnsLogicalJSXLeft && returnsLogicalJSXRight )
71
- : ( returnsLogicalJSXLeft || returnsLogicalJSXRight ) ;
72
- }
73
-
74
- function isReturnsSequentialJSX ( node , property ) {
75
- return node [ property ]
76
- && node [ property ] . type === 'SequenceExpression'
77
- && jsxUtil . isJSX ( node [ property ] . expressions [ node [ property ] . expressions . length - 1 ] ) ;
78
- }
79
-
80
50
const Lists = new WeakMap ( ) ;
81
51
82
52
/**
@@ -466,65 +436,12 @@ function componentRule(rule, context) {
466
436
} ;
467
437
} ,
468
438
469
- /**
470
- * Check if the node is returning JSX
471
- *
472
- * @param {ASTNode } ASTnode The AST node being checked
473
- * @param {Boolean } [strict] If true, in a ternary condition the node must return JSX in both cases
474
- * @returns {Boolean } True if the node is returning JSX, false if not
475
- */
476
- isReturningJSX ( ASTnode , strict ) {
477
- const nodeAndProperty = utils . getReturnPropertyAndNode ( ASTnode ) ;
478
- const node = nodeAndProperty . node ;
479
- const property = nodeAndProperty . property ;
480
-
481
- if ( ! node ) {
482
- return false ;
483
- }
484
-
485
- const returnsConditionalJSX = isReturnsConditionalJSX ( node , property , strict ) ;
486
- const returnsLogicalJSX = isReturnsLogicalJSX ( node , property , strict ) ;
487
- const returnsSequentialJSX = isReturnsSequentialJSX ( node , property ) ;
488
-
489
- const returnsJSX = node [ property ] && jsxUtil . isJSX ( node [ property ] ) ;
490
- const returnsPragmaCreateElement = this . isCreateElement ( node [ property ] ) ;
491
-
492
- return ! ! (
493
- returnsConditionalJSX
494
- || returnsLogicalJSX
495
- || returnsSequentialJSX
496
- || returnsJSX
497
- || returnsPragmaCreateElement
498
- ) ;
439
+ isReturningJSX ( ASTNode , strict ) {
440
+ return jsxUtil . isReturningJSX ( this . isCreateElement . bind ( this ) , ASTNode , strict , true ) ;
499
441
} ,
500
442
501
- /**
502
- * Check if the node is returning null
503
- *
504
- * @param {ASTNode } ASTnode The AST node being checked
505
- * @returns {Boolean } True if the node is returning null, false if not
506
- */
507
- isReturningNull ( ASTnode ) {
508
- const nodeAndProperty = utils . getReturnPropertyAndNode ( ASTnode ) ;
509
- const property = nodeAndProperty . property ;
510
- const node = nodeAndProperty . node ;
511
-
512
- if ( ! node ) {
513
- return false ;
514
- }
515
-
516
- return node [ property ] && node [ property ] . value === null ;
517
- } ,
518
-
519
- /**
520
- * Check if the node is returning JSX or null
521
- *
522
- * @param {ASTNode } ASTNode The AST node being checked
523
- * @param {Boolean } [strict] If true, in a ternary condition the node must return JSX in both cases
524
- * @returns {Boolean } True if the node is returning JSX or null, false if not
525
- */
526
443
isReturningJSXOrNull ( ASTNode , strict ) {
527
- return utils . isReturningJSX ( ASTNode , strict ) || utils . isReturningNull ( ASTNode ) ;
444
+ return jsxUtil . isReturningJSX ( this . isCreateElement . bind ( this ) , ASTNode , strict ) ;
528
445
} ,
529
446
530
447
getPragmaComponentWrapper ( node ) {
@@ -734,9 +651,20 @@ function componentRule(rule, context) {
734
651
return undefined ;
735
652
}
736
653
if ( utils . isInAllowedPositionForComponent ( node ) && utils . isReturningJSXOrNull ( node ) ) {
737
- if ( ! node . id || isFirstLetterCapitalized ( node . id . name ) ) {
654
+ const isMethod = node . parent . type === 'Property' && node . parent . method ;
655
+
656
+ if ( isMethod && ! isFirstLetterCapitalized ( node . parent . key . name ) ) {
657
+ return utils . isReturningJSX ( node ) ? node : undefined ;
658
+ }
659
+
660
+ if ( node . id && isFirstLetterCapitalized ( node . id . name ) ) {
738
661
return node ;
739
662
}
663
+
664
+ if ( ! node . id ) {
665
+ return node ;
666
+ }
667
+
740
668
return undefined ;
741
669
}
742
670
0 commit comments