The main caveat is that you have to use typescript. Put this into the rules
section of your .eslintrc.json
:
"@typescript-eslint/await-thenable": "error", "@typescript-eslint/require-await": "error", "@typescript-eslint/no-floating-promises": "error"
You'll also need to tell eslint where your tsconfig file is:
"parserOptions": { "project": "tsconfig.json" }
Then if you write code like this, where you don't await an asynchronous call:
async function f() { await fetch('a') doSomethingElse() fetch('b') }
Then you'll get a helpful error message, which pops up over the text in vscode if you're using the eslint extension:
temp.ts 4:5 error Promises must be handled appropriately or explicitly marked as ignored with the `void` operator @typescript-eslint/no-floating-promises
You'll also get errors if an async
function has no awaits or if you await a sync function.
Top comments (1)
All the rules with more examples and explanation are in here: github.com/typescript-eslint/types...