-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): [no-floating-promises] add an 'allowForKnownSafePromises' option #8502
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
'allowForKnownSafePromises' option fixes: typescript-eslint#7008
Thanks for the PR, @arka1002! 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. |
packages/eslint-plugin/tests/rules/no-floating-promises.test.ts
Outdated
Show resolved
Hide resolved
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.
Haven't been able to look deeply yet, but - looks like there's a mismatch in naming?
Ahh... I think I made a terrible mistake. Thanks for the reviews though. Sorry for the inconvenience. |
👋 @arka1002 adding the new If not, no worries - I'd happily take this on myself. It's a nuanced rule with a lot of context around it. ❤️ |
Yes, I've almost done the tests, give me just 3 more days. I'll open it for review. |
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.
🆒 thanks for trimming down the test cases! I think this is looking pretty great. Just one last bug from my end and I think I'll be done requesting changes (hopefully, probably).
I'll also leave this open to get at least one other review from @typescript-eslint/triage-team. I've looked at it enough that I don't trust myself to not be missing something. 😄
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
packages/eslint-plugin/tests/rules/no-floating-promises.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/no-floating-promises.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/no-floating-promises.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/no-floating-promises.test.ts
Outdated
Show resolved
Hide resolved
packages/eslint-plugin/tests/rules/no-floating-promises.test.ts
Outdated
Show resolved
Hide resolved
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.
Requesting some changes in #8502 (comment), but otherwise I think this is getting close! 🙂
Thanks for the reviews. I'm just writing down some notes for the future people who are going to stumble upon this pr.
|
@@ -2079,19 +2079,19 @@ promise; | |||
}, | |||
{ | |||
code: ` | |||
interface UnsafeThenable<T> { | |||
interface SafeThenable<T> { |
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... this one, should be valid, because the overall expression results in a SafeThenable
rather than ordinary promise (due to the way the SafeThenable#then
is defined)
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.
Yes, there's an issue which exactly describes Thenable
in this rule - #8433. (It also says thenables should be valid)
It'll be solved there.
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.
That is a separate thing entirely (and if it were the case, it would make this entire PR moot, not just this test case). This option needs to be able to support expressions that result in one of the allowed types.
Please move this case to the valid
array.
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 @arka1002! 👋
Heads up that that this PR is blocking some high-priority no-floating-promises issues. We appreciate how much work you've put into it 🙏 , but we really need to wrap it up soon.
We're going to "time-box" this PR; if it isn't merged before Monday the 3rd, we'll plan to take it over ourselves in order to have it ready for the release ~1pm EST that day.
If you have time to iterate with us this week on the requested changes, that's awesome! If not, we also understand, and we have bandwidth to handle the final rounds of change requests on our side.
Thanks again for your work on this! ❤️
@@ -2079,19 +2079,19 @@ promise; | |||
}, | |||
{ | |||
code: ` | |||
interface UnsafeThenable<T> { | |||
interface SafeThenable<T> { |
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.
That is a separate thing entirely (and if it were the case, it would make this entire PR moot, not just this test case). This option needs to be able to support expressions that result in one of the allowed types.
Please move this case to the valid
array.
}, | ||
], | ||
|
||
create(context, [options]) { | ||
const services = getParserServices(context); | ||
const checker = services.program.getTypeChecker(); | ||
// TODO: #5439 | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const allowForKnownSafePromises = options.allowForKnownSafePromises!; | ||
|
||
return { | ||
ExpressionStatement(node): void { |
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.
Spinning off from https://github.com/typescript-eslint/typescript-eslint/pull/8502/files/7422cf504ba51cc2e1855f0352e151877720755e#r1585695716, please move the duplicative checks for doesTypeMatchSpecifier
throughout the ExpressionStatement
handler into the start of isPromiseLike
function down below. (this will also resolve the test case in https://github.com/typescript-eslint/typescript-eslint/pull/8502/files/7422cf504ba51cc2e1855f0352e151877720755e#r1605894419).
(You might need to pass in context or just move isPromiseLike
into the create
function so it has access to the options and such, similarly to how you already handled isPromiseArray
🙂).
PR Checklist
Overview
Hi, I'm really curious, is there any way to test code which haveimport
in them ? #4436 also didn't have them.Nvm, found it.
Let's discuss.