# no-return-assign

> Disallow assignments in `return` statements

`return total = price + tax;` can be a typo for `return total === price + tax;`, and a reader can't tell which one you meant. Even when you do want the assignment, it hides a side effect in a line that looks like it only returns a value.

The rule also covers an arrow function whose body is an assignment.

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

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-return-assign" = ["error", "except-parens"] # "except-parens" or "always"
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```js
function setName(user, name) {
  return user.name = name;
}

const select = (item) => selected = item;
```

Not reported:

{/* good */}
```js
function setName(user, name) {
  user.name = name;
  return name;
}

const select = (item) => {
  selected = item;
};
```

## Options

| Option | What it does |
| --- | --- |
| `"except-parens"` (default) | Allow an assignment that's wrapped in parentheses. |
| `"always"` | Report every assignment in a `return`. |

The parentheses show that the assignment is on purpose:

{/* good */}
```js
function next() {
  return (current = current.next);
}
```

{/* bad {"options": ["always"]} */}
```js
function next() {
  return (current = current.next);
}
```
