Skip to content

Commit fa3f2c5

Browse files
feat(no-floating-observables)!: rename rule
1 parent 6472c63 commit fa3f2c5

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ The package includes the following rules.
8888
| [no-explicit-generics](docs/rules/no-explicit-generics.md) | Disallow unnecessary explicit generic type arguments. | 🔒 | | | | |
8989
| [no-exposed-subjects](docs/rules/no-exposed-subjects.md) | Disallow public and protected subjects. | 🔒 | | | 💭 | |
9090
| [no-finnish](docs/rules/no-finnish.md) | Disallow Finnish notation. | | | | 💭 | |
91+
| [no-floating-observables](docs/rules/no-floating-observables.md) | Require Observables to be handled appropriately. | 🔒 | | | 💭 | |
9192
| [no-ignored-default-value](docs/rules/no-ignored-default-value.md) | Disallow using `firstValueFrom`, `lastValueFrom`, `first`, and `last` without specifying a default value. | 🔒 | | | 💭 | |
9293
| [no-ignored-error](docs/rules/no-ignored-error.md) | Disallow calling `subscribe` without specifying an error handler. | 🔒 | | | 💭 | |
9394
| [no-ignored-notifier](docs/rules/no-ignored-notifier.md) | Disallow observables not composed from the `repeatWhen` or `retryWhen` notifier. | ✅ 🔒 | | | 💭 | |
94-
| [no-ignored-observable](docs/rules/no-ignored-observable.md) | Disallow ignoring observables returned by functions. | 🔒 | | | 💭 | |
9595
| [no-ignored-replay-buffer](docs/rules/no-ignored-replay-buffer.md) | Disallow using `ReplaySubject`, `publishReplay` or `shareReplay` without specifying the buffer size. | ✅ 🔒 | | | | |
9696
| [no-ignored-subscribe](docs/rules/no-ignored-subscribe.md) | Disallow calling `subscribe` without specifying arguments. | | | | 💭 | |
9797
| [no-ignored-subscription](docs/rules/no-ignored-subscription.md) | Disallow ignoring the subscription returned by `subscribe`. | | | | 💭 | |

docs/rules/no-ignored-observable.md renamed to docs/rules/no-floating-observables.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
# Disallow ignoring observables returned by functions (`rxjs-x/no-ignored-observable`)
1+
# Require Observables to be handled appropriately (`rxjs-x/no-floating-observables`)
22

33
💼 This rule is enabled in the 🔒 `strict` config.
44

55
💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting).
66

77
<!-- end auto-generated rule header -->
88

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-
This rule is like [no-floating-promises](https://typescript-eslint.io/rules/no-floating-promises/) but for Observables.
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.
1111

12-
This rule will report Observable-valued statements that are not treated in one of the following ways:
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:
1314

1415
- Calling its `.subscribe()`
1516
- `return`ing it
1617
- Wrapping it in `lastValueFrom` or `firstValueFrom` and `await`ing it
1718
- [`void`ing it](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void)
1819

1920
> [!TIP]
20-
> `no-ignored-observable` only detects apparently unhandled Observable _statements_.
21+
> `no-ignored-observable` only detects apparently unhandled observable _statements_.
2122
2223
## Rule details
2324

src/configs/strict.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export const createStrictConfig = (
1111
'rxjs-x/no-create': 'error',
1212
'rxjs-x/no-explicit-generics': 'error',
1313
'rxjs-x/no-exposed-subjects': 'error',
14+
'rxjs-x/no-floating-observables': 'error',
1415
'rxjs-x/no-ignored-default-value': 'error',
1516
'rxjs-x/no-ignored-error': 'error',
1617
'rxjs-x/no-ignored-notifier': 'error',
17-
'rxjs-x/no-ignored-observable': 'error',
1818
'rxjs-x/no-ignored-replay-buffer': 'error',
1919
'rxjs-x/no-ignored-takewhile-value': 'error',
2020
'rxjs-x/no-implicit-any-catch': ['error', {

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import { noCyclicActionRule } from './rules/no-cyclic-action';
1616
import { noExplicitGenericsRule } from './rules/no-explicit-generics';
1717
import { noExposedSubjectsRule } from './rules/no-exposed-subjects';
1818
import { noFinnishRule } from './rules/no-finnish';
19+
import { noFloatingObservablesRule } from './rules/no-floating-observables';
1920
import { noIgnoredDefaultValueRule } from './rules/no-ignored-default-value';
2021
import { noIgnoredErrorRule } from './rules/no-ignored-error';
2122
import { noIgnoredNotifierRule } from './rules/no-ignored-notifier';
22-
import { noIgnoredObservableRule } from './rules/no-ignored-observable';
2323
import { noIgnoredReplayBufferRule } from './rules/no-ignored-replay-buffer';
2424
import { noIgnoredSubscribeRule } from './rules/no-ignored-subscribe';
2525
import { noIgnoredSubscriptionRule } from './rules/no-ignored-subscription';
@@ -63,10 +63,10 @@ const plugin = {
6363
'no-explicit-generics': noExplicitGenericsRule,
6464
'no-exposed-subjects': noExposedSubjectsRule,
6565
'no-finnish': noFinnishRule,
66+
'no-floating-observables': noFloatingObservablesRule,
6667
'no-ignored-default-value': noIgnoredDefaultValueRule,
6768
'no-ignored-error': noIgnoredErrorRule,
6869
'no-ignored-notifier': noIgnoredNotifierRule,
69-
'no-ignored-observable': noIgnoredObservableRule,
7070
'no-ignored-replay-buffer': noIgnoredReplayBufferRule,
7171
'no-ignored-subscribe': noIgnoredSubscribeRule,
7272
'no-ignored-subscription': noIgnoredSubscriptionRule,

src/rules/no-ignored-observable.ts renamed to src/rules/no-floating-observables.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@ import { TSESTree as es } from '@typescript-eslint/utils';
22
import { getTypeServices } from '../etc';
33
import { ruleCreator } from '../utils';
44

5-
export const noIgnoredObservableRule = ruleCreator({
5+
export const noFloatingObservablesRule = ruleCreator({
66
defaultOptions: [],
77
meta: {
88
docs: {
9-
description: 'Disallow ignoring observables returned by functions.',
9+
description: 'Require Observables to be handled appropriately.',
1010
recommended: 'strict',
1111
requiresTypeChecking: true,
1212
},
1313
messages: {
14-
forbidden: 'Ignoring a returned Observable is forbidden.',
14+
forbidden:
15+
'Observables must be subscribed to, returned, converted to a promise and awaited, '
16+
+ 'or be explicitly marked as ignored with the `void` operator.',
1517
},
1618
schema: [],
1719
type: 'problem',
1820
},
19-
name: 'no-ignored-observable',
21+
name: 'no-floating-observables',
2022
create: (context) => {
2123
const { couldBeObservable } = getTypeServices(context);
2224

tests/rules/no-ignored-observable.test.ts renamed to tests/rules/no-floating-observables.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { stripIndent } from 'common-tags';
2-
import { noIgnoredObservableRule } from '../../src/rules/no-ignored-observable';
2+
import { noFloatingObservablesRule } from '../../src/rules/no-floating-observables';
33
import { fromFixture } from '../etc';
44
import { ruleTester } from '../rule-tester';
55

6-
ruleTester({ types: true }).run('no-ignored-observable', noIgnoredObservableRule, {
6+
ruleTester({ types: true }).run('no-floating-observables', noFloatingObservablesRule, {
77
valid: [
88
stripIndent`
99
// not ignored

0 commit comments

Comments
 (0)