-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [no-floating-promises] flag result of .map(async) #7897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JoshuaKGoldberg
merged 17 commits into
typescript-eslint:main
from
kirkwaiblinger:arrays-of-promises
Dec 29, 2023
+238
−13
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c37f343
flag arrays of promises
kirkwaiblinger 0244ccd
remove comment
kirkwaiblinger a69fe00
trying to trigger CI
kirkwaiblinger 8fd0773
Substantial simplification
kirkwaiblinger ea23d54
add some grody test cases for generics
kirkwaiblinger a486da2
flip if/else
kirkwaiblinger 8ee0d64
add detail to test case
kirkwaiblinger 2afe794
switch to isArrayLikeType
kirkwaiblinger 6335820
Revert "switch to isArrayLikeType"
kirkwaiblinger 852990e
add checks for tuples
kirkwaiblinger 8c9eadc
One more test case!
kirkwaiblinger 6498556
else if
kirkwaiblinger 8c1f526
Remove unnecessary whitespace
kirkwaiblinger 7817e8a
Remove invalid test case
kirkwaiblinger 81ced8a
Add to docs
kirkwaiblinger d14de70
Add test cases around array that's fine but tuple that isn't
kirkwaiblinger 428b976
tweaks
kirkwaiblinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
JoshuaKGoldberg marked this conversation as resolved.
Show resolved
Hide resolved
JoshuaKGoldberg marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -222,7 +222,7 @@ async function test() { | |
` | ||
async function test() { | ||
class Thenable { | ||
then(callback: () => {}): Thenable { | ||
then(callback: () => void): Thenable { | ||
return new Thenable(); | ||
} | ||
} | ||
|
@@ -264,7 +264,7 @@ async function test() { | |
` | ||
async function test() { | ||
class CatchableThenable { | ||
then(callback: () => {}, callback: () => {}): CatchableThenable { | ||
then(callback: () => void, callback: () => void): CatchableThenable { | ||
return new CatchableThenable(); | ||
} | ||
} | ||
|
@@ -475,6 +475,35 @@ Promise.reject() | |
.finally(() => {}); | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
await Promise.all([Promise.resolve(), Promise.resolve()]); | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
declare const promiseArray: Array<Promise<unknown>>; | ||
void promiseArray; | ||
`, | ||
}, | ||
{ | ||
code: ` | ||
[Promise.reject(), Promise.reject()].then(() => {}); | ||
`, | ||
}, | ||
{ | ||
// Expressions aren't checked by this rule, so this just becomes an array | ||
// of number | undefined, which is fine regardless of the ignoreVoid setting. | ||
code: ` | ||
[1, 2, void Promise.reject(), 3]; | ||
`, | ||
options: [{ ignoreVoid: false }], | ||
}, | ||
{ | ||
code: ` | ||
['I', 'am', 'just', 'an', 'array']; | ||
`, | ||
}, | ||
], | ||
|
||
invalid: [ | ||
|
@@ -997,7 +1026,7 @@ async function test() { | |
code: ` | ||
async function test() { | ||
class CatchableThenable { | ||
then(callback: () => {}, callback: () => {}): CatchableThenable { | ||
then(callback: () => void, callback: () => void): CatchableThenable { | ||
return new CatchableThenable(); | ||
} | ||
} | ||
|
@@ -1651,5 +1680,131 @@ Promise.reject(new Error('message')).finally(() => {}); | |
`, | ||
errors: [{ line: 2, messageId: 'floatingVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
function _<T, S extends Array<T | Promise<T>>>( | ||
maybePromiseArray: S | undefined, | ||
): void { | ||
maybePromiseArray?.[0]; | ||
} | ||
`, | ||
errors: [{ line: 5, messageId: 'floatingVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
[1, 2, 3].map(() => Promise.reject()); | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
declare const array: unknown[]; | ||
array.map(() => Promise.reject()); | ||
`, | ||
errors: [{ line: 3, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
declare const promiseArray: Array<Promise<unknown>>; | ||
void promiseArray; | ||
`, | ||
options: [{ ignoreVoid: false }], | ||
errors: [{ line: 3, messageId: 'floatingPromiseArray' }], | ||
}, | ||
{ | ||
code: ` | ||
[1, 2, Promise.reject(), 3]; | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
[1, 2, Promise.reject().catch(() => {}), 3]; | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test case from the issue report |
||
const data = ['test']; | ||
data.map(async () => { | ||
await new Promise((_res, rej) => setTimeout(rej, 1000)); | ||
}); | ||
`, | ||
errors: [{ line: 3, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
function _<T, S extends Array<T | Array<T | Promise<T>>>>( | ||
maybePromiseArrayArray: S | undefined, | ||
): void { | ||
maybePromiseArrayArray?.[0]; | ||
} | ||
`, | ||
errors: [{ line: 5, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
function f<T extends Array<Promise<number>>>(a: T): void { | ||
a; | ||
} | ||
`, | ||
errors: [{ line: 3, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
declare const a: Array<Promise<number>> | undefined; | ||
a; | ||
`, | ||
errors: [{ line: 3, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
function f<T extends Array<Promise<number>>>(a: T | undefined): void { | ||
a; | ||
} | ||
`, | ||
errors: [{ line: 3, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
[Promise.reject()] as const; | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
declare function cursed(): [Promise<number>, Promise<string>]; | ||
cursed(); | ||
`, | ||
errors: [{ line: 3, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
[ | ||
'Type Argument number ', | ||
1, | ||
'is not', | ||
Promise.resolve(), | ||
'but it still is flagged', | ||
] as const; | ||
`, | ||
errors: [{ line: 2, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
declare const arrayOrPromiseTuple: | ||
| Array<number> | ||
| [number, number, Promise<unknown>, string]; | ||
arrayOrPromiseTuple; | ||
`, | ||
errors: [{ line: 5, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
{ | ||
code: ` | ||
declare const okArrayOrPromiseArray: Array<number> | Array<Promise<unknown>>; | ||
okArrayOrPromiseArray; | ||
`, | ||
errors: [{ line: 3, messageId: 'floatingPromiseArrayVoid' }], | ||
}, | ||
], | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.