You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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]>
Copy file name to clipboardExpand all lines: packages/eslint-plugin/docs/rules/no-floating-promises.mdx
+13-6
Original file line number
Diff line number
Diff line change
@@ -12,14 +12,13 @@ import TabItem from '@theme/TabItem';
12
12
A "floating" Promise is one that is created without any code set up to handle any errors it might throw.
13
13
Floating Promises can cause several issues, such as improperly sequenced operations, ignored Promise rejections, and more.
14
14
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:
17
16
18
-
-`await`ing it
19
-
-`return`ing it
20
-
-`void`ing it
21
17
- Calling its `.then()` with two arguments
22
18
- Calling its `.catch()` with one argument
19
+
-`await`ing it
20
+
-`return`ing it
21
+
-[`void`ing it](#ignorevoid)
23
22
24
23
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:
25
24
@@ -29,8 +28,10 @@ This rule also reports when an Array containing Promises is created and not prop
29
28
-`Promise.race()`
30
29
31
30
:::tip
32
-
`no-floating-promises` only detects unhandled Promise _statements_.
31
+
`no-floating-promises` only detects apparently unhandled Promise _statements_.
33
32
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.
34
35
:::
35
36
36
37
## Examples
@@ -134,6 +135,12 @@ await createMyThenable();
134
135
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).
135
136
This can be a good way to explicitly mark a promise as intentionally not awaited.
136
137
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
+
137
144
Examples of **correct** code for this rule with `{ ignoreVoid: true }`:
0 commit comments