rspec/rules/S2128/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

61 lines
1.0 KiB
Plaintext

== 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
[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
[source,text]
----
public int getNumber(int a) {
int i;
int b = a;
for (i = 0; i < 10; i++) {
b *= i;
}
return b;
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this useless assignment of "xxx".
'''
== 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
endif::env-github,rspecator-view[]