87 lines
1.8 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
The ``++void++`` operator evaluates its argument and unconditionally returns ``++undefined++``. It can be useful in pre-ECMAScript 5 environments, where ``++undefined++`` could be reassigned, but generally, its use makes code harder to understand.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
void doSomething();
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
doSomething();
----
=== Exceptions
2021-04-28 16:49:39 +02:00
No issue is raised when ``++void 0++`` is used in place of ``++undefined++``.
2021-04-28 16:49:39 +02:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
if (parameter === void 0) {...}
----
No issue is raised when ``++void++`` is used before immediately invoked function expressions.
2021-04-28 16:49:39 +02:00
[source,javascript]
2021-04-28 16:49:39 +02:00
----
void (function() {
...
}());
----
No issue is raised when ``++void++``'s argument is a promise.
[source,javascript]
----
const promise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('done');
}, 3000);
});
void promise;
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Remove this use of the 'void' operator.
=== Highlighting
``++void arg++``
'''
== Comments And Links
(visible only on this page)
=== on 30 Sep 2016, 10:14:28 Elena Vilchik wrote:
\[~ann.campbell.2] Hi! Could you finish this ticket? Thanks!
(I'm struggling to define severity)
=== on 30 Sep 2016, 16:47:30 Ann Campbell wrote:
\[~elena.vilchik] could you supply some code samples?
=== on 30 Sep 2016, 17:13:13 Elena Vilchik wrote:
\[~ann.campbell.2] done
=== on 14 Mar 2017, 10:33:27 Elena Vilchik wrote:
\[~ann.campbell.2] Hi! we added exclusion to this rule: ``++void 0++`` used as ``++undefined++``. Could you update main part of description, as it's outdated now. Thanks!
endif::env-github,rspecator-view[]