Skip to content

Commit

Permalink
chore: Rename callbacks to handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
cartant committed Oct 26, 2021
1 parent ea36a6d commit a1b21de
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,14 @@ Rules marked with ✅ are recommended and rules marked with 🔧 have fixers.
| [`no-subclass`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-subclass.md) | Forbids subclassing RxJS classes. | | |
| [`no-subject-unsubscribe`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-subject-unsubscribe.md) | Forbids calling the `unsubscribe` method of a subject instance. || |
| [`no-subject-value`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-subject-value.md) | Forbids accessing the `value` property of a `BehaviorSubject` instance. | | |
| [`no-subscribe-callbacks`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-subscribe-callbacks.md) | Forbids the calling of `subscribe` with arguments. | | |
| [`no-subscribe-handlers`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-subscribe-handlers.md) | Forbids the passing of handlers to `subscribe`. | | |
| [`no-topromise`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-topromise.md) | Forbids the use of the `toPromise` method. | | |
| [`no-unbound-methods`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-unbound-methods.md) | Forbids the passing of unbound methods. || |
| [`no-unsafe-catch`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-unsafe-catch.md) | Forbids unsafe `catchError` usage in effects and epics. | | |
| [`no-unsafe-first`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-unsafe-first.md) | Forbids unsafe `first`/`take` usage in effects and epics. | | |
| [`no-unsafe-subject-next`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-unsafe-subject-next.md) | Forbids unsafe optional `next` calls. || |
| [`no-unsafe-switchmap`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-unsafe-switchmap.md) | Forbids unsafe `switchMap` usage in effects and epics. | | |
| [`no-unsafe-takeuntil`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-unsafe-takeuntil.md) | Forbids the application of operators after `takeUntil`. || |
| [`prefer-observer`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/prefer-observer.md) | Forbids the passing separate callbacks to `subscribe` and `tap`. | | |
| [`prefer-observer`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/prefer-observer.md) | Forbids the passing separate handlers to `subscribe` and `tap`. | | |
| [`suffix-subjects`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/suffix-subjects.md) | Enforces the use of a suffix in subject identifiers. | | |
| [`throw-error`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/throw-error.md) | Enforces the passing of `Error` values to error notifications. | | |
4 changes: 2 additions & 2 deletions docs/rules/no-implicit-any-catch.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Use type-safe error callbacks (`no-implicit-any-catch`)
# Use type-safe error handlers (`no-implicit-any-catch`)

This rule requires an explicit type annotation for error parameters in error callbacks. It's similar to the TypeScript [`no-implicit-any-catch`](https://github.com/typescript-eslint/typescript-eslint/blob/e01204931e460f5e6731abc443c88d666ca0b07a/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md) rule, but is for observables - not `try`/`catch` statements.
This rule requires an explicit type annotation for error parameters in error handlers. It's similar to the TypeScript [`no-implicit-any-catch`](https://github.com/typescript-eslint/typescript-eslint/blob/e01204931e460f5e6731abc443c88d666ca0b07a/packages/eslint-plugin/docs/rules/no-implicit-any-catch.md) rule, but is for observables - not `try`/`catch` statements.

## Rule details

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Forbid the passing of handlers to `subscribe` (`no-subscribe-callbacks`)
# Forbid the passing of handlers to `subscribe` (`no-subscribe-handlers`)

This rule effects failures whenever `subscribe` is called with handlers.

Expand All @@ -13,14 +13,25 @@ import { tap } from "rxjs/operators";
of(42, 54).subscribe((value) => console.log(value));
```

<!-- prettier-ignore -->
```ts
import { of } from "rxjs";
import { tap } from "rxjs/operators";

of(42, 54).subscribe({
next: (value) => console.log(value),
});
```

Examples of **correct** code for this rule:

<!-- prettier-ignore -->
```ts
import { of } from "rxjs";

of(42, 54).pipe(
tap((value) => console.log(value))
).subscribe();
of(42, 54)
.pipe(tap((value) => console.log(value)))
.subscribe();
```

## Options
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/prefer-observer.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Avoid separate callbacks (`prefer-observer`)
# Avoid separate handlers (`prefer-observer`)

This rule effects failures if `subscribe` - or `tap` - is called with separate callbacks instead of an observer.
This rule effects failures if `subscribe` - or `tap` - is called with separate handlers instead of an observer.

## Rule details

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@ const rule = ruleCreator({
defaultOptions: [],
meta: {
docs: {
description:
"Forbids the calling of `subscribe` with arguments.",
description: "Forbids the passing of handlers to `subscribe`.",
recommended: false,
},
fixable: undefined,
hasSuggestions: false,
messages: {
forbidden: "Calling subscribe with arguments is forbidden.",
forbidden: "Passing handlers to subscribe is forbidden.",
},
schema: [],
type: "problem",
},
name: "no-subscribe-callbacks",
name: "no-subscribe-handlers",
create: (context) => {
const { couldBeObservable, couldBeType } = getTypeServices(context);

Expand Down
4 changes: 2 additions & 2 deletions source/rules/prefer-observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ const rule = ruleCreator({
meta: {
docs: {
description:
"Forbids the passing separate callbacks to `subscribe` and `tap`.",
"Forbids the passing separate handlers to `subscribe` and `tap`.",
recommended: false,
},
fixable: undefined,
hasSuggestions: false,
messages: {
forbidden:
"Passing separate callbacks is forbidden; pass an observer instead.",
"Passing separate handlers is forbidden; pass an observer instead.",
},
schema: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

import { stripIndent } from "common-tags";
import { fromFixture } from "eslint-etc";
import rule = require("../../source/rules/no-subscribe-callbacks");
import rule = require("../../source/rules/no-subscribe-handlers");
import { ruleTester } from "../utils";

ruleTester({ types: true }).run("no-subscribe-callbacks", rule, {
ruleTester({ types: true }).run("no-subscribe-handlers", rule, {
valid: [
{
code: stripIndent`
Expand Down Expand Up @@ -95,5 +95,15 @@ ruleTester({ types: true }).run("no-subscribe-callbacks", rule, {
~~~~~~~~~ [forbidden]
`
),
fromFixture(
stripIndent`
import { Subscribable } from "rxjs";
declare const subscribable: Subscribable<unknown>;
subscribable.subscribe({
~~~~~~~~~ [forbidden]
next: (value) => console.log(value)
});
`
),
],
});

0 comments on commit a1b21de

Please sign in to comment.