# promise/no-promise-in-callback

> Disallow promises inside error-first callbacks

The code that calls a callback ignores what it returns. Nobody awaits a promise started inside one, so a rejection goes unhandled, and the code now reports errors in two different ways.

A function counts as a callback if its first parameter is named `err` or `error`. Inside one, the rule reports calls to `then()`, `catch()`, `finally()` and static methods such as `Promise.all()`.

A call that's the value of a `return` statement isn't reported. A function passed to `then()` or `catch()` doesn't count as a callback, no matter what its first parameter is called.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"promise/no-promise-in-callback" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"promise/no-promise-in-callback" = ["error", {
  exemptDeclarations = false,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
fs.readFile(path, "utf8", (err, text) => {
  if (err) throw err;
  upload(text).then(notify);
});
```

Not reported:

{/* good */}
```js
import { readFile } from "node:fs/promises";

async function publish(path) {
  const text = await readFile(path, "utf8");
  await upload(text);
  notify();
}

upload(draft).catch(err => retry(draft).then(notify));
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `exemptDeclarations` | `false` | Don't treat function declarations as callbacks, only function expressions and arrow functions. |

{/* bad */}
```js
function onFailure(error) {
  report(error).then(close);
}
```

{/* good {"options": [{"exemptDeclarations": true}]} */}
```js
function onFailure(error) {
  report(error).then(close);
}
```
