# promise/no-nesting

> Disallow `then()` and `catch()` nested inside another `then()` or `catch()`

A `then()` inside a `then()` adds a level of indentation for every step, and a `catch()` on the inner chain doesn't see errors from the outer one. Return the inner promise and continue the chain one level up.

A nested callback that uses a variable from the outer callback can't move up, so it isn't reported.

{/* 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-nesting" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad */}
```js
getUser(id).then(user => {
  return getOrders(user).then(orders => render(orders));
});
```

Not reported:

{/* good */}
```js
getUser(id)
  .then(user => getOrders(user))
  .then(orders => render(orders));
```

Here the inner callback needs `user`:

{/* good */}
```js
getUser(id).then(user => {
  return getOrders(user).then(orders => render(user, orders));
});
```
