Back to Biomejs

noVoid

src/content/docs/linter/rules/no-void.mdx

latest2.8 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/complexity/noVoid`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`no-void`](https://eslint.org/docs/latest/rules/no-void)

How to configure

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

Description

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

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

js
void 0;
<pre class="language-text"><code class="language-text">code-block.js:1:1 <a href="https://biomejs.dev/linter/rules/no-void">lint/complexity/noVoid</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">The use of </span><span style="color: Orange;"><strong>void</strong></span><span style="color: Orange;"> is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>void 0; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">If you use </span><span style="color: lightgreen;"><strong>void</strong></span><span style="color: lightgreen;"> to alter the return type of a function or return &#96;undefined&#96;, use the global &#96;undefined&#96; instead.</span> </code></pre> </TabItem> </Tabs>