unused-local-variable
What it does
Section titled “What it does”Reports a local variable that is declared, and perhaps assigned, but never read. No fix.
Why it matters
Section titled “Why it matters”A variable that is assigned and never read is dead code. It is a leftover of an earlier version, or a sign that the code was meant to use it (a misspelled name, a result that is forgotten), and it misleads the reader about what the code computes.
To fix, remove the variable, or use it.
Example
Section titled “Example”...
class A { int f(int a, List<String> xs) { int unused = 1; int written = 0; written = 2; int used = a; int counter = 0;... } for (int i = 0; i < 3; i++) { // keep } Runnable r = () -> { int inner = 1; }; return used; }...Configuration
Section titled “Configuration”java: lint: rules: unused-local-variable: warn # off (default), warn, errorruby: lint: rules: unused-local-variable: warn # off (default), warn, errorEnabled by the presets: ruby/rubocop.
Suppress one line with sudsy-disable-next-line unused-local-variable in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| checkstyle | UnusedLocalVariable |
full | |
| rubocop | Lint/UselessAssignment |
partial | not an assignment that is overwritten before any read |