Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
feat(eslint-plugin): [no-unsafe-return] check promise any#8693
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@yeonjuan! 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 onhttps://opencollective.com/typescript-eslint. |
netlifybot commentedMar 17, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site configuration. |
nx-cloudbot commentedMar 17, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
kirkwaiblinger left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
A good start! Curious to see what ends up changing in order to support the added test cases.
And a thought - these are realllly tricky. I spent a lot of time myself getting confused over whether the code I was trying out actually should pass or fail 😆.
So, I wonder if we can help the user out by supplying a custom error message for the async cases that don't directly returnany, but whose type evaluates toany after beingAwaited? Feel free to ignore this if it's a hassle to implement. But, my thought would be something like "Unsafe return of typePromise<any> that is equivalent to simply returningany within an async function." I'm curious for your thoughts. And, as said, it's completely ok if you would prefer to ignore this idea!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
| messageId:'unsafeReturn', | ||
| line:4, | ||
| column:3, | ||
| endColumn:16, |
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.
(nit, optional) If you're gonna include theendColumn, might as well include theendLine too for consistency. Here and elsewhere
yeonjuan commentedApr 25, 2024
@kirkwaiblinger I agree, this is great, but how about making the error message a little more concise? |
kirkwaiblinger commentedApr 25, 2024
👍 👍 |
# Conflicts:#packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts
codecovbot commentedApr 30, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## main #8693 +/- ##==========================================- Coverage 88.45% 88.42% -0.03%========================================== Files 422 422 Lines 14695 14717 +22 Branches 4298 4308 +10 ==========================================+ Hits 12998 13014 +16- Misses 1372 1378 +6 Partials 325 325
Flags with carried forward coverage won't be shown.Click here to find out more.
|
yeonjuan commentedMay 1, 2024
CI is failing, I created a separate PR to fix it.#9037 |
yeonjuan commentedMay 3, 2024
@kirkwaiblinger Thank you for your review. I added test cases and improved messsage. |
kirkwaiblinger left a comment
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.
Hi@yeonjuan!
First off, I want to say I am very sorry for how long it's taken me to get to another review pass on this!
This is great stuff. A few more tweaks and questions for iteration, but I feel like we're getting close 🙂
| ?'any' | ||
| :anyType===AnyType.AnyArray | ||
| ?'any[]' | ||
| :'Promise<any>', |
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.
Nit - not your fault, but this now runs into an "a" vs "an" issue in the generated string. I getUnsafe return of an `Promise<any>` typed value
Would you change the wording a bit so that it's grammatically consistent?
For example,Unsafe return of a value of type {{type}}.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
| Safe, | ||
| } | ||
| /** | ||
| *@returns `AnyType.Any` if the type is `any`, `AnyType.AnyArray` if the type is `any[]` or `readonly any[]`, |
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.
nit - comment will need updating
kirkwaiblinger left a comment
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.
Only blocker remaining is resolution of#8693 (comment), I think
| */ | ||
| getTypeOfPropertyOfType(type:Type,propertyName:string):Type|undefined; | ||
| /** | ||
| * Return the awaited type of the given type. |
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.
Maybe add a TODO that this should no longer be necessary in a future TS version and link the TS issue?
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.
Sure!fcca5ec
Uh oh!
There was an error while loading.Please reload this page.
JoshuaKGoldberg left a comment
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.
Yay! 🚀
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
| { | ||
| code:` | ||
| declare const value: Promise<any>; | ||
| function foo() { |
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 thought this is supposed to be valid, since it's not anasync function, according to#8674 (comment). Did that decision get changed?
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.
Note also that the error message for this case "Unsafe return of anPromise<any> typed value." is problematic, same as#8693 (comment)
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've fixed! I had forgotten about those comments.
auvred left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
Looks great!
UPD: There seems to be a merge conflict with#9540.
kirkwaiblinger left a comment
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.
Left a couple questions
kirkwaiblinger left a comment
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.
Yay!
JoshuaKGoldberg left a comment
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.


PR Checklist
Overview