Skip to content

noVoid

¥Summary

  • 规则生效日期:v1.0.0

    ¥Rule available since: v1.0.0

  • 诊断类别:lint/complexity/noVoid

    ¥Diagnostic Category: lint/complexity/noVoid

  • 此规则没有修复方案。

    ¥This rule doesn’t have a fix.

  • 此规则的默认严重级别为 warning

    ¥The default severity of this rule is warning.

  • 来源:

    ¥Sources:

¥How to configure

biome.json
{
"linter": {
"rules": {
"complexity": {
"noVoid": "error"
}
}
}
}

¥Description

禁止使用 void 运算符,因为它不是一个熟悉的运算符。

¥Disallow the use of void operators, which is not a familiar operator.

void 运算符通常仅用于获取未定义的原始值,通常使用 void(0)(相当于 void 0)。在这些情况下,可以使用全局变量 undefined

¥The void operator is often used merely to obtain the undefined primitive value, usually using void(0) (which is equivalent to void 0). In these cases, the global variable undefined can be used.

¥Examples

¥Invalid

void 0;
code-block.js:1:1 lint/complexity/noVoid ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

The use of void is not allowed.

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

If you use void to alter the return type of a function or return `undefined`, use the global `undefined` instead.

¥Related links