eslint-plugin-rxjs-x 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +89 -0
- package/dist/index.cjs +2936 -0
- package/dist/index.d.cts +121 -0
- package/dist/index.d.mts +121 -0
- package/dist/index.d.ts +121 -0
- package/dist/index.mjs +2916 -0
- package/docs/rules/ban-observables.md +22 -0
- package/docs/rules/ban-operators.md +21 -0
- package/docs/rules/finnish.md +54 -0
- package/docs/rules/just.md +11 -0
- package/docs/rules/macro.md +7 -0
- package/docs/rules/no-async-subscribe.md +27 -0
- package/docs/rules/no-compat.md +11 -0
- package/docs/rules/no-connectable.md +7 -0
- package/docs/rules/no-create.md +29 -0
- package/docs/rules/no-cyclic-action.md +62 -0
- package/docs/rules/no-explicit-generics.md +23 -0
- package/docs/rules/no-exposed-subjects.md +39 -0
- package/docs/rules/no-finnish.md +25 -0
- package/docs/rules/no-ignored-error.md +37 -0
- package/docs/rules/no-ignored-notifier.md +30 -0
- package/docs/rules/no-ignored-observable.md +23 -0
- package/docs/rules/no-ignored-replay-buffer.md +28 -0
- package/docs/rules/no-ignored-subscribe.md +28 -0
- package/docs/rules/no-ignored-subscription.md +33 -0
- package/docs/rules/no-ignored-takewhile-value.md +26 -0
- package/docs/rules/no-implicit-any-catch.md +78 -0
- package/docs/rules/no-index.md +21 -0
- package/docs/rules/no-internal.md +21 -0
- package/docs/rules/no-nested-subscribe.md +30 -0
- package/docs/rules/no-redundant-notify.md +32 -0
- package/docs/rules/no-sharereplay.md +22 -0
- package/docs/rules/no-subclass.md +7 -0
- package/docs/rules/no-subject-unsubscribe.md +11 -0
- package/docs/rules/no-subject-value.md +7 -0
- package/docs/rules/no-subscribe-handlers.md +39 -0
- package/docs/rules/no-tap.md +7 -0
- package/docs/rules/no-topromise.md +7 -0
- package/docs/rules/no-unbound-methods.md +47 -0
- package/docs/rules/no-unsafe-catch.md +50 -0
- package/docs/rules/no-unsafe-first.md +16 -0
- package/docs/rules/no-unsafe-subject-next.md +30 -0
- package/docs/rules/no-unsafe-switchmap.md +38 -0
- package/docs/rules/no-unsafe-takeuntil.md +46 -0
- package/docs/rules/prefer-observer.md +34 -0
- package/docs/rules/suffix-subjects.md +42 -0
- package/docs/rules/throw-error.md +49 -0
- package/package.json +82 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Avoid banned observable creators (`ban-observables`)
|
|
2
|
+
|
|
3
|
+
This rule can be configured so that developers can ban any observable creators they want to avoid in their project.
|
|
4
|
+
|
|
5
|
+
## Options
|
|
6
|
+
|
|
7
|
+
This rule accepts a single option which is an object the keys of which are the names of observable factory functions and the values are either booleans or strings containing the explanation for the ban.
|
|
8
|
+
|
|
9
|
+
The following configuration bans `partition` and `onErrorResumeNext`:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"rxjs-x/ban-observables": [
|
|
14
|
+
"error",
|
|
15
|
+
{
|
|
16
|
+
"partition": true,
|
|
17
|
+
"of": false,
|
|
18
|
+
"onErrorResumeNext": "What is this? Visual Basic?"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Avoid banned operators (`ban-operators`)
|
|
2
|
+
|
|
3
|
+
This rule can be configured so that developers can ban any operators they want to avoid in their project.
|
|
4
|
+
|
|
5
|
+
## Options
|
|
6
|
+
|
|
7
|
+
This rule accepts a single option which is an object the keys of which are the names of operators and the values are either booleans or strings containing the explanation for the ban.
|
|
8
|
+
|
|
9
|
+
The following configuration bans `partition` and `onErrorResumeNext`:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"rxjs-x/ban-operators": [
|
|
14
|
+
"error",
|
|
15
|
+
{
|
|
16
|
+
"partition": true,
|
|
17
|
+
"map": false,
|
|
18
|
+
"onErrorResumeNext": "What is this? Visual Basic?"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Use Finnish notation (`finnish`)
|
|
2
|
+
|
|
3
|
+
This rule enforces the use of Finnish notation - i.e. the `$` suffix.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const answers = of(42, 54);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Examples of **correct** code for this rule:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const answer$ = of(42, 54);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Options
|
|
20
|
+
|
|
21
|
+
This rule accepts a single option which is an object with properties that determine whether Finnish notation is enforced for `functions`, `methods`, `parameters`, `properties` and `variables`. It also contains:
|
|
22
|
+
|
|
23
|
+
- `names` and `types` properties that determine whether of not Finnish notation is to be enforced for specific names or types.
|
|
24
|
+
- a `strict` property that, if `true`, allows the `$` suffix to be used _only_ with identifiers that have an `Observable` type.
|
|
25
|
+
|
|
26
|
+
The default (Angular-friendly) configuration looks like this:
|
|
27
|
+
|
|
28
|
+
```json
|
|
29
|
+
{
|
|
30
|
+
"rxjs-x/finnish": [
|
|
31
|
+
"error",
|
|
32
|
+
{
|
|
33
|
+
"functions": true,
|
|
34
|
+
"methods": true,
|
|
35
|
+
"names": {
|
|
36
|
+
"^(canActivate|canActivateChild|canDeactivate|canLoad|intercept|resolve|validate)$": false
|
|
37
|
+
},
|
|
38
|
+
"parameters": true,
|
|
39
|
+
"properties": true,
|
|
40
|
+
"strict": false,
|
|
41
|
+
"types": {
|
|
42
|
+
"^EventEmitter$": false
|
|
43
|
+
},
|
|
44
|
+
"variables": true
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
The properties in the options object are themselves optional; they do not all have to be specified.
|
|
51
|
+
|
|
52
|
+
## Further reading
|
|
53
|
+
|
|
54
|
+
- [Observables and Finnish Notation](https://medium.com/@benlesh/observables-and-finnish-notation-df8356ed1c9b)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Use `just` instead of `of` (`just`)
|
|
2
|
+
|
|
3
|
+
This rule enforces the use of `just` instead of `of`. Some other languages with Rx implementations use the former and this rule is for developers who have that preference.
|
|
4
|
+
|
|
5
|
+
## Options
|
|
6
|
+
|
|
7
|
+
This rule has no options.
|
|
8
|
+
|
|
9
|
+
## Further reading
|
|
10
|
+
|
|
11
|
+
- [Rename `of` to `just`](https://github.com/ReactiveX/rxjs/issues/3747)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Avoid passing async functions to `subscribe` (`no-async-subscribe`)
|
|
2
|
+
|
|
3
|
+
This rule effects failures if async functions are passed to `subscribe`.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { of } from "rxjs";
|
|
11
|
+
of(42).subscribe(async () => console.log(value));
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Examples of **correct** code for this rule:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { of } from "rxjs";
|
|
18
|
+
of(42).subscribe(() => console.log(value));
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Options
|
|
22
|
+
|
|
23
|
+
This rule has no options.
|
|
24
|
+
|
|
25
|
+
## Further reading
|
|
26
|
+
|
|
27
|
+
- [Why does this rule exist?](https://stackoverflow.com/q/71559135)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Avoid the `rxjs-compat` package (`no-compat`)
|
|
2
|
+
|
|
3
|
+
This rule prevents the use of `rxjs-compat`.
|
|
4
|
+
|
|
5
|
+
## Options
|
|
6
|
+
|
|
7
|
+
This rule has no options.
|
|
8
|
+
|
|
9
|
+
## Further reading
|
|
10
|
+
|
|
11
|
+
- [Backwards compatibility](https://github.com/ReactiveX/rxjs/blob/a6590e971969c736a15b77154dabbc22275aa0d5/docs_app/content/guide/v6/migration.md#backwards-compatibility)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Avoid the static `create` function (`no-create`)
|
|
2
|
+
|
|
3
|
+
This rule prevents the use of the static `create` function in `Observable`. Developers should use `new` and the constructor instead.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const answers = Observable.create(subscriber => {
|
|
11
|
+
subscriber.next(42);
|
|
12
|
+
subscriber.next(54);
|
|
13
|
+
subscriber.complete();
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Examples of **correct** code for this rule:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const answers = new Observable<number>(subscriber => {
|
|
21
|
+
subscriber.next(42);
|
|
22
|
+
subscriber.next(54);
|
|
23
|
+
subscriber.complete();
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Options
|
|
28
|
+
|
|
29
|
+
This rule has no options.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Avoid cyclic actions in effects and epics (`no-cyclic-action`)
|
|
2
|
+
|
|
3
|
+
This rule effects failures for effects and epics that emit actions that would pass their `ofType` filter. Such actions are cyclic and, upon emission, immediately re-trigger the effect or epic.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
actions.pipe(
|
|
11
|
+
ofType("SOMETHING"),
|
|
12
|
+
map(() => ({ type: "SOMETHING" }))
|
|
13
|
+
);
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Examples of **correct** code for this rule:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
actions.pipe(
|
|
20
|
+
ofType("SOMETHING"),
|
|
21
|
+
map(() => ({ type: "SOMETHING_ELSE" }))
|
|
22
|
+
);
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
This rule can be used with effects _and epics_, so it makes __no attempt__ to discern whether or not dispatching is disabled for an NgRx effect. That is, code like this will effect (🙈) a failure:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
someEffect = createEffect(() =>
|
|
29
|
+
this.actions$.pipe(
|
|
30
|
+
ofType("SOMETHING"),
|
|
31
|
+
tap(() => console.log("do something")),
|
|
32
|
+
),
|
|
33
|
+
{ dispatch: false }
|
|
34
|
+
);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Instead, you can use the the RxJS [`ignoreElements`](https://rxjs.dev/api/operators/ignoreElements) operator:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
someEffect = createEffect(() =>
|
|
41
|
+
this.actions$.pipe(
|
|
42
|
+
ofType("SOMETHING"),
|
|
43
|
+
tap(() => console.log("do something")),
|
|
44
|
+
ignoreElements()
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Or you can use an ESLint [inline comment](https://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments) to disable the rule for a specific effect.
|
|
50
|
+
|
|
51
|
+
## Options
|
|
52
|
+
|
|
53
|
+
This rule accepts a single option which is an object with an `observable` property that is a regular expression used to match an effect or epic's actions observable. The default `observable` regular expression should match most effect and epic action sources.
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"rxjs-x/no-cyclic-action": [
|
|
58
|
+
"error",
|
|
59
|
+
{ "observable": "[Aa]ction(s|s\\$|\\$)$" }
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Avoid unnecessary explicit type arguments (`no-explicit-generics`)
|
|
2
|
+
|
|
3
|
+
This rule prevents the use of explicit type arguments when the type arguments can be inferred.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { BehaviorSubject } from "rxjs";
|
|
11
|
+
const subject = new BehaviorSubject<number>(42);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Examples of **correct** code for this rule:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { BehaviorSubject } from "rxjs";
|
|
18
|
+
const subject = new BehaviorSubject(42);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Options
|
|
22
|
+
|
|
23
|
+
This rule has no options.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Avoid public and protected subjects (`no-exposed-subjects`)
|
|
2
|
+
|
|
3
|
+
This rule prevents the public or protected subjects. Developers should instead expose observables via the subjects' `toObservable` method.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { Subject } from "rxjs";
|
|
11
|
+
class Answers {
|
|
12
|
+
public answers: Subject<number>;
|
|
13
|
+
}
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Examples of **correct** code for this rule:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { Subject } from "rxjs";
|
|
20
|
+
class Answers {
|
|
21
|
+
private _answers: Subject<string>;
|
|
22
|
+
get answers() {
|
|
23
|
+
return this._answers.toObservable();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Options
|
|
29
|
+
|
|
30
|
+
This rule accepts a single option which is an object with an `allowProtected` property that determines whether or not protected subjects are allowed. By default, they are not.
|
|
31
|
+
|
|
32
|
+
```json
|
|
33
|
+
{
|
|
34
|
+
"rxjs-x/no-exposed-subjects": [
|
|
35
|
+
"error",
|
|
36
|
+
{ "allowProtected": true }
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Avoid Finnish notation (`no-finnish`)
|
|
2
|
+
|
|
3
|
+
This rule prevents the use of Finnish notation.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
const answer$ = of(42, 54);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Examples of **correct** code for this rule:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
const answers = of(42, 54);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Options
|
|
20
|
+
|
|
21
|
+
This rule has no options.
|
|
22
|
+
|
|
23
|
+
## Further reading
|
|
24
|
+
|
|
25
|
+
- [Observables and Finnish Notation](https://medium.com/@benlesh/observables-and-finnish-notation-df8356ed1c9b)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Enforce the passing of error handlers (`no-ignored-error`)
|
|
2
|
+
|
|
3
|
+
This rule enforces the passing of an error handler to `subscribe` calls.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
source.subscribe((value) => console.log(value));
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
source.subscribe({
|
|
15
|
+
next: (value) => console.log(value)
|
|
16
|
+
});
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Examples of **correct** code for this rule:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
source.subscribe(
|
|
23
|
+
(value) => console.log(value),
|
|
24
|
+
(error) => console.error(error)
|
|
25
|
+
);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
source.subscribe({
|
|
30
|
+
next: (value) => console.log(value),
|
|
31
|
+
error: (error) => console.error(error)
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Options
|
|
36
|
+
|
|
37
|
+
This rule has no options.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Ensure `repeatWhen` or `retryWhen` notifiers are used (`no-ignored-notifier`)
|
|
2
|
+
|
|
3
|
+
This rule effects failures if the notifier passed to a `repeatWhen` or `retryWhen` callback is not used.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { range } from "rxjs";
|
|
11
|
+
import { repeatWhen, take } from "rxjs/operators";
|
|
12
|
+
|
|
13
|
+
const repeating = source.pipe(
|
|
14
|
+
repeatWhen(notifications => range(0, 3))
|
|
15
|
+
);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Examples of **correct** code for this rule:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { repeatWhen, take } from "rxjs/operators";
|
|
22
|
+
|
|
23
|
+
const repeating = source.pipe(
|
|
24
|
+
repeatWhen(notifications => notifications.pipe(take(3)))
|
|
25
|
+
);
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Options
|
|
29
|
+
|
|
30
|
+
This rule has no options.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Use returned observables (`no-ignored-observable`)
|
|
2
|
+
|
|
3
|
+
The effects failures if an observable returned by a function is neither assigned to a variable or property or passed to a function.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { of } from "rxjs";
|
|
11
|
+
of(42, 54);
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Examples of **correct** code for this rule:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { of } from "rxjs";
|
|
18
|
+
const answers = of(42, 54);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Options
|
|
22
|
+
|
|
23
|
+
This rule has no options.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Avoid unbounded replay buffers (`no-ignored-replay-buffer`)
|
|
2
|
+
|
|
3
|
+
This rule effects failures if the buffer size of a replay buffer is not explicitly specified.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { ReplaySubject } from "rxjs";
|
|
11
|
+
const subject = new ReplaySubject<number>();
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Examples of **correct** code for this rule:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { ReplaySubject } from "rxjs";
|
|
18
|
+
const subject = new ReplaySubject<number>(1);
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { ReplaySubject } from "rxjs";
|
|
23
|
+
const subject = new ReplaySubject<number>(Infinity);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Options
|
|
27
|
+
|
|
28
|
+
This rule has no options.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Enforce the passing of handlers to `subscribe` (`no-ignored-subscribe`)
|
|
2
|
+
|
|
3
|
+
This rule effects failures whenever `subscribe` is called without handlers.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { of } from "rxjs";
|
|
11
|
+
import { tap } from "rxjs/operators";
|
|
12
|
+
|
|
13
|
+
of(42, 54).pipe(
|
|
14
|
+
tap((value) => console.log(value))
|
|
15
|
+
).subscribe();
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Examples of **correct** code for this rule:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import { of } from "rxjs";
|
|
22
|
+
|
|
23
|
+
of(42, 54).subscribe((value) => console.log(value));
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Options
|
|
27
|
+
|
|
28
|
+
This rule has no options.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Use returned subscriptions (`no-ignored-subscription`)
|
|
2
|
+
|
|
3
|
+
The effects failures if an subscription returned by call to `subscribe` is neither assigned to a variable or property or passed to a function.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
interval(1e3).subscribe(
|
|
11
|
+
(value) => console.log(value)
|
|
12
|
+
);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Examples of **correct** code for this rule:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
const subscription = interval(1e3).subscribe(
|
|
19
|
+
(value) => console.log(value)
|
|
20
|
+
);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
When subscribers are passed to `subscribe` they are chained, so the returned subscription can be ignored:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
const numbers = new Observable<number>(subscriber => {
|
|
27
|
+
interval(1e3).subscribe(subscriber);
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Options
|
|
32
|
+
|
|
33
|
+
This rule has no options.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Avoid unused `takeWhile` values (`no-ignored-takewhile-value`)
|
|
2
|
+
|
|
3
|
+
This rule effects failures if the value received by a `takeWhile` callback is not used in an expression.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { takeWhile } from "rxjs/operators";
|
|
11
|
+
|
|
12
|
+
let flag = true;
|
|
13
|
+
const whilst = source.pipe(takeWhile(() => flag));
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Examples of **correct** code for this rule:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { takeWhile } from "rxjs/operators";
|
|
20
|
+
|
|
21
|
+
const whilst = source.pipe(takeWhile(value => value));
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Options
|
|
25
|
+
|
|
26
|
+
This rule has no options.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Use type-safe error handlers (`no-implicit-any-catch`)
|
|
2
|
+
|
|
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.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { throwError } from "rxjs";
|
|
11
|
+
import { catchError } from "rxjs/operators";
|
|
12
|
+
|
|
13
|
+
throwError(() => new Error("Kaboom!")).pipe(
|
|
14
|
+
catchError((error) => console.error(error))
|
|
15
|
+
);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import { throwError } from "rxjs";
|
|
20
|
+
|
|
21
|
+
throwError(() => new Error("Kaboom!")).subscribe({
|
|
22
|
+
error: (error) => console.error(error)
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { throwError } from "rxjs";
|
|
28
|
+
import { tap } from "rxjs/operators";
|
|
29
|
+
|
|
30
|
+
throwError(() => new Error("Kaboom!")).pipe(
|
|
31
|
+
tap(undefined, (error) => console.error(error))
|
|
32
|
+
);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Examples of **correct** code for this rule:
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { throwError } from "rxjs";
|
|
39
|
+
import { catchError } from "rxjs/operators";
|
|
40
|
+
|
|
41
|
+
throwError(() => new Error("Kaboom!")).pipe(
|
|
42
|
+
catchError((error: unknown) => console.error(error))
|
|
43
|
+
);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { throwError } from "rxjs";
|
|
48
|
+
|
|
49
|
+
throwError(() => new Error("Kaboom!")).subscribe({
|
|
50
|
+
error: (error: unknown) => console.error(error)
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { throwError } from "rxjs";
|
|
56
|
+
import { tap } from "rxjs/operators";
|
|
57
|
+
|
|
58
|
+
throwError(() => new Error("Kaboom!")).pipe(
|
|
59
|
+
tap(undefined, (error: unknown) => console.error(error))
|
|
60
|
+
);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Options
|
|
64
|
+
|
|
65
|
+
This rule accepts a single option which is an object with an `allowExplicitAny` property that determines whether or not the error variable can be explicitly typed as `any`. By default, the use of explicit `any` is forbidden.
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"rxjs-x/no-implicit-any-catch": [
|
|
70
|
+
"error",
|
|
71
|
+
{ "allowExplicitAny": true }
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Further reading
|
|
77
|
+
|
|
78
|
+
- [Catching Unknowns](https://ncjamieson.com/catching-unknowns/)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Avoid importing index modules (`no-index`)
|
|
2
|
+
|
|
3
|
+
This rule effects failures if an index module is specified as the import location.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { of } from "rxjs/index";
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Examples of **correct** code for this rule:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { of } from "rxjs";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Options
|
|
20
|
+
|
|
21
|
+
This rule has no options.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Avoid importing internal modules (`no-internal`)
|
|
2
|
+
|
|
3
|
+
This rule effects failures if an internal module is specified as the import location.
|
|
4
|
+
|
|
5
|
+
## Rule details
|
|
6
|
+
|
|
7
|
+
Examples of **incorrect** code for this rule:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { of } from "rxjs/internal/observable/of";
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Examples of **correct** code for this rule:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { of } from "rxjs";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Options
|
|
20
|
+
|
|
21
|
+
This rule has no options.
|