-
-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix some docs and enable the rule for JavaScript files
- Loading branch information
Showing
5 changed files
with
100 additions
and
14 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
5 changes: 5 additions & 0 deletions
5
crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.js
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,5 @@ | ||
async function returnsPromise() { | ||
return 'value'; | ||
} | ||
returnsPromise(); | ||
returnsPromise().then(() => { }).finally(() => { }); |
55 changes: 55 additions & 0 deletions
55
crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.js.snap
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,55 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: invalid.js | ||
--- | ||
# Input | ||
```jsx | ||
async function returnsPromise() { | ||
return 'value'; | ||
} | ||
returnsPromise(); | ||
returnsPromise().then(() => { }).finally(() => { }); | ||
|
||
``` | ||
|
||
# Diagnostics | ||
``` | ||
invalid.js:4:1 lint/nursery/noFloatingPromises FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! A "floating" Promise was found, meaning it is not properly handled and could lead to ignored errors or unexpected behavior. | ||
2 │ return 'value'; | ||
3 │ } | ||
> 4 │ returnsPromise(); | ||
│ ^^^^^^^^^^^^^^^^^ | ||
5 │ returnsPromise().then(() => { }).finally(() => { }); | ||
6 │ | ||
i This happens when a Promise is not awaited, lacks a `.catch` or `.then` rejection handler, or is not explicitly ignored using the `void` operator. | ||
i Safe fix: Add await operator. | ||
4 │ await·returnsPromise(); | ||
│ ++++++ | ||
``` | ||
|
||
``` | ||
invalid.js:5:1 lint/nursery/noFloatingPromises FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ | ||
! A "floating" Promise was found, meaning it is not properly handled and could lead to ignored errors or unexpected behavior. | ||
3 │ } | ||
4 │ returnsPromise(); | ||
> 5 │ returnsPromise().then(() => { }).finally(() => { }); | ||
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
6 │ | ||
i This happens when a Promise is not awaited, lacks a `.catch` or `.then` rejection handler, or is not explicitly ignored using the `void` operator. | ||
i Safe fix: Add await operator. | ||
5 │ await·returnsPromise().then(()·=>·{·}).finally(()·=>·{·}); | ||
│ ++++++ | ||
``` |
14 changes: 14 additions & 0 deletions
14
crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/valid.js
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,14 @@ | ||
async function returnsPromise() { | ||
return 'value'; | ||
} | ||
|
||
await returnsPromise(); | ||
void returnsPromise(); | ||
return returnsPromise(); | ||
|
||
returnsPromise().then( | ||
() => { }, | ||
() => { }, | ||
); | ||
|
||
returnsPromise().catch(() => { }); |
21 changes: 21 additions & 0 deletions
21
crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/valid.js.snap
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,21 @@ | ||
--- | ||
source: crates/biome_js_analyze/tests/spec_tests.rs | ||
expression: valid.js | ||
--- | ||
# Input | ||
```jsx | ||
async function returnsPromise() { | ||
return 'value'; | ||
} | ||
|
||
await returnsPromise(); | ||
void returnsPromise(); | ||
return returnsPromise(); | ||
|
||
returnsPromise().then( | ||
() => { }, | ||
() => { }, | ||
); | ||
|
||
returnsPromise().catch(() => { }); | ||
``` |