@typescript-eslint/require-await

Disallow async functions that never await and do not return a promise

has suggestionsneeds types

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.

bunfig.toml
[lint.rules]
"@typescript-eslint/require-await" = "error" # or "warn"

Examples#

example.ts2 problems
async function total(prices: number[]) {
  return prices.reduce((sum, price) => sum + price, 0);
}

const log = async (message: string) => {
  console.log(message);
};
example.tsNo problems
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}`);
}