-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement: @typescript-eslint/no-floating-promises
should Ignore node 18's built-in test function
#5231
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
Comments
From the docs
So there are cases you can ignore the promise and cases you can't. I think this is the perfect candidate for the We don't want to add specific handling for the semantics of libraries or frameworks. This is just another test framework, even if it's built into node. |
Hmm, I'm not sure that's the optimal solution @bradzacher. The user story of "if you write native Node tests in linted TypeScript you have to use this operator you've never used this way before" is not ideal. At the very least it'll be confusing for users. What if we added an option named something like |
I don't think that this is a good idea because there are many cases where you want to catch top-level floating promises. One example that comes to mind is the async entrypoint pattern, common case for CLIs: async function main() {}
main();
// explicitly need handling here so you don't
// have floating promise exceptions leak
// from your entrypoint Options live forever and people are lazy - so people will just turn on an option instead of using overrides - which creates safety holes! Idk if a safety hole in your application is worth test DevX? We could change our recommended set to add overrides - though we don't know what a user's test files look like so that's hard (do they use the I hate to say it as I hate these arguments - but there is a slippery slope to consider too. We don't special case any other things for NodeJS (that I can think of). So if we are special casing this NodeJS api are we going to special case more in future across other rules? Also what makes the node test framework anything different to one of the much more widely used test frameworks like jest, mocha, chai, etc? If we're special casing the new and barely used NodeJS testing framework, should we go back and special case the existing and widely used Jest? Sorry a bit of a rant - just trying to tease out why this case should be any different to the past stance of "we don't encode framework semantics". |
i have to agree with brad on this one for now, adding new option to rule is possible but for now we should wait and see how |
Coming back to this: it also occurs to me that if #5271 is a better solution for this & similar issues. In the meantime, you can either use Long term, if folks want to standardize rule options specific to a framework, that should happen in plugins specific to that framework. In this case, Thanks all! 🤝 |
Aside: I just filed nodejs/node#51292 on the Node.js issue tracker to start a discussion on whether Node.js should make "floating" Promises this way. |
Before You File a Proposal Please Confirm You Have Done The Following...
My proposal is suitable for this project
Link to the rule's documentation
https://typescript-eslint.io/rules/no-floating-promises/
Description
Example code to run an async test from node docs
It triggers
@typescript-eslint/no-floating-promises
so I have to add ignore comments. It would be great if we can ignore the test function fromnode:test
(node 18+).Fail
// See description.
Pass
// See description.
Additional Info
No response
The text was updated successfully, but these errors were encountered: