@@ -263,58 +263,17 @@ export const parseJestFnCallWithReason = (
263
263
264
264
const type = determineJestFnType ( name ) ;
265
265
266
- // if (
267
- // node.parent?.type === AST_NODE_TYPES.CallExpression
268
- // // node.parent?.type === AST_NODE_TYPES.MemberExpression
269
- // ) {
270
- // return null;
271
- // }
272
-
273
266
if ( type === 'expect' ) {
274
- // const findTopMostMemberExpression = (
275
- // node: TSESTree.MemberExpression,
276
- // ): TSESTree.MemberExpression => {
277
- // let topMostMemberExpression = node;
278
- // let { parent } = node;
279
- //
280
- // while (parent) {
281
- // if (parent.type !== AST_NODE_TYPES.MemberExpression) {
282
- // break;
283
- // }
284
- //
285
- // topMostMemberExpression = parent;
286
- // parent = parent.parent;
287
- // }
288
- //
289
- // return topMostMemberExpression;
290
- // };
291
267
const result = parseJestExpectCall ( parsedJestFnCall ) ;
292
268
293
- const topMost = findTopMostCallExpression ( node ) ;
294
-
295
- // if (topMost !== node) {
296
- // return null;
297
- // }
298
-
299
- // console.log(
300
- // typeof result,
301
- // 'topmost',
302
- // topMost === node,
303
- // parsedJestFnCall.members.length,
304
- // );
305
- if ( typeof result === 'string' && topMost !== node ) {
269
+ // if the `expect` call chain is not valid, only report on the topmost node
270
+ // since all members in the chain are likely to get flagged for some reason
271
+ if (
272
+ typeof result === 'string' &&
273
+ findTopMostCallExpression ( node ) !== node
274
+ ) {
306
275
return null ;
307
276
}
308
- // console.log(result);
309
-
310
- // if (typeof result !== 'string') {
311
- // if (
312
- // node.parent?.type === AST_NODE_TYPES.CallExpression ||
313
- // node.parent?.type === AST_NODE_TYPES.MemberExpression
314
- // ) {
315
- // return null;
316
- // }
317
- // }
318
277
319
278
if ( result === 'matcher-not-found' ) {
320
279
if ( node . parent ?. type === AST_NODE_TYPES . MemberExpression ) {
@@ -361,10 +320,6 @@ const findModifiersAndMatcher = (
361
320
) : ModifiersAndMatcher | string => {
362
321
const modifiers : KnownMemberExpressionProperty [ ] = [ ] ;
363
322
364
- if ( members . length === 0 ) {
365
- return 'matcher-not-found' ;
366
- }
367
-
368
323
for ( const member of members ) {
369
324
// check if the member is being called, which means it is the matcher
370
325
// (and also the end of the entire "expect" call chain)
@@ -377,7 +332,6 @@ const findModifiersAndMatcher = (
377
332
matcherArgs : member . parent . parent . arguments ,
378
333
modifiers,
379
334
} ;
380
- // return 'matcher-not-called';
381
335
}
382
336
383
337
// otherwise, it should be a modifier
@@ -410,7 +364,8 @@ const findModifiersAndMatcher = (
410
364
modifiers . push ( member ) ;
411
365
}
412
366
413
- return 'matcher-not-called' ;
367
+ // this will only really happen if there are no members
368
+ return 'matcher-not-found' ;
414
369
} ;
415
370
416
371
const parseJestExpectCall = (
0 commit comments