11import { TSESTree as es } from '@typescript-eslint/utils' ;
2- import { isCallExpression , isIdentifier , isLiteral , isMemberExpression , isObjectExpression , isProperty } from '../etc' ;
3- import { ruleCreator } from '../utils' ;
2+ import { DEFAULT_VALID_POST_COMPLETION_OPERATORS } from '../constants' ;
3+ import { isIdentifier , isLiteral , isMemberExpression , isObjectExpression , isProperty } from '../etc' ;
4+ import { findIsLastOperatorOrderValid , ruleCreator } from '../utils' ;
45
56export const noSharereplayBeforeTakeuntilRule = ruleCreator ( {
67 defaultOptions : [ ] ,
@@ -27,18 +28,18 @@ export const noSharereplayBeforeTakeuntilRule = ruleCreator({
2728 return ;
2829 }
2930
30- const takeUntilIndex = pipeCallExpression . arguments . findIndex ( arg =>
31- isCallExpression ( arg )
32- && (
33- ( isIdentifier ( arg . callee )
34- && arg . callee . name === 'takeUntil' )
35- || ( isMemberExpression ( arg . callee )
36- && isIdentifier ( arg . callee . property )
37- && arg . callee . property . name === 'takeUntil' )
38- ) ,
31+ const { isOrderValid, operatorNode : takeUntilNode } = findIsLastOperatorOrderValid (
32+ pipeCallExpression ,
33+ / ^ t a k e U n t i l $ / ,
34+ DEFAULT_VALID_POST_COMPLETION_OPERATORS ,
3935 ) ;
36+ if ( ! isOrderValid || ! takeUntilNode ) {
37+ // takeUntil is not present or in an unsafe position itself.
38+ return ;
39+ }
4040
41- if ( takeUntilIndex === - 1 ) {
41+ if ( takeUntilNode . range [ 0 ] < node . range [ 0 ] ) {
42+ // takeUntil is before shareReplay.
4243 return ;
4344 }
4445
0 commit comments