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

66 lines
1.6 KiB
Plaintext

== Why is this an issue?
Expressions with arithmetic (``/, {empty}*, %, {plus}{plus}, --, -, -=, {empty}*=, /=, %=, +=, {plus}``), unary (``++-++``), or comparison operators (``++>, <, >=, <=++``) where one, or both, of the operands is a String, Boolean or Date value rely on implicit conversions. Both the maintainability and reliability levels of such a piece of code are questionable.
=== Noncompliant code example
[source,javascript]
----
str = "80";
quarter = str / 4; // Noncompliant
if (str < 10) { // Noncompliant
// ...
}
----
=== Compliant solution
[source,javascript]
----
str = "80";
parsedStr = parseInt(str);
quarter = parsedStr / 4;
if (parsedStr < 10) {
// ...
}
----
=== Exceptions
* Expressions using the binary ``{plus}`` operator with at least one ``++String++`` operand are ignored because the ``{plus}`` operator will perform a concatenation in that case.
* Comparisons where both operands are strings are ignored because a lexicographical comparison is performed in that case.
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Convert this operand into a number.
=== Highlighting
Primary: non numerical operand
'''
== Comments And Links
(visible only on this page)
=== on 18 Oct 2016, 10:59:01 Pierre-Yves Nicolas wrote:
The current title of the rule seems rather vague to me. Shouldn't it mention "arithmetic and comparison expressions"?
=== on 18 Oct 2016, 13:09:38 Ann Campbell wrote:
\[~jeanchristophe.collet], please reword title into canonical form (x should [not] y)
endif::env-github,rspecator-view[]