Skip to content

Commit

Permalink
fix: Account for subscriber chaining.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Nov 5, 2020
1 parent 0464f87 commit a821e82
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions source/rules/rxjsNoIgnoredSubscriptionRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export class Rule extends Lint.Rules.TypedRule {
propertyAccessExpression.expression
);
if (couldBeType(type, "Observable")) {
if (
callExpression.arguments.length === 1 &&
couldBeType(
typeChecker.getTypeAtLocation(callExpression.arguments[0]),
"Subscriber"
)
) {
return;
}
const { name } = callExpression.expression;
failures.push(
new Lint.RuleFailure(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { of, Subscription } from "rxjs";
import { of, Subscriber, Subscription } from "rxjs";

of(42).subscribe();
~~~~~~~~~ [no-ignored-subscription]
Expand All @@ -9,4 +9,7 @@ b = of(42).subscribe();
const c = [of(42).subscribe()];
const d = { subscription: of(42).subscribe() };

const subscriber = new Subscriber<number>();
of(42).subscribe(subscriber);

[no-ignored-subscription]: Ignoring returned subscriptions is forbidden

0 comments on commit a821e82

Please sign in to comment.