@@ -40,6 +40,7 @@ import {
4040 isMemberExpression ,
4141 isNewExpression ,
4242 isObjectConstructorType ,
43+ isTSAsExpression ,
4344} from "#eslint-plugin-functional/utils/type-guards" ;
4445
4546/**
@@ -361,62 +362,66 @@ function checkUpdateExpression(
361362 * a mutator method call.
362363 */
363364function isInChainCallAndFollowsNew (
364- node : TSESTree . MemberExpression ,
365+ node : TSESTree . Expression ,
365366 context : Readonly < RuleContext < keyof typeof errorMessages , Options > > ,
366367) : 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+
367376 // Check for: [0, 1, 2]
368- if ( isArrayExpression ( node . object ) ) {
377+ if ( isArrayExpression ( node ) ) {
369378 return true ;
370379 }
371380
372381 // Check for: new Array()
373382 if (
374- isNewExpression ( node . object ) &&
375- isArrayConstructorType ( getTypeOfNode ( node . object . callee , context ) )
383+ isNewExpression ( node ) &&
384+ isArrayConstructorType ( getTypeOfNode ( node . callee , context ) )
376385 ) {
377386 return true ;
378387 }
379388
380389 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 )
384393 ) {
385394 // Check for: Array.from(iterable)
386395 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 ) )
391398 ) {
392399 return true ;
393400 }
394401
395402 // Check for: array.slice(0)
396403 if (
397- arrayNewObjectReturningMethods . some (
398- isExpected ( node . object . callee . property . name ) ,
399- )
404+ arrayNewObjectReturningMethods . some ( isExpected ( node . callee . property . name ) )
400405 ) {
401406 return true ;
402407 }
403408
404409 // Check for: Object.entries(object)
405410 if (
406411 objectConstructorNewObjectReturningMethods . some (
407- isExpected ( node . object . callee . property . name ) ,
412+ isExpected ( node . callee . property . name ) ,
408413 ) &&
409- isObjectConstructorType ( getTypeOfNode ( node . object . callee . object , context ) )
414+ isObjectConstructorType ( getTypeOfNode ( node . callee . object , context ) )
410415 ) {
411416 return true ;
412417 }
413418
414419 // Check for: "".split("")
415420 if (
416421 stringConstructorNewObjectReturningMethods . some (
417- isExpected ( node . object . callee . property . name ) ,
422+ isExpected ( node . callee . property . name ) ,
418423 ) &&
419- getTypeOfNode ( node . object . callee . object , context ) . isStringLiteral ( )
424+ getTypeOfNode ( node . callee . object , context ) . isStringLiteral ( )
420425 ) {
421426 return true ;
422427 }
0 commit comments