
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.
58 lines
1.2 KiB
Plaintext
58 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Use a ``+`` with two numbers and you'll get addition. But use it with a string and anything else, and you'll get concatenation. This could be confusing, especially if it's not obvious that one of the operands is a string. It is recommended to explicitly convert the non-string component to make it easier to understand to future maintainers.
|
|
|
|
|
|
This rule raises an issue when ``+`` or ``+=`` is used with a string and a non-string.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,javascript]
|
|
----
|
|
function foo() {
|
|
let x = 5 + 8; // okay
|
|
let z = "8"
|
|
return x + z; // Noncompliant; yields string "138"
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,javascript]
|
|
----
|
|
function foo() {
|
|
let x = 5 + 8;
|
|
let z = "8"
|
|
return x + Number(z);
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Review this expression to be sure that the concatenation was intended.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
* Primary: operator ``+``
|
|
* Additional: operands
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 20 Nov 2015, 17:20:49 Elena Vilchik wrote:
|
|
\[~ann.campbell.2] Perfect, thanks!
|
|
|
|
endif::env-github,rspecator-view[]
|