> 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.

# no-nesting

[Added in v0.6.2](https://github.com/web-infra-dev/rslint/releases/tag/v0.6.2)
## Configuration

| Preset                              | Configured Value |
| ----------------------------------- | ---------------- |
| ✅ promisePlugin.configs.recommended | `"warn"`         |


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

export default defineConfig([
  promisePlugin.configs.recommended,
  {
    rules: {
      'promise/no-nesting': 'error',
    },
  },
]);
```

## Rule Details

Disallow nesting `.then()` or `.catch()` statements inside promise callbacks when the
inner call does not depend on variables introduced by the enclosing callback.

Deeply nested promise chains are harder to read and can usually be rewritten as a flat
chain. This rule flags the inner `.then()` / `.catch()` when its arguments do not
reference any binding (parameter or local variable) that belongs to the immediately
enclosing promise callback, because in that case the nesting is unnecessary.

Examples of **incorrect** code for this rule:

```javascript
doThing().then(function () {
  return a.then();
});

doThing().then(() => b.catch());

doThing().then(function () {
  return a.then(function () {
    return b.catch();
  });
});
```

Examples of **correct** code for this rule:

```javascript
// Flat chain — no nesting
doThing().then(function () {
  return 4;
});

// Inner call uses a closure variable from the enclosing callback — cannot be flattened
doThing().then((a) => getB(a).then((b) => getC(a, b)));

// Promise.resolve / Promise.all inside a callback is fine
doThing().then(function () {
  return Promise.resolve(4);
});
```

## Original Documentation

- [eslint-plugin-promise: no-nesting](https://github.com/eslint-community/eslint-plugin-promise/blob/v7.3.0/docs/rules/no-nesting.md)
- [Source code](https://github.com/eslint-community/eslint-plugin-promise/blob/v7.3.0/rules/no-nesting.js)
