forked from cartant/eslint-plugin-rxjs
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(no-ignored-default-value): new rule for enforcing defaultValue (#15
) Introduces a new rule that enforces `defaultValue` to be passed into `firstValueFrom`, `lastValueFrom`, `first`, and `last`, in order to prevent `EmptyError`. Resolves upstream cartant#126
- Loading branch information
1 parent
994ff25
commit 9bd896e
Showing
6 changed files
with
358 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Disallow using `firstValueFrom`, `lastValueFrom`, `first`, and `last` without specifying a default value (`rxjs-x/no-ignored-default-value`) | ||
|
||
💭 This rule requires [type information](https://typescript-eslint.io/linting/typed-linting). | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
This rule prevents `EmptyError` rejections if there were no emissions from `firstValueFrom`, `lastValueFrom`, `first`, or `last` by requiring `defaultValue`. | ||
|
||
## Rule details | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```ts | ||
import { Subject, firstValueFrom } from "rxjs"; | ||
|
||
const sub = new Subject(); | ||
const result = firstValueFrom(sub); | ||
sub.complete(); | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```ts | ||
import { Subject, firstValueFrom } from "rxjs"; | ||
|
||
const sub = new Subject(); | ||
const result = firstValueFrom(sub, { defaultValue: null }); | ||
sub.complete(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.