rspec/rules/S2179/html/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

49 lines
1.3 KiB
Plaintext

== Why is this an issue?
The assignment of a boolean variable inside the test of a control structure such as an ``++if++``, ``++while++`` or ``++for++`` loop is almost always a mistake and should be corrected to avoid unexpected program results. In fact, even if it was done on purpose, it should be re-examined.
=== Noncompliant code example
[source,html]
----
boolean b = false;
if ( b = m.getTrue()) { ... } // Noncompliant
while (b = getTrue()) { ... } // Noncompliant; unintentionally infinite
for (int i = 0; i < 10 && b = getTrue(); i++) { ... } // Noncompliant
----
=== Compliant solution
[source,html]
----
boolean b = false;
if ( b = m.getTrue())
{
System.out.println("How did we get here");
}
----
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
=== duplicates: S1121
=== on 21 Oct 2014, 18:57:07 Nicolas Peru wrote:
Isn't that covered by this one \http://jira.sonarsource.com/browse/RSPEC-1121 ?
=== on 21 Oct 2014, 20:30:47 Ann Campbell wrote:
Uhm... you tell me [~nicolas.peru]. I did look at that one, but from the examples decided not.
=== on 22 Oct 2014, 07:08:39 Nicolas Peru wrote:
For me this is completely covered by RSPEC-1121 and as it also provides exception I would not bother with this one.
endif::env-github,rspecator-view[]