# promise/param-names

> Require the parameters of a `new Promise()` executor to be named `resolve` and `reject`

The function you pass to `new Promise()` gets its two parameters by position, no matter what you call them. If you write them in the wrong order, `reject(value)` fulfills the promise and `resolve(error)` rejects it.

The first parameter must be `resolve` or `_resolve`, and the second must be `reject` or `_reject`. You can leave out parameters you don't use.

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

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"promise/param-names" = ["error", {
  resolvePattern = "^_?resolve$",
  rejectPattern = "^_?reject$",
}]
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```js
new Promise((reject, resolve) => {
  setTimeout(resolve, 1000); // rejects the promise
});
```

{/* bad */}
```js
new Promise(done => {
  setTimeout(done, 1000);
});
```

Not reported:

{/* good */}
```js
new Promise(resolve => {
  setTimeout(resolve, 1000);
});

new Promise((_resolve, reject) => {
  setTimeout(reject, 1000);
});
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `resolvePattern` | `"^_?resolve$"` | A regular expression that the first parameter's name must match. |
| `rejectPattern` | `"^_?reject$"` | A regular expression that the second parameter's name must match. |

{/* good {"options": [{"resolvePattern": "^(resolve|done)$", "rejectPattern": "^(reject|fail)$"}]} */}
```js
new Promise((done, fail) => {
  socket.once("open", done);
  socket.once("error", fail);
});
```
