Skip to content

noMeaninglessVoidOperator (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noMeaninglessVoidOperator": "error"
}
}
}
}

Disallow void when it does not discard a call’s return value or a thenable.

Using void communicates that a value is deliberately ignored. Applying it to a call that already returns void or undefined obscures that intent and can hide changes to the called API. Non-call operands are also reported, except for thenables and the common void 0 idiom.

invalid-call.ts
declare function log(): void;
void log();
/invalid-call.ts:2:1 lint/nursery/noMeaninglessVoidOperator  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This void operator is unnecessary.

1 │ declare function log(): void;
> 2 │ void log();
│ ^^^^^^^^^^
3 │

ℹ This call already returns void or undefined.

ℹ Use void to explicitly discard a call's return value or a thenable.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the void operator.

1 1 │ declare function log(): void;
2 │ - void·log();
2 │ + (log());
3 3 │

invalid-value.js
void 1;
/invalid-value.js:1:1 lint/nursery/noMeaninglessVoidOperator  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

ℹ This void operator is unnecessary.

> 1 │ void 1;
│ ^^^^^^
2 │

ℹ This operand is neither a function call nor a thenable.

ℹ Use void to explicitly discard a call's return value or a thenable.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the void operator.

1 │ - void·1;
1 │ + (1);
2 2 │

valid.ts
declare function value(): number;
void value();
void Promise.resolve();
void 0;