For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/promise/prefer-await-to-callbacks.md.
close

prefer-await-to-callbacks

Added in v0.9.3

Configuration

rslint.config.ts
import { defineConfig, promisePlugin } from '@rslint/core';

export default defineConfig([
  promisePlugin.configs.recommended,
  {
    rules: {
      'promise/prefer-await-to-callbacks': 'error',
    },
  },
]);

Prefer async/await to callback patterns.

Rule Details

This rule reports calls to identifiers named cb or callback, function parameters with either name in the last position, and calls whose last argument is a function or arrow function with a first parameter named err or error.

Examples of incorrect code for this rule:

cb();
callback();
doSomething(arg, (err) => {});
function doSomethingElse(cb) {}

Examples of correct code for this rule:

await doSomething(arg);
async function doSomethingElse() {}
function* values() {
  yield yieldValue((err) => {});
}
eventEmitter.on('error', (err) => {});

The last-argument check allows on and once listeners and the array methods map, every, forEach, some, find, and filter with one argument. It also allows those methods with two arguments on lodash, underscore, or _, and direct calls to those method names with two arguments.

Callbacks within an await or yield expression are exempt from the last-argument check. Direct cb/callback calls and last parameters with those names are still reported in those contexts.

This rule has no options and provides no automatic fixes or suggestions.

Original Documentation