---
title: "analyse/dead-code/unused-variable"
pagination: false
---

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

<RuleId id="analyse/dead-code/unused-variable" />

In the [`analyse-recommended`](/docs/rules/presets/analyse-recommended) preset and every stricter one. Report only. Upstream gates: `bleedingEdge (featureToggles.unusedVariable)`.

## Configuration

```toml title="pun.toml"
[analyse.rules]
"dead-code/unused-variable" = "on"
```

To skip it in some files or lines, add an [ignore comment](/docs/configuration/ignore-comments).

## Replaces

- [`UnusedVariableRule`](https://phpstan.org/error-identifiers/assign.redundant) (phpstan-classes)
- [`array.offsetOverwritten`](https://phpstan.org/error-identifiers/array.offsetOverwritten) (phpstan)
- [`array.unusedOffset`](https://phpstan.org/error-identifiers/array.unusedOffset) (phpstan)
- [`array.unusedOffsetFlow`](https://phpstan.org/error-identifiers/array.unusedOffsetFlow) (phpstan)
- [`assign.overwritten`](https://phpstan.org/error-identifiers/assign.overwritten) (phpstan)
- [`assign.redundant`](https://phpstan.org/error-identifiers/assign.redundant) (phpstan)
- [`assign.unused`](https://phpstan.org/error-identifiers/assign.unused) (phpstan)
- [`assign.unusedFlow`](https://phpstan.org/error-identifiers/assign.unusedFlow) (phpstan)
- [`catch.unusedVariableFlow`](https://phpstan.org/error-identifiers/catch.unusedVariableFlow) (phpstan)
- [`foreach.keyOverwritten`](https://phpstan.org/error-identifiers/foreach.keyOverwritten) (phpstan)
- [`foreach.unusedKey`](https://phpstan.org/error-identifiers/foreach.unusedKey) (phpstan)
- [`foreach.unusedKeyFlow`](https://phpstan.org/error-identifiers/foreach.unusedKeyFlow) (phpstan)
- [`foreach.unusedValue`](https://phpstan.org/error-identifiers/foreach.unusedValue) (phpstan)
- [`foreach.unusedValueFlow`](https://phpstan.org/error-identifiers/foreach.unusedValueFlow) (phpstan)
- [`foreach.valueOverwritten`](https://phpstan.org/error-identifiers/foreach.valueOverwritten) (phpstan)
- [`postDec.overwritten`](https://phpstan.org/error-identifiers/postDec.overwritten) (phpstan)
- [`postDec.unused`](https://phpstan.org/error-identifiers/postDec.unused) (phpstan)
- [`postDec.unusedFlow`](https://phpstan.org/error-identifiers/postDec.unusedFlow) (phpstan)
- [`postInc.overwritten`](https://phpstan.org/error-identifiers/postInc.overwritten) (phpstan)
- [`postInc.unused`](https://phpstan.org/error-identifiers/postInc.unused) (phpstan)
- [`postInc.unusedFlow`](https://phpstan.org/error-identifiers/postInc.unusedFlow) (phpstan)
- [`preDec.overwritten`](https://phpstan.org/error-identifiers/preDec.overwritten) (phpstan)
- [`preDec.unused`](https://phpstan.org/error-identifiers/preDec.unused) (phpstan)
- [`preDec.unusedFlow`](https://phpstan.org/error-identifiers/preDec.unusedFlow) (phpstan)
- [`preInc.overwritten`](https://phpstan.org/error-identifiers/preInc.overwritten) (phpstan)
- [`preInc.unused`](https://phpstan.org/error-identifiers/preInc.unused) (phpstan)
- [`preInc.unusedFlow`](https://phpstan.org/error-identifiers/preInc.unusedFlow) (phpstan)
- [`variable.unused`](https://phpstan.org/error-identifiers/variable.unused) (phpstan)

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