This rule raises an issue when an async function does not use any asynchronous feature.

Why is this an issue?

Declaring a function async signals that it suspends on await or for await, so other work can proceed while an operation such as I/O completes.

If the function’s body never suspends, the async keyword is superfluous. Using async unnecessarily can:

How to fix it

Before changing the function, verify whether it must wait for an asynchronous operation and how callers use its return value.

  1. If the function must wait for a Promise expression that is not awaited, add await to that expression.
  2. If callers accept synchronous return values and synchronous exceptions, and the function does not need to return a Promise, remove async.

Code examples

Noncompliant code example

async function getUserName(user) { // Noncompliant: nothing is awaited, "async" only wraps the result in a Promise
  return user.name;
}

Compliant solution

function getUserName(user) {
  return user.name;
}

Noncompliant code example

async function saveUser(user) { // Noncompliant: the request is sent but never awaited
  fetch('/api/users', { method: 'POST', body: JSON.stringify(user) });
  console.log('User saved');
}

Compliant solution

async function saveUser(user) { // Compliant: waits for the request before logging
  await fetch('/api/users', { method: 'POST', body: JSON.stringify(user) });
  console.log('User saved');
}

Exceptions

This rule does not raise an issue in the following cases:

async function stub() {} // Compliant: empty body

async function relay(id) {
  return fetchUser(id); // Compliant: the return value is already a Promise
}

async function* stream(source) {
  yield* source; // Compliant: delegates to an async-iterable source
}

async function refreshProfile() {
  'use server'; // Compliant: Server Functions must be async
  revalidatePath('/profile');
}
function load(loader: () => Promise<User | null> = async () => null) { // Compliant: the parameter type requires a Promise
  // ...
}

interface Repository {
  save(entity: Entity): Promise<void>;
}

class InMemoryRepository implements Repository {
  private readonly entities: Entity[] = [];

  async save(entity: Entity): Promise<void> { // Compliant: implements a Promise-returning interface method
    this.entities.push(entity);
  }
}
function SaveButton({ onSave }: { onSave: () => Promise<void> }) {
  // ...
}

<SaveButton onSave={async () => { logger.info('saved'); }} />; // Compliant: the prop type requires a Promise

Resources

Documentation