unused-assignment
What it does
Section titled “What it does”Reports a value stored in a local variable that no path reads before it is overwritten or the variable goes out of scope (a dead store). Variables that are captured or whose address is taken are not checked. A variable that is never read at all is unused-variable’s.
Why it matters
Section titled “Why it matters”A dead store is a computation whose result is thrown away. It is often the sign of a bug: the value was meant to be used and a later line forgot it, or an earlier branch was changed.
To fix, use the value, or delete the assignment (keep the right side if it has a side effect).
Example
Section titled “Example”class A { int F() { int n = 0; n = G(); return n; } int H() { int m = 0; m = 1; m = G(); return m; } int G() => 1; }Configuration
Section titled “Configuration”csharp: lint: rules: unused-assignment: warn # off (default), warn, errorEnabled by the presets: csharp/roslynator.
Suppress one line with sudsy-disable-next-line unused-assignment in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| Roslynator | RCS1179 |
full |
| Roslynator | RCS1212 |
full |