Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Before You File a Proposal Please Confirm You Have Done The Following...
- I havesearched for related issues and found none that match my proposal.
- I have searched thecurrent rule list and found no rules that match my proposal.
- I haveread the FAQ and my problem is not listed.
My proposal is suitable for this project
- I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).
Link to the rule's documentation
https://typescript-eslint.io/rules/no-floating-promises
Description
For years, various community members have asked to add a type allowlist/blocklist or other"stop complaining about these specific areas" forno-floating-promises
:
- [no-floating-promises] Ability to ignore certain types from producing errors #2640
- [no-floating-promises] feature: does-not-throw annotation #3192(ish)
- [no-floating-promises] Provide a configuration option or other method to mark a Promise-returning function as "safe" #4722
- [no-floating-promises] Rule proposal: Add ignore for typescript types or specific methods #4791
- Enhancement:
@typescript-eslint/no-floating-promises
should Ignore node 18's built-in test function #5231 - Enhancement: [no-floating-promises] need a configuration that would allow to exclude an object from this rule #5844
- RFC: Common format to specify a type or value as a rule option #6017
- Enhancement: [no-floating-promises] add ignorePattern #7006
(including clearly duplicate issues to show how this is a relatively more requested option, and to surface the different use cases requested for)
Out of those,#5844'snode:test
is most convincing - asnode:test
is stable as of Node 20.0.0 (nodejs/node#46642 ->nodejs/node#46983), and returnsPromise<void>
for tests:https://github.com/DefinitelyTyped/DefinitelyTyped/blob/8730660c37a33dc0768b3f1e36b679294acc4988/types/node/test.d.ts#L134.
I propose we adopt the format discussed in#6017 & implemented in#4436 (see v6 docs) as a newallow
option forno-floating-promises
. We'd want to add some very explicitly, strongly worded descriptions in the docs as to why it's not an option we recommend using lightly.
Fail
asyncfunctiontest(name:string,executor:()=>Promise<void>){// ...}test("example",()=>{});
Pass
importtestfrom'node:test';test("example",()=>{});
Additional Info
cc@armano2@bradzacher as past people who, like me, have previously disagreed with the suggestion of adding this option.
Edit: to be clear, this is roughly what users would be able to specify in their ESLint config(pending naming bikeshedding):
"@typescript-eslint/no-floating-promises":["error",{"allowForKnownSafePromises":[{"from":"package","name":"SafePromise","package":"some-fancy-package"]}]