# no-promise-executor-return

> Disallow returning a value from the function passed to `new Promise`

`new Promise` ignores whatever its function returns. A `return value` there usually means you meant `resolve(value)`, and the promise never settles.

An arrow function without braces also returns a value. For example, `resolve => setTimeout(resolve, 100)` returns the timer. That one's harmless, but it's reported too. Put the body in braces.

A `return` without a value is allowed, so you can still leave the function early.

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"no-promise-executor-return" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-promise-executor-return" = ["error", {
  allowVoid = false,
}]
```

## Examples

Reported:

```js
function readCached(key) {
  return new Promise((resolve, reject) => {
    if (cache.has(key)) {
      return cache.get(key);
    }
    load(key, resolve, reject);
  });
}

const wait = ms => new Promise(resolve => setTimeout(resolve, ms));
```

Not reported:

```js
function readCached(key) {
  return new Promise((resolve, reject) => {
    if (cache.has(key)) {
      resolve(cache.get(key));
      return;
    }
    load(key, resolve, reject);
  });
}

const wait = ms =>
  new Promise(resolve => {
    setTimeout(resolve, ms);
  });
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowVoid` | `false` | Allow returning a `void` expression, which says you're dropping the value on purpose. |

With `{ allowVoid: true }`, this is allowed:

```js
const wait = ms => new Promise(resolve => void setTimeout(resolve, ms));
```

Without the option, that line is reported:

```js
const wait = ms => new Promise(resolve => void setTimeout(resolve, ms));
```
