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

{/* 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]
"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,
}]
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```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:

{/* good */}
```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:

{/* good {"options": [{"allowVoid": true}]} */}
```js
const wait = ms => new Promise(resolve => void setTimeout(resolve, ms));
```

Without the option, that line is reported:

{/* bad */}
```js
const wait = ms => new Promise(resolve => void setTimeout(resolve, ms));
```
