90 lines
1.8 KiB
Plaintext
90 lines
1.8 KiB
Plaintext
== Why is this an issue?
|
|
|
|
The `void` operator evaluates its argument and always returns `undefined`.
|
|
|
|
[source,javascript]
|
|
----
|
|
void doSomething();
|
|
----
|
|
|
|
It can be useful to prevent reassigning `undefined` in pre-ECMAScript 5 environments. However, using `void` makes code more difficult to understand.
|
|
|
|
[source,javascript]
|
|
----
|
|
doSomething();
|
|
----
|
|
|
|
=== Exceptions
|
|
|
|
No issue is raised when ``++void 0++`` is used in place of ``++undefined++``.
|
|
|
|
[source,javascript]
|
|
----
|
|
if (parameter === void 0) {...}
|
|
----
|
|
|
|
No issue is raised when ``++void++`` is used before immediately invoked function expressions.
|
|
|
|
[source,javascript]
|
|
----
|
|
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;
|
|
----
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/void[MDN - Void]
|
|
|
|
|
|
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[]
|