no-void
Disallow the void operator
void expression runs the expression and returns undefined. Few people know the operator, and undefined says the same thing in a word everybody can read.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"no-void" = "error" # or "warn"Every option, set to its default:
bunfig.toml
[lint.rules]
"no-void" = ["error", {
allowAsStatement = false,
}]Examples#
example.js2 problems
let selected = void 0Expected undefined and instead saw void.;
button.onclick = () => void save()Expected undefined and instead saw void.;example.jsNo problems
let selected = undefined;
button.onclick = () => {
save();
};Options#
| Option | Default | What it does |
|---|---|---|
allowAsStatement | false | Allow void when it's the whole statement. |
void at the start of a statement is how you tell @typescript-eslint/no-floating-promises that you're ignoring a promise on purpose. Turn this option on if you use both rules.
example.jswith
{ "allowAsStatement": true }No problemsvoid save();Anywhere else, void is still reported:
example.jswith
{ "allowAsStatement": true }1 problemconst result = void save()Expected undefined and instead saw void.;