---
title: "lint/control-flow/no-return-assignment"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

<RuleId id="lint/control-flow/no-return-assignment" />

In the [`dead-code`](/docs/rules/sets/dead-code) set. Safe fix.

## What it does

Local, dynamic and directly referenced variables should not be assigned and directly returned by a function or method.

## Configuration

```toml title="pun.toml"
[lint.rules]
"control-flow/no-return-assignment" = "error"
```

To skip it in some files, add an [override](/docs/configuration/pun-toml#lint) or a [`@pun-ignore-file`](/docs/configuration/ignore-comments) comment.

## Options

| Name | Type | Allowed values | Default | Upstream name |
| --- | --- | --- | --- | --- |
| `skip-named-var-tags` | `bool` | Any | `false` | `skip_named_var_tags` |
| `skip-commented` | `bool` | Any | `false` | None (Pun's own) |

## Replaces

- [`return_assignment`](https://cs.symfony.com/doc/rules/return_notation/return_assignment.html) (php-cs-fixer)
- [`SimplifyUselessVariable`](https://getrector.com/rule-detail/simplify-useless-variable-rector) (rector)
- [`inline-variable-return`](https://mago.carthage.software/1.61.0/en/tools/linter/rules/#inline-variable-return) (mago-linter)

## Merged rules

These old IDs are now this rule. A config that still names one stops with an error. See [merged rules](/docs/migrate/merged-rules).

- `lint/dead-code/no-useless-variable`

Rector's SimplifyUselessVariableRector leaves an assignment alone when a comment is before it, or when a comment before the return names the variable or has `@var`. `skip-commented = true` does the same; `pun migrate` sets it when the rule comes from rector.php and not from PHP-CS-Fixer's return_assignment.

[More lint/control-flow rules](/docs/rules/lint/control-flow) · [Edit this page](https://github.com/shipfastlabs/pun/edit/main/crates/pun-config/rules/mapping.toml)
