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 0;

button.onclick = () => void save();
example.jsNo problems
let selected = undefined;

button.onclick = () => {
  save();
};

Options#

OptionDefaultWhat it does
allowAsStatementfalseAllow 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 problems
void save();

Anywhere else, void is still reported:

example.jswith { "allowAsStatement": true }1 problem
const result = void save();