Enforces that all calls to async functions within an async function are awaited.
npm install eslint-plugin-no-await-async-call --save
Via .eslintrc (Recommended)
{
"plugins": ["no-await-async-call"],
"rules": {
"no-await-async-call/no-await-async-call": 2,
}
}
Or if required that the async function return value is stored in a variable
{
"plugins": ["no-await-async-call"],
"rules": {
"no-await-async-call/no-await-async-call": [ 2, "assignment-required" ]
}
}
Invalid code: (since f is called without await)
async function f() {};
async function g() {
f();
}
Valid code:
async function f() {};
async function g() {
await f();
}
Invalid code: (since f is called without await)
async function f() {};
async function g() {
let x = f();
}
Valid code:
async function f() {};
async function g() {
let x = await f();
}