Skip to content
← Back to rules

promise/no-promise-in-callback Suspicious

What it does

Disallows the use of Promises within error-first callback functions.

Why is this bad?

Mixing Promises and callbacks can lead to unclear and inconsistent code. Promises and callbacks are different patterns for handling asynchronous code. Mixing them makes the logic flow harder to follow and complicates error handling, as callbacks rely on an error-first pattern, while Promises use catch.

Examples

Examples of incorrect code for this rule:

js
doSomething((err, val) => {
  if (err) console.error(err);
  else doSomethingElse(val).then(console.log);
});

Examples of correct code for this rule:

js
promisify(doSomething)().then(doSomethingElse).then(console.log).catch(console.error);

Configuration

exemptDeclarations

type: boolean

default: false

Whether or not to exempt function declarations. Defaults to false.

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["promise"],
  "rules": {
    "promise/no-promise-in-callback": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["promise"],
  rules: {
    "promise/no-promise-in-callback": "error",
  },
});
bash
oxlint --deny promise/no-promise-in-callback --promise-plugin

Version

This rule was added in v0.13.1.

References