Skip to content

Commit c5dc755

Browse files
alexanderceruttiJoshuaKGoldbergkirkwaiblinger
authored
docs: [no-floating-promises] clarify that void does not resolve promises (#9949)
* Improved no-floating-promises documentation * Changed silencing phrase * Moved rules report order to prioritize handling * Improved ignoreVoid warning * Removed handled/unhandled markers and added a bit on the next tip * Reverted tip edit * Added a paragraph about promises handling and improved the warning in ignoreVoid * Moved handling Promises paragraph up * Reworked a bit Handling Promises rejections * Removed Handling Promises rejection * Added link to mdn in the tip * Removed ref to handling promises rejection (not existing anymore) * Changed monospace comment in warning to link Co-authored-by: Josh Goldberg ✨ <[email protected]> * Typo fix Co-authored-by: Josh Goldberg ✨ <[email protected]> --------- Co-authored-by: Josh Goldberg ✨ <[email protected]> Co-authored-by: Kirk Waiblinger <[email protected]>
1 parent 1c183ab commit c5dc755

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

packages/eslint-plugin/docs/rules/no-floating-promises.mdx

+13-6
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ import TabItem from '@theme/TabItem';
1212
A "floating" Promise is one that is created without any code set up to handle any errors it might throw.
1313
Floating Promises can cause several issues, such as improperly sequenced operations, ignored Promise rejections, and more.
1414

15-
This rule reports when a Promise is created and not properly handled.
16-
Valid ways of handling a Promise-valued statement include:
15+
This rule will report Promise-valued statements that are not treated in one of the following ways:
1716

18-
- `await`ing it
19-
- `return`ing it
20-
- `void`ing it
2117
- Calling its `.then()` with two arguments
2218
- Calling its `.catch()` with one argument
19+
- `await`ing it
20+
- `return`ing it
21+
- [`void`ing it](#ignorevoid)
2322

2423
This rule also reports when an Array containing Promises is created and not properly handled. The main way to resolve this is by using one of the Promise concurrency methods to create a single Promise, then handling that according to the procedure above. These methods include:
2524

@@ -29,8 +28,10 @@ This rule also reports when an Array containing Promises is created and not prop
2928
- `Promise.race()`
3029

3130
:::tip
32-
`no-floating-promises` only detects unhandled Promise _statements_.
31+
`no-floating-promises` only detects apparently unhandled Promise _statements_.
3332
See [`no-misused-promises`](./no-misused-promises.mdx) for detecting code that provides Promises to _logical_ locations such as if statements.
33+
34+
See [_Using promises (error handling) on MDN_](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises#error_handling) for a detailed writeup on Promise error-handling.
3435
:::
3536

3637
## Examples
@@ -134,6 +135,12 @@ await createMyThenable();
134135
This option, which is `true` by default, allows you to stop the rule reporting promises consumed with the [`void` operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void).
135136
This can be a good way to explicitly mark a promise as intentionally not awaited.
136137

138+
:::warning
139+
Voiding a Promise doesn't handle it or change the runtime behavior.
140+
The outcome is just ignored, like disabling the rule with an [ESLint disable comment](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1).
141+
Such Promise rejections will still be unhandled.
142+
:::
143+
137144
Examples of **correct** code for this rule with `{ ignoreVoid: true }`:
138145

139146
```ts option='{ "ignoreVoid": true }' showPlaygroundButton

0 commit comments

Comments
 (0)