@@ -9,6 +9,7 @@ const has = require('has');
99const Components = require ( '../util/Components' ) ;
1010const variableUtil = require ( '../util/variable' ) ;
1111const annotations = require ( '../util/annotations' ) ;
12+ const astUtil = require ( '../util/ast' ) ;
1213
1314// ------------------------------------------------------------------------------
1415// Rule Definition
@@ -38,27 +39,13 @@ module.exports = {
3839 const allowRequiredDefaults = configuration . allowRequiredDefaults || false ;
3940 const propWrapperFunctions = new Set ( context . settings . propWrapperFunctions || [ ] ) ;
4041
41- /**
42- * Get properties name
43- * @param {Object } node - Property.
44- * @returns {String } Property name.
45- */
46- function getPropertyName ( node ) {
47- if ( node . key || [ 'MethodDefinition' , 'Property' ] . indexOf ( node . type ) !== - 1 ) {
48- return node . key . name ;
49- } else if ( node . type === 'MemberExpression' ) {
50- return node . property . name ;
51- }
52- return '' ;
53- }
54-
5542 /**
5643 * Checks if the Identifier node passed in looks like a propTypes declaration.
5744 * @param {ASTNode } node The node to check. Must be an Identifier node.
5845 * @returns {Boolean } `true` if the node is a propTypes declaration, `false` if not
5946 */
6047 function isPropTypesDeclaration ( node ) {
61- return getPropertyName ( node ) === 'propTypes' ;
48+ return astUtil . getPropertyName ( node ) === 'propTypes' ;
6249 }
6350
6451 /**
@@ -67,7 +54,7 @@ module.exports = {
6754 * @returns {Boolean } `true` if the node is a defaultProps declaration, `false` if not
6855 */
6956 function isDefaultPropsDeclaration ( node ) {
70- const propName = getPropertyName ( node ) ;
57+ const propName = astUtil . getPropertyName ( node ) ;
7158 return ( propName === 'defaultProps' || propName === 'getDefaultProps' ) ;
7259 }
7360
@@ -336,7 +323,7 @@ module.exports = {
336323 }
337324
338325 function isPropTypeAnnotation ( node ) {
339- return ( getPropertyName ( node ) === 'props' && ! ! node . typeAnnotation ) ;
326+ return ( astUtil . getPropertyName ( node ) === 'props' && ! ! node . typeAnnotation ) ;
340327 }
341328
342329 function propFromName ( propTypes , name ) {
@@ -528,7 +515,7 @@ module.exports = {
528515 return ;
529516 }
530517
531- const propName = getPropertyName ( node ) ;
518+ const propName = astUtil . getPropertyName ( node ) ;
532519 const isPropType = propName === 'propTypes' ;
533520 const isDefaultProp = propName === 'defaultProps' || propName === 'getDefaultProps' ;
534521
0 commit comments