Skip to content

Commit a1b21de

Browse files
committed
chore: Rename callbacks to handlers.
1 parent ea36a6d commit a1b21de

7 files changed

+38
-18
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ Rules marked with ✅ are recommended and rules marked with 🔧 have fixers.
103103
| [`no-subclass`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-subclass.md) | Forbids subclassing RxJS classes. | | |
104104
| [`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. || |
105105
| [`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. | | |
106-
| [`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. | | |
106+
| [`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`. | | |
107107
| [`no-topromise`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-topromise.md) | Forbids the use of the `toPromise` method. | | |
108108
| [`no-unbound-methods`](https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/no-unbound-methods.md) | Forbids the passing of unbound methods. || |
109109
| [`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. | | |
110110
| [`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. | | |
111111
| [`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. || |
112112
| [`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. | | |
113113
| [`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`. || |
114-
| [`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`. | | |
114+
| [`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`. | | |
115115
| [`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. | | |
116116
| [`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. | | |

docs/rules/no-implicit-any-catch.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Use type-safe error callbacks (`no-implicit-any-catch`)
1+
# Use type-safe error handlers (`no-implicit-any-catch`)
22

3-
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.
3+
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.
44

55
## Rule details
66

docs/rules/no-subscribe-callbacks.md renamed to docs/rules/no-subscribe-handlers.md

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Forbid the passing of handlers to `subscribe` (`no-subscribe-callbacks`)
1+
# Forbid the passing of handlers to `subscribe` (`no-subscribe-handlers`)
22

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

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

16+
<!-- prettier-ignore -->
17+
```ts
18+
import { of } from "rxjs";
19+
import { tap } from "rxjs/operators";
20+
21+
of(42, 54).subscribe({
22+
next: (value) => console.log(value),
23+
});
24+
```
25+
1626
Examples of **correct** code for this rule:
1727

28+
<!-- prettier-ignore -->
1829
```ts
1930
import { of } from "rxjs";
2031

21-
of(42, 54).pipe(
22-
tap((value) => console.log(value))
23-
).subscribe();
32+
of(42, 54)
33+
.pipe(tap((value) => console.log(value)))
34+
.subscribe();
2435
```
2536

2637
## Options

docs/rules/prefer-observer.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Avoid separate callbacks (`prefer-observer`)
1+
# Avoid separate handlers (`prefer-observer`)
22

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

55
## Rule details
66

source/rules/no-subscribe-callbacks.ts renamed to source/rules/no-subscribe-handlers.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ const rule = ruleCreator({
1111
defaultOptions: [],
1212
meta: {
1313
docs: {
14-
description:
15-
"Forbids the calling of `subscribe` with arguments.",
14+
description: "Forbids the passing of handlers to `subscribe`.",
1615
recommended: false,
1716
},
1817
fixable: undefined,
1918
hasSuggestions: false,
2019
messages: {
21-
forbidden: "Calling subscribe with arguments is forbidden.",
20+
forbidden: "Passing handlers to subscribe is forbidden.",
2221
},
2322
schema: [],
2423
type: "problem",
2524
},
26-
name: "no-subscribe-callbacks",
25+
name: "no-subscribe-handlers",
2726
create: (context) => {
2827
const { couldBeObservable, couldBeType } = getTypeServices(context);
2928

source/rules/prefer-observer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ const rule = ruleCreator({
2121
meta: {
2222
docs: {
2323
description:
24-
"Forbids the passing separate callbacks to `subscribe` and `tap`.",
24+
"Forbids the passing separate handlers to `subscribe` and `tap`.",
2525
recommended: false,
2626
},
2727
fixable: undefined,
2828
hasSuggestions: false,
2929
messages: {
3030
forbidden:
31-
"Passing separate callbacks is forbidden; pass an observer instead.",
31+
"Passing separate handlers is forbidden; pass an observer instead.",
3232
},
3333
schema: [
3434
{

tests/rules/no-subscribe-callbacks.ts renamed to tests/rules/no-subscribe-handlers.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

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

11-
ruleTester({ types: true }).run("no-subscribe-callbacks", rule, {
11+
ruleTester({ types: true }).run("no-subscribe-handlers", rule, {
1212
valid: [
1313
{
1414
code: stripIndent`
@@ -95,5 +95,15 @@ ruleTester({ types: true }).run("no-subscribe-callbacks", rule, {
9595
~~~~~~~~~ [forbidden]
9696
`
9797
),
98+
fromFixture(
99+
stripIndent`
100+
import { Subscribable } from "rxjs";
101+
declare const subscribable: Subscribable<unknown>;
102+
subscribable.subscribe({
103+
~~~~~~~~~ [forbidden]
104+
next: (value) => console.log(value)
105+
});
106+
`
107+
),
98108
],
99109
});

0 commit comments

Comments
 (0)