eslint-plugin-rxjs-x 0.4.1 → 0.5.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/README.md +7 -5
- package/dist/index.d.mts +24 -2
- package/dist/index.d.ts +24 -2
- package/dist/index.js +537 -65
- package/dist/index.mjs +551 -79
- package/docs/rules/no-floating-observables.md +48 -0
- package/docs/rules/no-misused-observables.md +85 -0
- package/docs/rules/no-topromise.md +1 -1
- package/docs/rules/prefer-observer.md +1 -1
- package/docs/rules/prefer-root-operators.md +1 -1
- package/docs/rules/throw-error.md +1 -1
- package/package.json +11 -9
- package/docs/rules/no-ignored-observable.md +0 -25
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Require Observables to be handled appropriately (`rxjs-x/no-floating-observables`)
|
|
2
|
+
|
|
3
|
+
💼 This rule is enabled in the 🔒 `strict` config.
|
|
4
|
+
|
|
5
|
+
💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting).
|
|
6
|
+
|
|
7
|
+
<!-- end auto-generated rule header -->
|
|
8
|
+
|
|
9
|
+
A "floating" observable is one that is created without any code set up to handle any errors it might emit.
|
|
10
|
+
Like a floating Promise, floating observables can cause several issues, such as ignored errors, unhandled cold observables, and more.
|
|
11
|
+
|
|
12
|
+
This rule is like [no-floating-promises](https://typescript-eslint.io/rules/no-floating-promises/) but for Observables.
|
|
13
|
+
This rule will report observable-valued statements that are not treated in one of the following ways:
|
|
14
|
+
|
|
15
|
+
- Calling its `.subscribe()`
|
|
16
|
+
- `return`ing it
|
|
17
|
+
- Wrapping it in `lastValueFrom` or `firstValueFrom` and `await`ing it
|
|
18
|
+
- [`void`ing it](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void)
|
|
19
|
+
|
|
20
|
+
> [!TIP]
|
|
21
|
+
> `no-floating-observables` only detects apparently unhandled observable _statements_.
|
|
22
|
+
> See [`no-misused-observables`](./no-misused-observables.md) for detecting code that provides observables to _logical_ locations
|
|
23
|
+
|
|
24
|
+
## Rule details
|
|
25
|
+
|
|
26
|
+
Examples of **incorrect** code for this rule:
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { of } from "rxjs";
|
|
30
|
+
of(42, 54);
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Examples of **correct** code for this rule:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { of } from "rxjs";
|
|
37
|
+
const answers = of(42, 54);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Options
|
|
41
|
+
|
|
42
|
+
<!-- begin auto-generated rule options list -->
|
|
43
|
+
|
|
44
|
+
| Name | Description | Type | Default |
|
|
45
|
+
| :----------- | :------------------------------------ | :------ | :------ |
|
|
46
|
+
| `ignoreVoid` | Whether to ignore `void` expressions. | Boolean | `true` |
|
|
47
|
+
|
|
48
|
+
<!-- end auto-generated rule options list -->
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Disallow Observables in places not designed to handle them (`rxjs-x/no-misused-observables`)
|
|
2
|
+
|
|
3
|
+
💼 This rule is enabled in the 🔒 `strict` config.
|
|
4
|
+
|
|
5
|
+
💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting).
|
|
6
|
+
|
|
7
|
+
<!-- end auto-generated rule header -->
|
|
8
|
+
|
|
9
|
+
This rule forbids providing observables to logical locations where the TypeScript compiler allows them but they are not handled properly.
|
|
10
|
+
These situations can often arise due to a misunderstanding of the way observables are handled.
|
|
11
|
+
|
|
12
|
+
> [!TIP]
|
|
13
|
+
> `no-misused-observables` only detects code that provides observables to incorrect _logical_ locations.
|
|
14
|
+
> See [`no-floating-observables`](./no-floating-observables.md) for detecting unhandled observable _statements_.
|
|
15
|
+
|
|
16
|
+
This rule is like [no-misused-promises](https://typescript-eslint.io/rules/no-misused-promises) but for Observables.
|
|
17
|
+
|
|
18
|
+
> [!NOTE]
|
|
19
|
+
> Unlike `@typescript-eslint/no-misused-promises`, this rule does not check conditionals like `if` statements.
|
|
20
|
+
> Use `@typescript-eslint/no-unnecessary-condition` for linting those situations.
|
|
21
|
+
|
|
22
|
+
## Rule details
|
|
23
|
+
|
|
24
|
+
Examples of **incorrect** code for this rule:
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { of } from "rxjs";
|
|
28
|
+
|
|
29
|
+
[1, 2, 3].forEach(i => of(i));
|
|
30
|
+
|
|
31
|
+
interface MySyncInterface {
|
|
32
|
+
foo(): void;
|
|
33
|
+
}
|
|
34
|
+
class MyRxClass implements MySyncInterface {
|
|
35
|
+
foo(): Observable<number> {
|
|
36
|
+
return of(42);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const a = of(42);
|
|
41
|
+
const b = { ...b };
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Examples of **correct** code for this rule:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { of } from "rxjs";
|
|
48
|
+
|
|
49
|
+
[1, 2, 3].map(i => of(i));
|
|
50
|
+
|
|
51
|
+
interface MyRxInterface {
|
|
52
|
+
foo(): Observable<number>;
|
|
53
|
+
}
|
|
54
|
+
class MyRxClass implements MyRxInterface {
|
|
55
|
+
foo(): Observable<number> {
|
|
56
|
+
return of(42);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Options
|
|
62
|
+
|
|
63
|
+
<!-- WARNING: not auto-generated! -->
|
|
64
|
+
|
|
65
|
+
| Name | Description | Type | Default |
|
|
66
|
+
| :----------------- | :-------------------------------------------------------------------------- | :------ | :------ |
|
|
67
|
+
| `checksSpreads` | Disallow `...` spreading an Observable. | Boolean | `true` |
|
|
68
|
+
| `checksVoidReturn` | Disallow returning an Observable from a function typed as returning `void`. | Object | `true` |
|
|
69
|
+
|
|
70
|
+
### `checksVoidReturn`
|
|
71
|
+
|
|
72
|
+
You can disable selective parts of the `checksVoidReturn` option. The following sub-options are supported:
|
|
73
|
+
|
|
74
|
+
| Name | Description | Type | Default |
|
|
75
|
+
| :----------------- | :--------------------------------------------------------------------------------------------------------------------------------------- | :------ | :------ |
|
|
76
|
+
| `arguments` | Disallow passing an Observable-returning function as an argument where the parameter type expects a function that returns `void`. | Boolean | `true` |
|
|
77
|
+
| `attributes` | Disallow passing an Observable-returning function as a JSX attribute expected to be a function that returns `void`. | Boolean | `true` |
|
|
78
|
+
| `inheritedMethods` | Disallow providing an Observable-returning function where a function that returns `void` is expected by an extended or implemented type. | Boolean | `true` |
|
|
79
|
+
| `properties` | Disallow providing an Observable-returning function where a function that returns `void` is expected by a property. | Boolean | `true` |
|
|
80
|
+
| `returns` | Disallow returning an Observable-returning function where a function that returns `void` is expected. | Boolean | `true` |
|
|
81
|
+
| `variables` | Disallow assigning or declaring an Observable-returning function where a function that returns `void` is expected. | Boolean | `true` |
|
|
82
|
+
|
|
83
|
+
## Further reading
|
|
84
|
+
|
|
85
|
+
- [TypeScript void function assignability](https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-functions-returning-non-void-assignable-to-function-returning-void)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Disallow use of the `toPromise` method (`rxjs-x/no-topromise`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the 🔒 `strict
|
|
3
|
+
💼 This rule is enabled in the following configs: ✅ `recommended`, 🔒 `strict`.
|
|
4
4
|
|
|
5
5
|
💡 This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Disallow passing separate handlers to `subscribe` and `tap` (`rxjs-x/prefer-observer`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the 🔒 `strict
|
|
3
|
+
💼 This rule is enabled in the following configs: ✅ `recommended`, 🔒 `strict`.
|
|
4
4
|
|
|
5
5
|
🔧💡 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Disallow importing operators from `rxjs/operators` (`rxjs-x/prefer-root-operators`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the 🔒 `strict
|
|
3
|
+
💼 This rule is enabled in the following configs: ✅ `recommended`, 🔒 `strict`.
|
|
4
4
|
|
|
5
5
|
🔧💡 This rule is automatically fixable by the [`--fix` CLI option](https://eslint.org/docs/latest/user-guide/command-line-interface#--fix) and manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Enforce passing only `Error` values to `throwError` (`rxjs-x/throw-error`)
|
|
2
2
|
|
|
3
|
-
💼 This rule is enabled in the 🔒 `strict
|
|
3
|
+
💼 This rule is enabled in the following configs: ✅ `recommended`, 🔒 `strict`.
|
|
4
4
|
|
|
5
5
|
💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting).
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-rxjs-x",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"packageManager": "yarn@4.5.3+sha512.3003a14012e2987072d244c720506549c1aab73ee728208f1b2580a9fd67b92d61ba6b08fe93f6dce68fd771e3af1e59a0afa28dd242dd0940d73b95fedd4e90",
|
|
6
6
|
"description": "ESLint v9+ plugin for RxJS",
|
|
7
7
|
"author": "Jason Weinzierl <weinzierljason@gmail.com>",
|
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
"lint",
|
|
19
19
|
"rules",
|
|
20
20
|
"eslint",
|
|
21
|
+
"eslintplugin",
|
|
22
|
+
"eslint-plugin",
|
|
21
23
|
"rxjs"
|
|
22
24
|
],
|
|
23
25
|
"sideEffects": false,
|
|
@@ -62,7 +64,7 @@
|
|
|
62
64
|
},
|
|
63
65
|
"peerDependencies": {
|
|
64
66
|
"eslint": "^8.57.0 || ^9.0.0",
|
|
65
|
-
"rxjs": ">=7.
|
|
67
|
+
"rxjs": ">=7.2.0",
|
|
66
68
|
"typescript": ">=4.7.4"
|
|
67
69
|
},
|
|
68
70
|
"peerDependenciesMeta": {
|
|
@@ -71,16 +73,16 @@
|
|
|
71
73
|
}
|
|
72
74
|
},
|
|
73
75
|
"devDependencies": {
|
|
74
|
-
"@eslint/js": "^9.
|
|
76
|
+
"@eslint/js": "^9.16.0",
|
|
75
77
|
"@stylistic/eslint-plugin": "^2.11.0",
|
|
76
78
|
"@types/common-tags": "^1.8.4",
|
|
77
79
|
"@types/node": "~18.18.0",
|
|
78
|
-
"@typescript-eslint/rule-tester": "^8.
|
|
80
|
+
"@typescript-eslint/rule-tester": "^8.17.0",
|
|
79
81
|
"@typescript/vfs": "^1.6.0",
|
|
80
|
-
"@vitest/coverage-v8": "^2.1.
|
|
81
|
-
"@vitest/eslint-plugin": "^1.1.
|
|
82
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
83
|
+
"@vitest/eslint-plugin": "^1.1.14",
|
|
82
84
|
"bumpp": "^9.8.1",
|
|
83
|
-
"eslint": "^9.
|
|
85
|
+
"eslint": "^9.16.0",
|
|
84
86
|
"eslint-config-flat-gitignore": "^0.3.0",
|
|
85
87
|
"eslint-doc-generator": "^1.7.1",
|
|
86
88
|
"eslint-import-resolver-typescript": "^3.6.3",
|
|
@@ -91,8 +93,8 @@
|
|
|
91
93
|
"rxjs": "^7.8.1",
|
|
92
94
|
"tsup": "^8.3.5",
|
|
93
95
|
"typescript": "~5.7.2",
|
|
94
|
-
"typescript-eslint": "^8.
|
|
95
|
-
"vitest": "^2.1.
|
|
96
|
+
"typescript-eslint": "^8.17.0",
|
|
97
|
+
"vitest": "^2.1.8"
|
|
96
98
|
},
|
|
97
99
|
"engines": {
|
|
98
100
|
"node": "^18.18.0 || ^20.9.0 || >= 21.1.0"
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# Disallow ignoring observables returned by functions (`rxjs-x/no-ignored-observable`)
|
|
2
|
-
|
|
3
|
-
💼 This rule is enabled in the 🔒 `strict` config.
|
|
4
|
-
|
|
5
|
-
💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting).
|
|
6
|
-
|
|
7
|
-
<!-- end auto-generated rule header -->
|
|
8
|
-
|
|
9
|
-
The effects failures if an observable returned by a function is neither assigned to a variable or property or passed to a function.
|
|
10
|
-
|
|
11
|
-
## Rule details
|
|
12
|
-
|
|
13
|
-
Examples of **incorrect** code for this rule:
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
import { of } from "rxjs";
|
|
17
|
-
of(42, 54);
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
Examples of **correct** code for this rule:
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
import { of } from "rxjs";
|
|
24
|
-
const answers = of(42, 54);
|
|
25
|
-
```
|