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

65 lines
1.4 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
[source,javascript]
----
function pickNumber() {
let i = 0;
i = i++; // Noncompliant; i is still zero
return i++; // Noncompliant; 0 returned
}
----
=== Compliant solution
[source,javascript]
----
function pickNumber() {
let i = 0;
i++;
return ++i;
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
=== on 16 Mar 2015, 13:31:43 Pierre-Yves Nicolas wrote:
Raising issues on "return i{plus}{plus}" would lead to false positives because variable i can be referenced and used by other places in the code: it could be an object property and it could also be referenced by a closure.
=== on 16 Mar 2015, 14:34:31 Ann Campbell wrote:
I'm confused, [~pierre-yves.nicolas]. The original code examples showed post-incrementing a method-scope var...?
=== on 16 Mar 2015, 14:46:43 Pierre-Yves Nicolas wrote:
\[~ann.campbell.2]: the following example illustrates the case of a closure which keeps a reference on a variable:
----
function f(x) {
var i = 0;
x.y = function () { return i; };
return i++;
}
var z = {};
f(z); // 0
z.y(); // 1
----
I don't think we can currently raise issues on "return i{plus}{plus};" without false positives.
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]