@@ -9,6 +9,7 @@ const has = require('has');
9
9
const Components = require ( '../util/Components' ) ;
10
10
const variableUtil = require ( '../util/variable' ) ;
11
11
const annotations = require ( '../util/annotations' ) ;
12
+ const astUtil = require ( '../util/ast' ) ;
12
13
13
14
// ------------------------------------------------------------------------------
14
15
// Rule Definition
@@ -38,27 +39,13 @@ module.exports = {
38
39
const allowRequiredDefaults = configuration . allowRequiredDefaults || false ;
39
40
const propWrapperFunctions = new Set ( context . settings . propWrapperFunctions || [ ] ) ;
40
41
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
-
55
42
/**
56
43
* Checks if the Identifier node passed in looks like a propTypes declaration.
57
44
* @param {ASTNode } node The node to check. Must be an Identifier node.
58
45
* @returns {Boolean } `true` if the node is a propTypes declaration, `false` if not
59
46
*/
60
47
function isPropTypesDeclaration ( node ) {
61
- return getPropertyName ( node ) === 'propTypes' ;
48
+ return astUtil . getPropertyName ( node ) === 'propTypes' ;
62
49
}
63
50
64
51
/**
@@ -67,7 +54,7 @@ module.exports = {
67
54
* @returns {Boolean } `true` if the node is a defaultProps declaration, `false` if not
68
55
*/
69
56
function isDefaultPropsDeclaration ( node ) {
70
- const propName = getPropertyName ( node ) ;
57
+ const propName = astUtil . getPropertyName ( node ) ;
71
58
return ( propName === 'defaultProps' || propName === 'getDefaultProps' ) ;
72
59
}
73
60
@@ -336,7 +323,7 @@ module.exports = {
336
323
}
337
324
338
325
function isPropTypeAnnotation ( node ) {
339
- return ( getPropertyName ( node ) === 'props' && ! ! node . typeAnnotation ) ;
326
+ return ( astUtil . getPropertyName ( node ) === 'props' && ! ! node . typeAnnotation ) ;
340
327
}
341
328
342
329
function propFromName ( propTypes , name ) {
@@ -528,7 +515,7 @@ module.exports = {
528
515
return ;
529
516
}
530
517
531
- const propName = getPropertyName ( node ) ;
518
+ const propName = astUtil . getPropertyName ( node ) ;
532
519
const isPropType = propName === 'propTypes' ;
533
520
const isDefaultProp = propName === 'defaultProps' || propName === 'getDefaultProps' ;
534
521
0 commit comments