@typescript-eslint/require-await
Disallow async functions that never await and do not return a promise
Also called typescript-eslint/require-await, typescript/require-await
An async function with no await in it does its work right away and then wraps the result in a promise for nothing. Often the async is left over from a refactor, or an await is missing.
This is require-await with types, so it can allow a function that returns a promise. There, async turns an error thrown before the return into a rejection. for await and await using count as an await, and a function with an empty body isn't reported.
With bunfig.toml, turning this rule on runs it in TypeScript files and require-await in JavaScript files, so nothing is reported twice. With an ESLint config, turn the other rule off when you use this one.
bun lint --type-aware turns this rule on in TypeScript files.
Configure#
Off by default. This rule needs types, so turning it on makes bun lint type check your code first.
[lint.rules]
"@typescript-eslint/require-await" = "error" # or "warn"Examples#
async function totalAsync function total has no await expression.(prices: number[]) {
return prices.reduce((sum, price) => sum + price, 0);
}
const log = async (message: string) =>Async arrow function log has no await expression. {
console.log(message);
};function total(prices: number[]) {
return prices.reduce((sum, price) => sum + price, 0);
}
async function readConfig(path: string) {
const text = await Bun.file(path).text();
return JSON.parse(text);
}
async function loadUser(id: string) {
return fetch(`/users/${id}`);
}