
In some cases, the `rule.adoc` at root of a rule is never included anywhere and thus is dead code. It's a maintenance cost by itself, but also it misses opportunities to inline code that seems used by two documents when in fact only one document is actually rendered. And this missed opportunity, in turn, stops us from applying the correct language tag on the code samples.
52 lines
1.2 KiB
Plaintext
52 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Using the output of a non-boolean assignment as a condition is highly suspicious. Either it was done accidentally, and the assignment operator ``++=++`` was used in place of the equality operator ``++==++``, or it was done with the intent to rely on the automatic conversion of the non-boolean value to a boolean, which could be confusing for maintainers.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
function process(var a) {
|
|
var BAD_OPS = 3;
|
|
if( a = BAD_OPS) {...}
|
|
}
|
|
----
|
|
|
|
[source,javascript]
|
|
----
|
|
function process(var a) {
|
|
var BAD_OPS = "UNKNOWN";
|
|
if( a = BAD_OPS) {...}
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Refactor this suspicious code to not use the result of this non-boolean assignment as a condition
|
|
|
|
|
|
=== Highlighting
|
|
|
|
The overall non-boolean assignment
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== relates to: S1121
|
|
|
|
=== on 21 Mar 2017, 09:50:54 Freddy Mallet wrote:
|
|
Before C99, the C language didn't have any boolean type so applying this rule on C might raise a lot of false-positives.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|