All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.javascript.rules.javascript.S3735.html Maven / Gradle / Ivy

There is a newer version: 10.17.0.28100
Show newest version

Why is this an issue?

The void operator evaluates its argument and always returns undefined. void allows using any expression where an undefined is expected. However, using void makes code more difficult to understand, as the intent is often unclear.

if (parameter === void 42) { // Noncompliant
   // ...
}
doSomethingElse(void doSomething()); // Noncompliant

Instead of using void to get the undefined value, use the undefined global property. In ECMAScript5 and newer environments, undefined cannot be reassigned. In other cases, remove the void operator to avoid confusion for maintainers.

if (parameter === undefined) {
   // ...
}
doSomething();
doSomethingElse();

Exceptions

  • void 0 (or the equivalent void(0)) is allowed as it was a conventional way to obtain the undefined value in environments before ECMAScript 5.
if (parameter === void 0) {
   // ...
}
  • void is allowed with immediately invoked function expressions.
void function() {
   // ...
}();
const runPromise = () => Promise.resolve();
void runPromise();

Resources

Documentation





© 2015 - 2024 Weber Informatics LLC | Privacy Policy