The same value is assigned to the variable again
- ASSIGN_SAME_VALUE
- Code Quality
- Low
- No tags
This rule applies when a variable is assigned with the same value as the following:
- Assignment made to same variable
- Redundant assignment
- Swapping the assignment with LHS and RHS variables
The above assignments can be unnecessary code, but they can be assigned with a wrong variable which is not likely to be a programmer's intent.
Noncompliant Code Example
View with compliant examples side by sidefunction example1() {
a = a; // ASSIGN_SAME_VALUE alarm
}
function example2() {
a = b;
a = b; // ASSIGN_SAME_VALUE alarm
}
function example3() {
r = a;
a = b;
b = a; // ASSIGN_SAME_VALUE alarm because b already has the same value as a.
}
Compliant Code Example
View with noncompliant examples side by sidefunction example1() {
a = b;
}
function example2() {
a = b;
}
function example3() {
r = a;
a = b;
b = r; // a and b are correctly swapped.
}
Version
This rule was introduced in DeepScan 1.0.0-alpha.