Back to Biomejs

noEmptySource

src/content/docs/linter/rules/no-empty-source.mdx

latest18.4 KB
Original Source

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

<Tabs> <TabItem label="GraphQL" icon="seti:graphql"> ## Summary - Rule available since: `v2.2.7` - Diagnostic Category: [`lint/suspicious/noEmptySource`](/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). ## How to configure ```json title="biome.json" { "linter": { "rules": { "suspicious": { "noEmptySource": "error" } } } }
## Description
Disallow empty sources.

A source containing only the following is considered empty:

- Whitespace (spaces, tabs or newlines)
- Comments

## Examples

### Invalid

```graphql

<pre class="language-text"><code class="language-text">code-block.graphql:2:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> <strong> │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>
graphql

Valid

graphql
query Member {}
graphql
fragment StrippedMember on Member {}

Options

allowComments

Whether the comments should be marked as meaningful. When this option has been set to true, a file with only comments is considered valid.

Default false

json
{
	"linter": {
		"rules": {
			"suspicious": {
				"noEmptySource": {
					"options": {
						"allowComments": true
					}
				}
			}
		}
	}
}

Invalid

graphql
<pre class="language-text"><code class="language-text">code-block.graphql:2:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> <strong> │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>

Valid

graphql
</TabItem> <TabItem label="CSS" icon="seti:css"> ## Summary - Rule available since: `v2.2.7` - Diagnostic Category: [`lint/suspicious/noEmptySource`](/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-empty-source`](https://github.com/stylelint/stylelint/blob/main/lib/rules/no-empty-source/README.md)

How to configure

json
{
	"linter": {
		"rules": {
			"suspicious": {
				"noEmptySource": "error"
			}
		}
	}
}

Description

Disallow empty sources.

A source containing only the following is considered empty:

  • Whitespace (spaces, tabs or newlines)
  • Comments

Examples

Invalid

css
<pre class="language-text"><code class="language-text">code-block.css:2:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> <strong> │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>
css
/* Only comments */
<pre class="language-text"><code class="language-text">code-block.css:2:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong>1 │ </strong>/&#42; Only comments &#42;/ <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> <strong> │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>

Valid

css
a { }

Options

allowComments

Whether the comments should be marked as meaningful. When this option has been set to true, a file with only comments is considered valid.

Default false

json
{
	"linter": {
		"rules": {
			"suspicious": {
				"noEmptySource": {
					"options": {
						"allowComments": true
					}
				}
			}
		}
	}
}

Invalid

css
<pre class="language-text"><code class="language-text">code-block.css:2:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> <strong> │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>

Valid

css
/* Only comments */
</TabItem> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v2.2.7` - Diagnostic Category: [`lint/suspicious/noEmptySource`](/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 [`unicorn/no-empty-file`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-empty-file.md)

How to configure

json
{
	"linter": {
		"rules": {
			"suspicious": {
				"noEmptySource": "error"
			}
		}
	}
}

Description

Disallow empty sources.

A source containing only the following is considered empty:

  • Whitespace (spaces, tabs or newlines)
  • Comments
  • Directives
  • Empty statements
  • Empty block statements
  • Hashbang

Examples

Invalid

js
<pre class="language-text"><code class="language-text">code-block.js:2:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> <strong> │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>
js
// Only comments
<pre class="language-text"><code class="language-text">code-block.js:2:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong>1 │ </strong>// Only comments <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> <strong> │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>
js
/* Only comments */
<pre class="language-text"><code class="language-text">code-block.js:2:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong>1 │ </strong>/&#42; Only comments &#42;/ <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> <strong> │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>
js
'use strict';
<pre class="language-text"><code class="language-text">code-block.js:1:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>'use strict'; <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><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;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>
js
;
<pre class="language-text"><code class="language-text">code-block.js:1:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>
js
{
}
<pre class="language-text"><code class="language-text">code-block.js:1:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>&#123; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>&#125; <strong> │ </strong><strong><span style="color: Tomato;">^</span></strong> <strong>3 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>
js
#!/usr/bin/env node
<pre class="language-text"><code class="language-text">code-block.js:1:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>1 │ </strong>#!/usr/bin/env node <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><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>2 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>

Valid

js
const x = 0;
js
'use strict';
const x = 0;
js
;;
const x = 0;
js
{
  const x = 0;
}

Options

allowComments

Whether the comments should be marked as meaningful. When this option has been set to true, a file with only comments is considered valid.

Default false

json
{
	"linter": {
		"rules": {
			"suspicious": {
				"noEmptySource": {
					"options": {
						"allowComments": true
					}
				}
			}
		}
	}
}

Invalid

js
<pre class="language-text"><code class="language-text">code-block.js:2:1 <a href="https://biomejs.dev/linter/rules/no-empty-source">lint/suspicious/noEmptySource</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">An empty source is not allowed.</span> <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong> <strong> │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.</span> </code></pre>

Valid

js
/* Only comments */
</TabItem> </Tabs>