rspec/rules/S2126/rule.adoc

30 lines
625 B
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
When an assignment is made in a return statement, the assigned value is returned and the assignment does take place. But if the assigned variable is local to the method, the assignment itself is simply wasted code.
Whether the variable is local or not, it makes for confusing code that will leave maintainers scratching their heads, wondering at the real intent.
=== Noncompliant code example
2022-02-04 17:28:24 +01:00
[source,text]
----
public int getNumber() {
int a = 0;
return a = 8; // Noncompliant
}
----
=== Compliant solution
2022-02-04 17:28:24 +01:00
[source,text]
----
public int getNumber() {
int a = 0;
return 8;
}
----