# no-param-reassign

> Disallow assigning to function parameters

After `price = price * 1.2`, the name `price` no longer holds what the caller passed, and anyone reading further down the function has to notice that. In a function that isn't in strict mode, the assignment also changes `arguments[0]`.

Use a new variable for the new value.

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

Every option, set to its default. The ones that are commented out are unset by default.

```toml bunfig.toml
[lint.rules]
"no-param-reassign" = ["error", {
  props = false,
  # ignorePropertyModificationsFor = [], # list of strings
  # ignorePropertyModificationsForRegex = [], # list of strings
}]
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```js
function total(price, count) {
  price = price * 1.2;
  count++;
  return price * count;
}
```

Not reported:

{/* good */}
```js
function total(price, count) {
  const withTax = price * 1.2;
  return withTax * (count + 1);
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `props` | `false` | Also report a change to a parameter's property: an assignment, `++`, `--`, `delete`, or use as the variable of a `for...in` or `for...of` loop. |
| `ignorePropertyModificationsFor` | `[]` | With `props`: names of parameters whose properties can be changed. |
| `ignorePropertyModificationsForRegex` | `[]` | With `props`: the same, as regular expressions. |

By default, changing a property is allowed:

{/* good */}
```js
function activate(user) {
  user.active = true;
}
```

With `{ props: true }`, it's reported, because the caller's object changes:

{/* bad {"options": [{"props": true}], "count": 2} */}
```js
function activate(user) {
  user.active = true;
  delete user.pending;
}
```

The two lists make exceptions for parameters that exist to be changed. With `{ props: true, ignorePropertyModificationsFor: ["res"], ignorePropertyModificationsForRegex: ["^draft"] }`:

{/* good {"options": [{"props": true, "ignorePropertyModificationsFor": ["res"], "ignorePropertyModificationsForRegex": ["^draft"]}]} */}
```js
function notFound(req, res) {
  res.statusCode = 404;
}

function rename(draftUser, name) {
  draftUser.name = name;
}
```
