Skip to content

Commit

Permalink
Add test case for non-async function that returns Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
kaykdm committed Jan 22, 2025
1 parent a110c4f commit 1cb349f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ async function returnsPromise(): Promise<string> {
}
returnsPromise();
returnsPromise().then(() => { }).finally(() => { });


function returnsPromiseWithoutAsync(): Promise<string> {
return Promise.resolve("value")
}


returnsPromiseWithoutAsync()
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ async function returnsPromise(): Promise<string> {
returnsPromise();
returnsPromise().then(() => { }).finally(() => { });


function returnsPromiseWithoutAsync(): Promise<string> {
return Promise.resolve("value")
}


returnsPromiseWithoutAsync()
```

# Diagnostics
Expand Down Expand Up @@ -53,3 +60,20 @@ invalid.ts:5:1 lint/nursery/noFloatingPromises FIXABLE ━━━━━━━
│ ++++++
```

```
invalid.ts:13: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.
> 13 │ returnsPromiseWithoutAsync()
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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.
13 │ await·returnsPromiseWithoutAsync()
│ ++++++
```

0 comments on commit 1cb349f

Please sign in to comment.