@@ -40,6 +40,7 @@ import {
40
40
isMemberExpression ,
41
41
isNewExpression ,
42
42
isObjectConstructorType ,
43
+ isTSAsExpression ,
43
44
} from "#eslint-plugin-functional/utils/type-guards" ;
44
45
45
46
/**
@@ -361,62 +362,66 @@ function checkUpdateExpression(
361
362
* a mutator method call.
362
363
*/
363
364
function isInChainCallAndFollowsNew (
364
- node : TSESTree . MemberExpression ,
365
+ node : TSESTree . Expression ,
365
366
context : Readonly < RuleContext < keyof typeof errorMessages , Options > > ,
366
367
) : boolean {
368
+ if ( isMemberExpression ( node ) ) {
369
+ return isInChainCallAndFollowsNew ( node . object , context ) ;
370
+ }
371
+
372
+ if ( isTSAsExpression ( node ) ) {
373
+ return isInChainCallAndFollowsNew ( node . expression , context ) ;
374
+ }
375
+
367
376
// Check for: [0, 1, 2]
368
- if ( isArrayExpression ( node . object ) ) {
377
+ if ( isArrayExpression ( node ) ) {
369
378
return true ;
370
379
}
371
380
372
381
// Check for: new Array()
373
382
if (
374
- isNewExpression ( node . object ) &&
375
- isArrayConstructorType ( getTypeOfNode ( node . object . callee , context ) )
383
+ isNewExpression ( node ) &&
384
+ isArrayConstructorType ( getTypeOfNode ( node . callee , context ) )
376
385
) {
377
386
return true ;
378
387
}
379
388
380
389
if (
381
- isCallExpression ( node . object ) &&
382
- isMemberExpression ( node . object . callee ) &&
383
- isIdentifier ( node . object . callee . property )
390
+ isCallExpression ( node ) &&
391
+ isMemberExpression ( node . callee ) &&
392
+ isIdentifier ( node . callee . property )
384
393
) {
385
394
// Check for: Array.from(iterable)
386
395
if (
387
- arrayConstructorFunctions . some (
388
- isExpected ( node . object . callee . property . name ) ,
389
- ) &&
390
- isArrayConstructorType ( getTypeOfNode ( node . object . callee . object , context ) )
396
+ arrayConstructorFunctions . some ( isExpected ( node . callee . property . name ) ) &&
397
+ isArrayConstructorType ( getTypeOfNode ( node . callee . object , context ) )
391
398
) {
392
399
return true ;
393
400
}
394
401
395
402
// Check for: array.slice(0)
396
403
if (
397
- arrayNewObjectReturningMethods . some (
398
- isExpected ( node . object . callee . property . name ) ,
399
- )
404
+ arrayNewObjectReturningMethods . some ( isExpected ( node . callee . property . name ) )
400
405
) {
401
406
return true ;
402
407
}
403
408
404
409
// Check for: Object.entries(object)
405
410
if (
406
411
objectConstructorNewObjectReturningMethods . some (
407
- isExpected ( node . object . callee . property . name ) ,
412
+ isExpected ( node . callee . property . name ) ,
408
413
) &&
409
- isObjectConstructorType ( getTypeOfNode ( node . object . callee . object , context ) )
414
+ isObjectConstructorType ( getTypeOfNode ( node . callee . object , context ) )
410
415
) {
411
416
return true ;
412
417
}
413
418
414
419
// Check for: "".split("")
415
420
if (
416
421
stringConstructorNewObjectReturningMethods . some (
417
- isExpected ( node . object . callee . property . name ) ,
422
+ isExpected ( node . callee . property . name ) ,
418
423
) &&
419
- getTypeOfNode ( node . object . callee . object , context ) . isStringLiteral ( )
424
+ getTypeOfNode ( node . callee . object , context ) . isStringLiteral ( )
420
425
) {
421
426
return true ;
422
427
}
0 commit comments