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
Reported:
let selected = void 0;
button.onclick = () => void save();
Not reported:
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.
void save();
Anywhere else, void is still reported:
const result = void save();