53 lines
1.2 KiB
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
str = "80";
quarter = str / 4; // Noncompliant
if (str < 10) { // Noncompliant
// ...
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
str = "80";
parsedStr = parseInt(str);
quarter = parsedStr / 4;
if (parsedStr < 10) {
// ...
}
----
2021-04-28 16:49:39 +02:00
== 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)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]