@@ -86,7 +86,7 @@ module.exports = {
86
86
if ( node . type === 'ExperimentalSpreadProperty' || node . type === 'SpreadElement' ) {
87
87
return null ;
88
88
}
89
- if ( node . value . property ) {
89
+ if ( node . value && node . value . property ) {
90
90
const name = node . value . property . name ;
91
91
if ( name === 'isRequired' ) {
92
92
if ( node . value . object && node . value . object . property ) {
@@ -96,7 +96,7 @@ module.exports = {
96
96
}
97
97
return name ;
98
98
}
99
- if ( node . value . type === 'Identifier' ) {
99
+ if ( node . value && node . value . type === 'Identifier' ) {
100
100
return node . value . name ;
101
101
}
102
102
return null ;
@@ -145,6 +145,16 @@ module.exports = {
145
145
) ;
146
146
}
147
147
148
+ function tsCheck ( prop ) {
149
+ if ( prop . type !== 'TSPropertySignature' ) return false ;
150
+ const typeAnnotation = ( prop . typeAnnotation || { } ) . typeAnnotation ;
151
+ return (
152
+ typeAnnotation
153
+ && typeAnnotation . type === 'TSBooleanKeyword'
154
+ && rule . test ( getPropName ( prop ) ) === false
155
+ ) ;
156
+ }
157
+
148
158
/**
149
159
* Checks if prop is nested
150
160
* @param {Object } prop Property object, single prop type declaration
@@ -170,7 +180,7 @@ module.exports = {
170
180
runCheck ( prop . value . arguments [ 0 ] . properties , addInvalidProp ) ;
171
181
return ;
172
182
}
173
- if ( flowCheck ( prop ) || regularCheck ( prop ) ) {
183
+ if ( flowCheck ( prop ) || regularCheck ( prop ) || tsCheck ( prop ) ) {
174
184
addInvalidProp ( prop ) ;
175
185
}
176
186
} ) ;
@@ -289,6 +299,12 @@ module.exports = {
289
299
}
290
300
} ,
291
301
302
+ TSTypeAliasDeclaration ( node ) {
303
+ if ( node . typeAnnotation . type === 'TSTypeLiteral' ) {
304
+ objectTypeAnnotations . set ( node . id . name , node . typeAnnotation ) ;
305
+ }
306
+ } ,
307
+
292
308
// eslint-disable-next-line object-shorthand
293
309
'Program:exit' ( ) {
294
310
if ( ! rule ) {
@@ -299,22 +315,30 @@ module.exports = {
299
315
Object . keys ( list ) . forEach ( ( component ) => {
300
316
// If this is a functional component that uses a global type, check it
301
317
if (
302
- list [ component ] . node . type === 'FunctionDeclaration'
318
+ (
319
+ list [ component ] . node . type === 'FunctionDeclaration'
320
+ || list [ component ] . node . type === 'ArrowFunctionExpression'
321
+ )
303
322
&& list [ component ] . node . params
304
323
&& list [ component ] . node . params . length
305
324
&& list [ component ] . node . params [ 0 ] . typeAnnotation
306
325
) {
307
326
const typeNode = list [ component ] . node . params [ 0 ] . typeAnnotation ;
308
327
const annotation = typeNode . typeAnnotation ;
309
-
310
328
let propType ;
311
329
if ( annotation . type === 'GenericTypeAnnotation' ) {
312
330
propType = objectTypeAnnotations . get ( annotation . id . name ) ;
313
331
} else if ( annotation . type === 'ObjectTypeAnnotation' ) {
314
332
propType = annotation ;
333
+ } else if ( annotation . type === 'TSTypeReference' ) {
334
+ propType = objectTypeAnnotations . get ( annotation . typeName . name ) ;
315
335
}
336
+
316
337
if ( propType ) {
317
- validatePropNaming ( list [ component ] . node , propType . properties ) ;
338
+ validatePropNaming (
339
+ list [ component ] . node ,
340
+ propType . properties || propType . members
341
+ ) ;
318
342
}
319
343
}
320
344
0 commit comments