rspec/rules/S2128/rule.adoc

61 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
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
2022-02-04 17:28:24 +01:00
[source,text]
----
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
2022-02-04 17:28:24 +01:00
[source,text]
----
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)
=== Message
Remove this useless assignment of "xxx".
2022-01-25 18:36:46 +01:00
'''
== Comments And Links
(visible only on this page)
=== on 10 Oct 2014, 14:05:08 Freddy Mallet wrote:
@Ann, for me this RSPEC duplicates RSPEC-1981
2022-01-25 18:36:46 +01:00
endif::env-github,rspecator-view[]