@@ -181,6 +181,25 @@ module.exports = {
181
181
}
182
182
}
183
183
184
+ // valid-jsdoc cannot read function types
185
+ // eslint-disable-next-line valid-jsdoc
186
+ /**
187
+ * Find a parent that satisfy the given predicate
188
+ * @param {ASTNode } node
189
+ * @param {(node: ASTNode) => boolean } predicate
190
+ * @returns {ASTNode | undefined }
191
+ */
192
+ function findParent ( node , predicate ) {
193
+ let n = node ;
194
+ while ( n ) {
195
+ if ( predicate ( n ) ) {
196
+ return n ;
197
+ }
198
+ n = n . parent ;
199
+ }
200
+ return undefined ;
201
+ }
202
+
184
203
return {
185
204
186
205
FunctionDeclaration : handleStatelessComponent ,
@@ -196,12 +215,7 @@ module.exports = {
196
215
'FunctionExpression:exit' : handleStatelessComponentExit ,
197
216
198
217
MemberExpression ( node ) {
199
- let scope = getScope ( context , node ) ;
200
- let SFCComponent = components . get ( scope . block ) ;
201
- while ( ! SFCComponent && scope . upper && scope . upper !== scope ) {
202
- SFCComponent = components . get ( scope . upper . block ) ;
203
- scope = scope . upper ;
204
- }
218
+ const SFCComponent = utils . getParentStatelessComponent ( node ) ;
205
219
if ( SFCComponent ) {
206
220
handleSFCUsage ( node ) ;
207
221
}
@@ -212,6 +226,25 @@ module.exports = {
212
226
}
213
227
} ,
214
228
229
+ TSQualifiedName ( node ) {
230
+ if ( configuration !== 'always' ) {
231
+ return ;
232
+ }
233
+ // handle `typeof props.a.b`
234
+ if ( node . left . type === 'Identifier'
235
+ && node . left . name === sfcParams . propsName ( )
236
+ && findParent ( node , ( n ) => n . type === 'TSTypeQuery' )
237
+ && utils . getParentStatelessComponent ( node )
238
+ ) {
239
+ report ( context , messages . useDestructAssignment , 'useDestructAssignment' , {
240
+ node,
241
+ data : {
242
+ type : 'props' ,
243
+ } ,
244
+ } ) ;
245
+ }
246
+ } ,
247
+
215
248
VariableDeclarator ( node ) {
216
249
const classComponent = utils . getParentComponent ( node ) ;
217
250
const SFCComponent = components . get ( getScope ( context , node ) . block ) ;
0 commit comments