@@ -70,10 +70,9 @@ module.exports = {
70
70
// Used to track the type annotations in scope.
71
71
// Necessary because babel's scopes do not track type annotations.
72
72
const classExpressions = [ ] ;
73
- const defaults = { skipShapeProps : true , customValidators : [ ] } ;
73
+ const defaults = { customValidators : [ ] } ;
74
74
const configuration = Object . assign ( { } , defaults , context . options [ 0 ] || { } ) ;
75
75
const customValidators = configuration . customValidators ;
76
- const skipShapeProps = configuration . skipShapeProps ;
77
76
const sourceCode = context . getSourceCode ( ) ;
78
77
const propWrapperFunctions = new Set ( context . settings . propWrapperFunctions || [ ] ) ;
79
78
@@ -149,9 +148,6 @@ module.exports = {
149
148
}
150
149
return { } ;
151
150
case 'ObjectTypeAnnotation' :
152
- if ( skipShapeProps ) {
153
- return { } ;
154
- }
155
151
let containsObjectTypeSpread = false ;
156
152
const shapeTypeDefinition = {
157
153
type : 'shape' ,
@@ -183,13 +179,14 @@ module.exports = {
183
179
for ( let i = 0 , j = annotation . types . length ; i < j ; i ++ ) {
184
180
const type = buildTypeAnnotationDeclarationTypes ( annotation . types [ i ] , parentName , seen ) ;
185
181
// keep only complex type
186
- if ( Object . keys ( type ) . length > 0 ) {
182
+ if ( type . type ) {
187
183
if ( type . children === true ) {
188
184
// every child is accepted for one type, abort type analysis
189
185
unionTypeDefinition . children = true ;
190
186
return unionTypeDefinition ;
191
187
}
192
188
}
189
+ // type.node = annotation.types[i];
193
190
194
191
unionTypeDefinition . children . push ( type ) ;
195
192
}
@@ -200,10 +197,14 @@ module.exports = {
200
197
return unionTypeDefinition ;
201
198
case 'ArrayTypeAnnotation' :
202
199
const fullName = [ parentName , '*' ] . join ( '.' ) ;
200
+ const child = buildTypeAnnotationDeclarationTypes ( annotation . elementType , fullName , seen ) ;
201
+ child . fullName = fullName ;
202
+ child . name = '__ANY_KEY__' ;
203
+ child . node = annotation ;
203
204
return {
204
205
type : 'object' ,
205
206
children : {
206
- __ANY_KEY__ : buildTypeAnnotationDeclarationTypes ( annotation . elementType , fullName , seen )
207
+ __ANY_KEY__ : child
207
208
}
208
209
} ;
209
210
default :
@@ -316,10 +317,6 @@ module.exports = {
316
317
const argument = value . arguments [ 0 ] ;
317
318
switch ( callName ) {
318
319
case 'shape' :
319
- if ( skipShapeProps ) {
320
- return { } ;
321
- }
322
-
323
320
if ( argument . type !== 'ObjectExpression' ) {
324
321
// Invalid proptype or cannot analyse statically
325
322
return { } ;
@@ -365,7 +362,7 @@ module.exports = {
365
362
for ( let i = 0 , j = argument . elements . length ; i < j ; i ++ ) {
366
363
const type = buildReactDeclarationTypes ( argument . elements [ i ] , parentName ) ;
367
364
// keep only complex type
368
- if ( Object . keys ( type ) . length > 0 ) {
365
+ if ( type . type ) {
369
366
if ( type . children === true ) {
370
367
// every child is accepted for one type, abort type analysis
371
368
unionTypeDefinition . children = true ;
@@ -417,6 +414,7 @@ module.exports = {
417
414
case 'ObjectExpression' :
418
415
iterateProperties ( context , propTypes . properties , ( key , value ) => {
419
416
if ( ! value ) {
417
+ /* eslint-disable */
420
418
ignorePropsValidation = true ;
421
419
return ;
422
420
}
@@ -453,12 +451,27 @@ module.exports = {
453
451
propTypes . parent . right ,
454
452
propTypes . parent . left . object . property . name
455
453
) ;
454
+
456
455
types . name = propTypes . property . name ;
457
- types . node = propTypes . property ;
458
456
types . fullName = propTypes . property . name ;
457
+ types . node = propTypes . property ;
459
458
curDeclaredPropTypes [ propTypes . property . name ] = types ;
460
459
} else {
461
- ignorePropsValidation = true ;
460
+ let isUsedInPropTypes = false ;
461
+ let n = propTypes ;
462
+ while ( n ) {
463
+ if ( n . type === 'AssignmentExpression' && propsUtil . isPropTypesDeclaration ( n . left ) ||
464
+ ( n . type === 'ClassProperty' || n . type === 'Property' ) && propsUtil . isPropTypesDeclaration ( n ) ) {
465
+ // Found a propType used inside of another propType. This is not considered usage, we'll still validate
466
+ // this component.
467
+ isUsedInPropTypes = true ;
468
+ break ;
469
+ }
470
+ n = n . parent ;
471
+ }
472
+ if ( ! isUsedInPropTypes ) {
473
+ ignorePropsValidation = true ;
474
+ }
462
475
}
463
476
break ;
464
477
case 'Identifier' :
0 commit comments