-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
💅 useAwait
should be type-aware and require async
for functions that return a promise
#1161
Comments
@lensbart Biome doesn't have the infrastructure yet to deduce types, so it's impossible at the moment to match the rule from TypeScript Eslint. Unless there's an issue with the current logic of the rule, I advise to close the issue. We will soon publish more info about this topic. |
@ematipico thanks for the quick response! I’m fine with closing this ticket, but will add some additional context for future reference. I think the ideal setup uses a combination of The suggested approach would then be to use const problematic1 = () => {
db.getUsers() // @typescript-eslint/no-floating-promises
}
const problematic2 = () => { // @typescript-eslint/promise-function-async
return db.getUsers()
}
const problematic3 = async () => {
const users = db.getUsers() // @typescript-eslint/require-await
}
const okay1 = async () => {
return db.getUsers()
}
const okay2 = async () => {
void db.getUsers() // contrived example but just for the sake of argument
} |
+1 this feature request. The biggest reason for it in my company that eslint is slow is because it does type inference and we only need it for this one rule: |
Yeah we would really like |
Hello,
First of all, thanks for maintaining this project. It’s amazingly fast. I hope to one day learn some Rust so that I can contribute.
The
useAwait
that’s currently in the nursery, seems to be modeled after ESLint’srequire-await
(judging by #575). I think that in general, it’s better to mimic the behaviour of an equivalenttypescript-eslint
rule, if available, rather than the (non-type-aware) eslint rule.In this case, for example,
useAwait
will flag functions that are marked asasync
if they don’t contain theawait
keyword, even if the function returns a promise. In constrast,@typescript-eslint/require-await
(or is it@typescript-eslint/promise-function-async
?) explicitly addsasync
in this case, to inform the developer, since the return value must still be awaited.I’d propose to follow this behaviour in the case of
useAwait
as well.Relevant links:
useAwait
require-await
require-await
no-floating-promises
promise-function-async
Rule name
useAwait
Playground link
https://biomejs.dev/playground/?lintRules=all&code=YQBzAHkAbgBjACAAZgB1AG4AYwB0AGkAbwBuACAAcgBlAHQAdQByAG4AcwBQAHIAbwBtAGkAcwBlADEAKAApACAAewAKACAAIAByAGUAdAB1AHIAbgAgAFAAcgBvAG0AaQBzAGUALgByAGUAcwBvAGwAdgBlACgAMQApADsACgB9AAoACgBjAG8AbgBzAHQAIABfAHIAZQB0AHUAcgBuAHMAUAByAG8AbQBpAHMAZQAyACAAPQAgACgAKQAgAD0APgAgAHIAZQB0AHUAcgBuAHMAUAByAG8AbQBpAHMAZQAxACgAKQA7AAoACgA%3D
Expected result
No error for functions marked as
async
that don’t containawait
but do return a promiseCode of Conduct
The text was updated successfully, but these errors were encountered: