noEmptySource (YAML)
Summary
Section titled “Summary”- Rule available since:
v2.6.0 - Diagnostic Category:
lint/suspicious/noEmptySource - 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.
- Sources:
- Same as
yml/no-empty-document
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "suspicious": { "noEmptySource": "error" } } }}Description
Section titled “Description”Disallow empty sources.
A YAML file can hold several documents, separated by --- lines.
This rule reports each document that has no content, and files that contain no documents at all.
A document that only has a tag (such as !!map) or an anchor (such as &config) also counts as empty,
because it still holds no value.
Empty documents and files are usually leftovers from editing, and tools that read the file
get an empty value (null) for them.
By default, whitespace and comments do not count as content.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”code-block.yaml:2:1 lint/suspicious/noEmptySource ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ An empty source is not allowed.
> 2 │
│
ℹ Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.
# Only commentscode-block.yaml:2:1 lint/suspicious/noEmptySource ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ An empty source is not allowed.
1 │ # Only comments
> 2 │
│
ℹ Empty sources can clutter the codebase and increase cognitive load; deleting empty sources can help reduce it.
name: foo---code-block.yaml:2:1 lint/suspicious/noEmptySource ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ An empty document is not allowed.
1 │ name: foo
> 2 │ ---
│ ^^^
3 │
ℹ Tools that read this file get an empty value for this document, which is rarely intended.
ℹ Add content to the document, or remove it.
--- !!mapcode-block.yaml:1:1 lint/suspicious/noEmptySource ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ An empty document is not allowed.
> 1 │ --- !!map
│ ^^^^^^^^^
2 │
ℹ Tools that read this file get an empty value for this document, which is rarely intended.
ℹ Add content to the document, or remove it.
name: foo---name: barOptions
Section titled “Options”allowComments
Section titled “allowComments”Default: false
Treats comments as meaningful content when set to true, so a file or document that only
contains comments is valid.
An entirely empty file or document remains invalid.
{ "linter": { "rules": { "suspicious": { "noEmptySource": { "level": "on", "options": { "allowComments": true } } } } }}Invalid
Section titled “Invalid”name: foo---code-block.yaml:2:1 lint/suspicious/noEmptySource ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ An empty document is not allowed.
1 │ name: foo
> 2 │ ---
│ ^^^
3 │
ℹ Tools that read this file get an empty value for this document, which is rarely intended.
ℹ Add content to the document, or remove it.
name: foo---# Only commentsRelated links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.