CodyC
CodyC3y ago

Lint for if you forgot to `await` a Promise?

If you have async methods that you call for their side effects, it's easy to forget to await them. Is there a lint rule that I can enable for that? (Sort of like Rust's rules about unused Results?) ex:
async myFn() {
// code

// oops, I forgot to await:
doThing()

// more code
// fails at runtime because doThing()
// hasn't finished yet.

}
async myFn() {
// code

// oops, I forgot to await:
doThing()

// more code
// fails at runtime because doThing()
// hasn't finished yet.

}
4 Replies
CodyC
CodyCOP3y ago
I've been searching/skimming https://lint.deno.land/ but don't see a relevant one yet.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
CodyC
CodyCOP3y ago
Yeah, I knew about require-await, and it's enabled by default. (Which TBH I find a bit annoying. :p) Yeah, I know there are some times where you don't want to await the promise. But if you enable the lint, you could handle that by just creating a function like
function noAwait<T>(p: Promise<T>): void {}
function noAwait<T>(p: Promise<T>): void {}
To explicitly mark cases you don't want to wait for. (which is almost never in my admittedly limited experience)
dandv
dandv2w ago
Maybe typescript-eslint works in Deno nowadays
I'm also trying to figure out how! https://stackoverflow.com/questions/79354265/using-typescript-eslint-with-deno
Stack Overflow
Using typescript-eslint with Deno
typescript-eslint recommends using "dual-linting" with Deno... using those linters for what they support, then adding in ESLint for typed linting in a parallel or second step ...but doe...

Did you find this page helpful?