Skip to content

Commit f4b16eb

Browse files
docs: when not to use each rule (#91)
Adds useful documentation like typescript-eslint's **When Not To Use It** section to each rule. This also cleans up or expands on various existing rule documentation. This also adds a **Resources** section to each rule linking to the rule source and unit tests. This also tries to link related rules together in a **Related To** section. Resolves #67
1 parent bf783c6 commit f4b16eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+623
-14
lines changed

docs/rules/ban-observables.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
<!-- end auto-generated rule header -->
44

5-
This rule can be configured so that developers can ban any observable creators they want to avoid in their project.
5+
It can sometimes be useful to ban specific `rxjs` imports.
6+
This rule can be configured to ban a list of specific `rxjs` imports developers want to avoid in their project.
7+
8+
> [!TIP]
9+
> `ban-observables` only bans at the _import_ site. (In fact, it can ban anything imported from `rxjs`.)
10+
> See [`ban-operators`](./ban-operators.md) for banning operators at their _usage_.
611
712
## Options
813

9-
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.
14+
This rule accepts a single option which is an object the keys of which are the names of anything in `rxjs` and the values are either booleans or strings containing the explanation for the ban.
1015

1116
The following configuration bans `partition` and `onErrorResumeNext`:
1217

@@ -22,3 +27,16 @@ The following configuration bans `partition` and `onErrorResumeNext`:
2227
]
2328
}
2429
```
30+
31+
## When Not To Use It
32+
33+
If you have no need to ban importing anything from `rxjs`, you don't need this rule.
34+
35+
## Related To
36+
37+
- [`ban-operators`](./ban-operators.md)
38+
39+
## Resources
40+
41+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/ban-observables.ts)
42+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/ban-observables.test.ts)

docs/rules/ban-operators.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
<!-- end auto-generated rule header -->
66

7-
This rule can be configured so that developers can ban any operators they want to avoid in their project.
7+
This rule can be configured so that developers can ban `rxjs` operators they want to avoid in their project.
8+
9+
> [!NOTE]
10+
> Operators outside of a `pipe` or not directly exported by `rxjs` are ignored.
811
912
## Options
1013

@@ -23,3 +26,19 @@ The following configuration bans `partition` and `onErrorResumeNext`:
2326
}
2427
]
2528
}
29+
```
30+
31+
## When Not To Use It
32+
33+
If you have no need to ban `rxjs` operators, you don't need this rule.
34+
35+
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.
36+
37+
## Related To
38+
39+
- [`ban-observables`](./ban-observables.md)
40+
41+
## Resources
42+
43+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/ban-operators.ts)
44+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/ban-operators.test.ts)

docs/rules/finnish.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,24 @@ The default (Angular-friendly) configuration looks like this:
6868

6969
The properties in the options object are themselves optional; they do not all have to be specified.
7070

71+
## When Not To Use It
72+
73+
If you don't use Finnish notation in your project or don't care about enforcing Finnish notation in your project, you don't need this rule.
74+
However, keep in mind that inconsistent style can harm readability in a project;
75+
consider using [`no-finnish`](./no-finnish.md) to ban Finnish notation if you don't use it in your project.
76+
77+
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.
78+
7179
## Further reading
7280

7381
- [Observables and Finnish Notation](https://medium.com/@benlesh/observables-and-finnish-notation-df8356ed1c9b)
82+
83+
## Related To
84+
85+
- [`no-finnish`](./no-finnish.md)
86+
- [`suffix-subjects`](./suffix-subjects.md)
87+
88+
## Resources
89+
90+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/finnish.ts)
91+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/finnish.test.ts)

docs/rules/just.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@
66

77
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.
88

9+
## When Not To Use It
10+
11+
If you prefer `of` in your project, you will want to avoid this rule.
12+
913
## Further reading
1014

1115
- [Rename `of` to `just`](https://github.com/ReactiveX/rxjs/issues/3747)
16+
17+
## Resources
18+
19+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/just.ts)
20+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/just.test.ts)

docs/rules/no-async-subscribe.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,19 @@ of(42).pipe(
3636
).subscribe(data2 => console.log(data2));
3737
```
3838

39+
## When Not To Use It
40+
41+
If you don't care about avoiding `.subscribe(async...`, then you will not need this rule.
42+
However, keep in mind that features of observables like cancellation or retrying will not work, and race conditions may occur.
43+
44+
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.
45+
3946
## Further reading
4047

4148
- [Why does this rule exist?](https://stackoverflow.com/q/71559135)
4249
- [Higher-order Observables](https://rxjs.dev/guide/higher-order-observables)
50+
51+
## Resources
52+
53+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/no-async-subscribe.ts)
54+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/no-async-subscribe.test.ts)

docs/rules/no-connectable.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,30 @@
44

55
<!-- end auto-generated rule header -->
66

7-
This rule prevents the use of connectable observables.
7+
This rule prevents the use of operators that return connectable observables.
8+
9+
> [!NOTE]
10+
> All operators banned by this rule are also deprecated by RxJS,
11+
> so this rule may be removed in a future major version.
12+
13+
## Rule details
14+
15+
Examples of **incorrect** code for this rule:
16+
17+
```ts
18+
import { of, publish } from "rxjs";
19+
20+
const result = of(42).pipe(publish());
21+
```
22+
23+
## When Not To Use It
24+
25+
If you use operators that return connectable observables in your project, you may not need this rule.
26+
Or you may rely on RxJS's deprecation of those operators and don't need to double-flag the operators as banned.
27+
28+
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.
29+
30+
## Resources
31+
32+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/no-connectable.ts)
33+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/no-connectable.test.ts)

docs/rules/no-create.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,15 @@ const answers = new Observable<number>(subscriber => {
2929
subscriber.complete();
3030
});
3131
```
32+
33+
## When Not To Use It
34+
35+
If you rely on RxJS's deprecation of `Observable.create` and don't need to double-flag usage,
36+
then you don't need this rule.
37+
38+
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.
39+
40+
## Resources
41+
42+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/no-create.ts)
43+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/no-create.test.ts)

docs/rules/no-cyclic-action.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,17 @@ This rule accepts a single option which is an object with an `observable` proper
7272
]
7373
}
7474
```
75+
76+
## When Not To Use It
77+
78+
If you don't use a library with effects and epics (e.g. NgRx or redux-observable),
79+
then you don't need this rule.
80+
Alternatively, if you use NgRx's own [`avoid-cyclic-effects`](https://ngrx.io/guide/eslint-plugin/rules/avoid-cyclic-effects) rule,
81+
then you don't need this rule.
82+
83+
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.
84+
85+
## Resources
86+
87+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/no-cyclic-action.ts)
88+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/no-cyclic-action.test.ts)

docs/rules/no-explicit-generics.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ import { BehaviorSubject } from "rxjs";
2020
const subject = new BehaviorSubject(42);
2121
```
2222

23-
## Known problems
23+
## When Not To Use It
24+
25+
This rule has known problems in the latest release:
2426

2527
- ([#77](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/issues/77)) Type unions cause false positives e.g. `new BehaviorSubject<number | null>(null)` will be incorrectly caught by this rule.
28+
29+
## Resources
30+
31+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/no-explicit-generics.ts)
32+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/no-explicit-generics.test.ts)

docs/rules/no-exposed-subjects.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ Examples of **correct** code for this rule:
2323

2424
```ts
2525
import { Subject } from "rxjs";
26+
2627
class Answers {
27-
private _answers: Subject<string>;
28-
get answers() {
29-
return this._answers.asObservable();
28+
private answersSubject$ = new Subject<string>();
29+
public answers$ = this.answersSubject$.asObservable();
30+
31+
public nextAnswer(a: string) {
32+
this.answersSubject$.next(a);
3033
}
3134
}
3235
```
@@ -51,3 +54,15 @@ This rule accepts a single option which is an object with an `allowProtected` pr
5154
]
5255
}
5356
```
57+
58+
## When Not To Use It
59+
60+
If you don't care about encapsulating subjects in your project, then you don't need this rule.
61+
However, be aware that anyone can call `next()` or `complete()` on the exposed subject, which may cause bugs or less readable code.
62+
63+
Type checked lint rules are more powerful than traditional lint rules, but also require configuring type checked linting.
64+
65+
## Resources
66+
67+
- [Rule source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/src/rules/no-exposed-subjects.ts)
68+
- [Test source](https://github.com/JasonWeinzierl/eslint-plugin-rxjs-x/blob/main/tests/rules/no-exposed-subjects.test.ts)

0 commit comments

Comments
 (0)