-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [await-thenable] check Promise.all #10282
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
Conversation
Thanks for the PR, @Zamiell! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 55513d4. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
Codecov ReportAttention: Patch coverage is
❌ Your patch status has failed because the patch coverage (66.66%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #10282 +/- ##
==========================================
- Coverage 86.56% 86.54% -0.03%
==========================================
Files 431 431
Lines 15188 15206 +18
Branches 4418 4425 +7
==========================================
+ Hits 13148 13160 +12
- Misses 1683 1688 +5
- Partials 357 358 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
if ( | ||
node.callee.type === AST_NODE_TYPES.MemberExpression && | ||
node.callee.object.type === AST_NODE_TYPES.Identifier && | ||
node.callee.object.name === 'Promise' && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type verification part probably needs to be reviewed, ...
[Bug] Good question. isBuiltinSymbolLike
is our standard utility for this. You'll want to use that, and add tests to make sure things coincidentally named Array
or Promise
don't erroneously trigger this rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is on the wrong line, see https://github.com/typescript-eslint/typescript-eslint/pull/10282/files#r1836229674
}; | ||
}, | ||
}); | ||
|
||
/** This is a simplified version of the `getTypeName` utility function. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Question] Why use this the existing getTypeName
, then?
This might be a moot point if you end up using isBuiltinSymbolLike
or one of the functions around it.
const argument = node.arguments[0]; | ||
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Style] 💡 hint:
const argument = node.arguments[0]; | |
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition | |
const argument = node.arguments.at(0); |
declare const booleans: boolean[]; | ||
await Promise.all(booleans); | ||
await Promise.allSettled(booleans); | ||
await Promise.race(booleans); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://typescript-eslint.io/contributing/pull-requests#granular-unit-tests: one error per invalid
case please
If we go with this PR, we should add co-author attributions to @abrahamguo and @Tjstretchalot for #10163 and #8094. |
Sadly, TS's I was also wondering if we can do something roughly like function getIteratedType(checker: ts.TypeChecker, type: ts.Type): ts.Type | undefined {
const symbolIterator = tsutils.getWellKnownSymbolPropertyOfType(type, 'iterator', checker);
if (symbolIterator == null) {
return;
}
const symbolIteratorType = checker.getTypeOfSymbol(symbolIterator);
const symbolIteratorCallSignatures = tsutils.getCallSignaturesOfType(symbolIteratorType);
const returnTypes = symbolIteratorCallSignatures.map(signature => signature.getReturnType());
// figure out how to make a union of these types or just return the list :shrug:
return returnTypes
} As for checking whether something looks like a promise, we generally use the |
const typeName = getTypeNameSimple(type); | ||
const typeArgName = getTypeNameSimple(typeArg); | ||
|
||
if (typeName === 'Array' && typeArgName !== 'Promise') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 Hey @Zamiell! Just checking in, is this still something you have time for? No worries if not - I just don't want to leave it hanging. |
Yeah I'll try to get to it this weekend if I have time. |
👋 Checking in again @Zamiell, happy new year! Is this still on your radar? |
yeah i still plan to work on this when i get some more free time, i have been very sick lately |
Same as #10265 (comment): ❤️ hope you feel better soon! Removing |
Closing out to un-block the issue, as planned. Cheers! |
PR Checklist
Promise.all
,Promise.allSettled
,Promise.race
) #1804Overview
Promise.all
,Promise.allSettled
, andPromise.race
. As discussed in the aforementioned issue, we are arbitrarily adding this toawait-thenable
instead of putting it in into a new rule.ts.Type
matches the form ofIterable<Promise<any>>
. So for now, I just check for the most common case with hard-coded names.