eslint-plugin-rxjs-x 0.5.0 → 0.6.0

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.
@@ -19,6 +19,7 @@ This rule will report observable-valued statements that are not treated in one o
19
19
 
20
20
  > [!TIP]
21
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
22
23
 
23
24
  ## Rule details
24
25
 
@@ -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)
@@ -0,0 +1,37 @@
1
+ # Disallow calling of `subscribe` within any RxJS operator inside a `pipe` (`rxjs-x/no-subscribe-in-pipe`)
2
+
3
+ 💼 This rule is enabled in the following configs: ✅ `recommended`, 🔒 `strict`.
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 effects failures if `subscribe` is called within any operator inside a `pipe` operation.
10
+
11
+ ## Rule details
12
+
13
+ Examples of **incorrect** code for this rule:
14
+
15
+ ```ts
16
+ import { of } from "rxjs";
17
+ import { map } from "rxjs/operators";
18
+
19
+ of(42, 54).pipe(
20
+ map(value => {
21
+ of(value).subscribe(console.log); // This will trigger the rule
22
+ return value * 2;
23
+ })
24
+ ).subscribe(result => console.log(result));
25
+ ```
26
+
27
+ Examples of **correct** code for this rule:
28
+
29
+ ```ts
30
+ import { of } from "rxjs";
31
+ import { map, tap } from "rxjs/operators";
32
+
33
+ of(42, 54).pipe(
34
+ tap(value => console.log(value)),
35
+ map(value => value * 2)
36
+ ).subscribe(result => console.log(result));
37
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-rxjs-x",
3
3
  "type": "commonjs",
4
- "version": "0.5.0",
4
+ "version": "0.6.0",
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,
@@ -63,7 +65,7 @@
63
65
  "peerDependencies": {
64
66
  "eslint": "^8.57.0 || ^9.0.0",
65
67
  "rxjs": ">=7.2.0",
66
- "typescript": ">=4.7.4"
68
+ "typescript": ">=4.8.4"
67
69
  },
68
70
  "peerDependenciesMeta": {
69
71
  "rxjs": {
@@ -71,16 +73,16 @@
71
73
  }
72
74
  },
73
75
  "devDependencies": {
74
- "@eslint/js": "^9.14.0",
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.16.0",
80
+ "@typescript-eslint/rule-tester": "^8.17.0",
79
81
  "@typescript/vfs": "^1.6.0",
80
- "@vitest/coverage-v8": "^2.1.5",
81
- "@vitest/eslint-plugin": "^1.1.10",
82
+ "@vitest/coverage-v8": "^2.1.8",
83
+ "@vitest/eslint-plugin": "^1.1.14",
82
84
  "bumpp": "^9.8.1",
83
- "eslint": "^9.14.0",
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.16.0",
95
- "vitest": "^2.1.5"
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"