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

57 lines
1.3 KiB
Plaintext

== Why is this an issue?
Mixing up the order of operations will almost always yield unexpected results.
Similarly, mis-applied negation will also yield bad results. For instance consider the difference between ``++!key in dict++`` and ``++!(key in dict)++``. The first looks for a boolean value (``++!key++``) in ``++dict++``, and the other looks for a string and inverts the result. ``++!obj instanceof SomeClass++`` has the same problem.
This rule raises an issue when the left operand of an ``++in++`` or ``++instanceof++`` operator is negated.
=== Noncompliant code example
[source,javascript]
----
if (!"prop" in myObj) { // Noncompliant; "in" operator is checking property "false"
doTheThing(); // this block will be never executed
}
if (!foo instanceof MyClass) { // Noncompliant; "!foo" returns a boolean, which is not an instance of anything
doTheOtherThing(); // this block is never executed
}
----
=== Compliant solution
[source,javascript]
----
if (!("prop" in myObj)) {
doTheThing();
}
if (!(foo instanceof MyClass)) {
doTheOtherThing();
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add parentheses to disambiguate this expression.
=== Highlighting
minus operator
endif::env-github,rspecator-view[]