Back to Biomejs

noExportedImports

src/content/docs/linter/rules/no-exported-imports.mdx

latest5.5 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.9.0` - Diagnostic Category: [`lint/style/noExportedImports`](/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 [**information**](/reference/diagnostics#information). ## How to configure ```json title="biome.json" { "linter": { "rules": { "style": { "noExportedImports": "error" } } } }
## Description
Disallow exporting an imported variable.

In JavaScript, you can re-export a variable either by using `export from` or
by first importing the variable and then exporting it with a regular `export`.

You may prefer to use the first approach, as it clearly communicates the intention
to re-export an import, and can make static analysis easier.

## Examples

### Invalid

```js
import { A } from "mod";
export { A };
<pre class="language-text"><code class="language-text">code-block.js:1:10 <a href="https://biomejs.dev/linter/rules/no-exported-imports">lint/style/noExportedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">An import should not be exported. Use </span><span style="color: lightgreen;"><strong>export from</strong></span><span style="color: lightgreen;"> instead.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#123; A &#125; from &quot;mod&quot;; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong>export &#123; A &#125;; <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;"><strong>export from</strong></span><span style="color: lightgreen;"> makes it clearer that the intention is to re-export a variable.</span> </code></pre>
js
import * as ns from "mod";
export { ns };
<pre class="language-text"><code class="language-text">code-block.js:1:8 <a href="https://biomejs.dev/linter/rules/no-exported-imports">lint/style/noExportedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">An import should not be exported. Use </span><span style="color: lightgreen;"><strong>export from</strong></span><span style="color: lightgreen;"> instead.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import &#42; as ns from &quot;mod&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><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong>export &#123; ns &#125;; <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;"><strong>export from</strong></span><span style="color: lightgreen;"> makes it clearer that the intention is to re-export a variable.</span> </code></pre>
js
import D from "mod";
export { D };
<pre class="language-text"><code class="language-text">code-block.js:1:8 <a href="https://biomejs.dev/linter/rules/no-exported-imports">lint/style/noExportedImports</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">An import should not be exported. Use </span><span style="color: lightgreen;"><strong>export from</strong></span><span style="color: lightgreen;"> instead.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>import D from &quot;mod&quot;; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong>export &#123; D &#125;; <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;"><strong>export from</strong></span><span style="color: lightgreen;"> makes it clearer that the intention is to re-export a variable.</span> </code></pre>

Valid

js
export { A } from "mod";
export * as ns from "mod";
export { default as D } from "mod";
</TabItem> </Tabs>