Skip to content

Commit 0fba606

Browse files
committed
fix: Handle not-last takeUntil.
1 parent 0810a82 commit 0fba606

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

source/rules/rxjsPreferAngularTakeuntilRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export class Rule extends Lint.Rules.TypedRule {
181181
pipedOperators.forEach((pipedOperator) => {
182182
if (tsutils.isCallExpression(pipedOperator)) {
183183
const { found, name } = this.checkOperator(options, pipedOperator);
184-
takeUntilFound = found;
184+
takeUntilFound = takeUntilFound || found;
185185
if (name) {
186186
addDestroySubjectName(name);
187187
}

test/v6/fixtures/prefer-angular-takeuntil/default/fixture.ts.lint

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, OnDestroy } from "@angular/core";
22
import { of, Subject } from "rxjs";
3-
import { switchMap, takeUntil } from "rxjs/operators";
3+
import { map, switchMap, takeUntil } from "rxjs/operators";
44

55
const a = of("a");
66
const b = of("b");
@@ -24,6 +24,24 @@ class CorrectComponent implements OnDestroy {
2424
}
2525
}
2626

27+
@Component({
28+
selector: "correct-component-not-last"
29+
})
30+
class CorrectComponentNotLast implements OnDestroy {
31+
private destroy = new Subject<void>();
32+
someMethod() {
33+
a.pipe(
34+
switchMap(_ => b),
35+
takeUntil(this.destroy),
36+
map(value => value)
37+
).subscribe();
38+
}
39+
ngOnDestroy() {
40+
this.destroy.next();
41+
this.destroy.complete();
42+
}
43+
}
44+
2745
@Component({
2846
selector: "destructured-component"
2947
})

0 commit comments

Comments
 (0)