@@ -35,19 +35,15 @@ module.exports = {
3535 }
3636
3737 /**
38- * Check if a given AST node has a render method
39- * @param {ASTNode } node The AST node being checked .
40- * @returns {Boolean } True if there is a render method, false if not
38+ * Find render method in a given AST node
39+ * @param {ASTNode } node The component to find render method .
40+ * @returns {ASTNode } Method node if found, undefined if not.
4141 */
42- function hasRenderMethod ( node ) {
42+ function findRenderMethod ( node ) {
4343 const properties = astUtil . getComponentProperties ( node ) ;
44- for ( let i = 0 , j = properties . length ; i < j ; i ++ ) {
45- if ( astUtil . getPropertyName ( properties [ i ] ) !== 'render' || ! properties [ i ] . value ) {
46- continue ;
47- }
48- return astUtil . isFunctionLikeExpression ( properties [ i ] . value ) ;
49- }
50- return false ;
44+ return properties
45+ . filter ( property => astUtil . getPropertyName ( property ) === 'render' && property . value )
46+ . find ( property => astUtil . isFunctionLikeExpression ( property . value ) ) ;
5147 }
5248
5349 return {
@@ -80,14 +76,14 @@ module.exports = {
8076 const list = components . list ( ) ;
8177 Object . keys ( list ) . forEach ( component => {
8278 if (
83- ! hasRenderMethod ( list [ component ] . node ) ||
79+ ! findRenderMethod ( list [ component ] . node ) ||
8480 list [ component ] . hasReturnStatement ||
8581 ( ! utils . isES5Component ( list [ component ] . node ) && ! utils . isES6Component ( list [ component ] . node ) )
8682 ) {
8783 return ;
8884 }
8985 context . report ( {
90- node : list [ component ] . node ,
86+ node : findRenderMethod ( list [ component ] . node ) ,
9187 message : 'Your render method should have return statement'
9288 } ) ;
9389 } ) ;
0 commit comments