# promise/no-return-wrap

> Disallow returning `Promise.resolve()` or `Promise.reject()` from a promise callback

`then()` and `catch()` already wrap whatever their callback returns in a promise, and an error thrown in the callback already rejects the chain. So `return Promise.resolve(value)` does the same as `return value`, and `return Promise.reject(error)` does the same as `throw error`.

The rule checks the return values of `then()`, `catch()` and `finally()` callbacks.

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

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"promise/no-return-wrap" = ["error", {
  allowReject = false,
}]
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```js
fetchUser(id).then(user => {
  if (!user.active) {
    return Promise.reject(new Error("inactive user"));
  }
  return Promise.resolve(user.profile);
});
```

Not reported:

{/* good */}
```js
fetchUser(id).then(user => {
  if (!user.active) {
    throw new Error("inactive user");
  }
  return user.profile;
});
```

Outside a promise callback, both are fine:

{/* good */}
```js
function cachedUser(id) {
  return Promise.resolve(cache.get(id));
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowReject` | `false` | Allow `return Promise.reject(error)`. `Promise.resolve()` is still reported. |

{/* good {"options": [{"allowReject": true}]} */}
```js
fetchUser(id).catch(err => Promise.reject(new Error("no user", { cause: err })));
```

{/* bad {"options": [{"allowReject": true}]} */}
```js
fetchUser(id).then(user => Promise.resolve(user.profile));
```
