Back to Biomejs

noUselessEmptyExport

src/content/docs/linter/rules/no-useless-empty-export.mdx

latest9.0 KB
Original Source

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

<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/complexity/noUselessEmptyExport`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`@typescript-eslint/no-useless-empty-export`](https://typescript-eslint.io/rules/no-useless-empty-export)

How to configure

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

Description

Disallow empty exports that don't change anything in a module file.

An empty export {} is sometimes useful to turn a file that would otherwise be a script into a module. Per the TypeScript Handbook Modules page:

In TypeScript, just as in ECMAScript 2015, any file containing a top-level import or export is considered a module. Conversely, a file without any top-level import or export declarations is treated as a script whose contents are available in the global scope.

However, an export {} statement does nothing if there are any other top-level import or export in the file.

Examples

Invalid

js
import { A } from "module";
export {};
<pre class="language-text"><code class="language-text">code-block.js:2:1 <a href="https://biomejs.dev/linter/rules/no-useless-empty-export">lint/complexity/noUselessEmptyExport</a> <span style="color: #000; background-color: #ddd;"> FIXABLE </span> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This empty </span><span style="color: lightgreen;"><strong>export</strong></span><span style="color: lightgreen;"> is useless because there's another </span><span style="color: lightgreen;"><strong>export</strong></span><span style="color: lightgreen;"> or </span><span style="color: lightgreen;"><strong>import</strong></span><span style="color: lightgreen;">.</span> <strong>1 │ </strong>import &#123; A &#125; from &quot;module&quot;; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>export &#123;&#125;; <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><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>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This </span><span style="color: lightgreen;"><strong>import</strong></span><span style="color: lightgreen;"> makes useless the empty export.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#123; A &#125; from &quot;module&quot;; <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>export &#123;&#125;; <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Safe fix</span><span style="color: lightgreen;">: </span><span style="color: lightgreen;">Remove this useless empty export.</span> <strong>1</strong> <strong>1</strong><strong> │ </strong> import &#123; A &#125; from &quot;module&quot;; <strong>2</strong> <strong> │ </strong><span style="color: Tomato;">-</span> <span style="color: Tomato;"><strong>e</strong></span><span style="color: Tomato;"><strong>x</strong></span><span style="color: Tomato;"><strong>p</strong></span><span style="color: Tomato;"><strong>o</strong></span><span style="color: Tomato;"><strong>r</strong></span><span style="color: Tomato;"><strong>t</strong></span><span style="color: Tomato;"><span style="opacity: 0.8;"><strong>·</strong></span></span><span style="color: Tomato;"><strong>&#123;</strong></span><span style="color: Tomato;"><strong>&#125;</strong></span><span style="color: Tomato;"><strong>;</strong></span> <strong>3</strong> <strong>2</strong><strong> │ </strong> </code></pre>
js
export const A = 0;
export {};
<pre class="language-text"><code class="language-text">code-block.js:2:1 <a href="https://biomejs.dev/linter/rules/no-useless-empty-export">lint/complexity/noUselessEmptyExport</a> <span style="color: #000; background-color: #ddd;"> FIXABLE </span> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This empty </span><span style="color: lightgreen;"><strong>export</strong></span><span style="color: lightgreen;"> is useless because there's another </span><span style="color: lightgreen;"><strong>export</strong></span><span style="color: lightgreen;"> or </span><span style="color: lightgreen;"><strong>import</strong></span><span style="color: lightgreen;">.</span> <strong>1 │ </strong>export const A = 0; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>export &#123;&#125;; <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><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>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This </span><span style="color: lightgreen;"><strong>export</strong></span><span style="color: lightgreen;"> makes useless the empty export.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>export const A = 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>export &#123;&#125;; <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Safe fix</span><span style="color: lightgreen;">: </span><span style="color: lightgreen;">Remove this useless empty export.</span> <strong>1</strong> <strong>1</strong><strong> │ </strong> export const A = 0; <strong>2</strong> <strong> │ </strong><span style="color: Tomato;">-</span> <span style="color: Tomato;"><strong>e</strong></span><span style="color: Tomato;"><strong>x</strong></span><span style="color: Tomato;"><strong>p</strong></span><span style="color: Tomato;"><strong>o</strong></span><span style="color: Tomato;"><strong>r</strong></span><span style="color: Tomato;"><strong>t</strong></span><span style="color: Tomato;"><span style="opacity: 0.8;"><strong>·</strong></span></span><span style="color: Tomato;"><strong>&#123;</strong></span><span style="color: Tomato;"><strong>&#125;</strong></span><span style="color: Tomato;"><strong>;</strong></span> <strong>3</strong> <strong>2</strong><strong> │ </strong> </code></pre>

Valid

js
export {};
</TabItem> </Tabs>