rspec/rules/S2128/rule.adoc

52 lines
882 B
Plaintext
Raw Normal View History

There is no reason to store a value that is never read. Doing so indicates a bug: was the value assigned to the wrong variable? Was some calculation left out of the method? If it is not a bug, it is a waste of cycles and an obfuscation of the code.
== Noncompliant Code Example
----
public int getNumber(int a) {
int i;
int b = a;
for (i = 0; i < 10; i++) {
b *= i;
}
i = a; // Noncompliant; value assigned but not used before return
return b;
}
----
== Compliant Solution
----
public int getNumber(int a) {
int i;
int b = a;
for (i = 0; i < 10; i++) {
b *= i;
}
return b;
}
----
2022-01-25 18:36:46 +01:00
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]