Why this matters
Assignments to variables that are never used waste computation and clutter the code. Remove them to improve clarity.
Eliminate assignments to variables that are never used or overwritten immediately to improve code efficiency and readability.
Assignments to variables that are never used waste computation and clutter the code. Remove them to improve clarity.
Side-by-side examples engineers can pattern-match during review.
int foo(int y) {
int x = 100; // Noncompliant: dead store
x = 150; // Noncompliant: dead store
x = 200;
return x + y;
}int foo(int y) {
int x = 200; // Compliant: no unnecessary assignment
return x + y;
}int foo(int y) {
int x = 100; // Noncompliant: dead store
x = 150; // Noncompliant: dead store
x = 200;
return x + y;
}int foo(int y) {
int x = 200; // Compliant: no unnecessary assignment
return x + y;
}From the same buckets as this rule.