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

63 lines
1.8 KiB
Plaintext

== Why is this an issue?
Boolean literals should be avoided in comparison expressions ``++==++`` and ``++!=++`` to improve code readability.
This rule also reports on redundant boolean operations.
=== Noncompliant code example
[source,javascript]
----
let someValue = "0";
// ...
if (someValue == true) { /* ... */ }
if (someBooleanValue != true) { /* ... */ }
doSomething(!false);
----
=== Compliant solution
[source,javascript]
----
if (someValue && someValue != "0") { /* ... */ }
if (!someBooleanValue) { /* ... */ }
doSomething(true);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Refactor the code to avoid using this boolean literal.
'''
== Comments And Links
(visible only on this page)
=== on 10 Mar 2017, 17:04:41 Elena Vilchik wrote:
Rule is deprecated as it's a wrong in JS:
----
"0" == false // true
Boolean("0") // true
----
=== on 2 Nov 2017, 20:03:36 Ann Campbell wrote:
\[~elena.vilchik] if it's wrong, why not just remove it? I'm not generally in favor of jerking the rug out from under users in that manner, but what you're saying is essentially that this rule _is_ a bug. As such, it should be fixed / removed.
=== on 6 Nov 2017, 14:50:08 Elena Vilchik wrote:
\[~ann.campbell.2] I see your point, we deprecated it as the matter of habit. We will remove the rule in the next version (\https://github.com/SonarSource/SonarJS/issues/825), there is no point in fixing it.
=== on 4 Dec 2017, 09:44:32 Elena Vilchik wrote:
Eventually we decided to keep the rule but for ``++==++`` and ``++!=++`` use different message. Even though there are some cases then simple drop of literal will break the code, code is still smelly and should be refactored.
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]