December 17, 2021 06:58 pm GMT
Original Link: https://dev.to/qpwo/most-useful-eslint-rules-for-networking-code-asyncawaitpromises-1mg4
Most useful eslint rules for networking code (async/await/promises)
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.ts4: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.
Original Link: https://dev.to/qpwo/most-useful-eslint-rules-for-networking-code-asyncawaitpromises-1mg4
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To