The same value is assigned to the variable again
- Code Quality
- 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 ExampleView with compliant examples side by side
// Example 1 a = a; // ASSIGN_SAME_VALUE alarm // Example 2 a = b; a = b; // ASSIGN_SAME_VALUE alarm // Example 3 r = a; a = b; b = a; // ASSIGN_SAME_VALUE alarm
Compliant Code ExampleView with noncompliant examples side by side
// Example 3 r = a; a = b; b = r; // a and b are swapped
This rule was introduced in DeepScan 1.0.0-alpha.