Skip to content

markdown-preferences/no-multiple-empty-lines

disallow multiple empty lines in Markdown files.

  • 🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.

📖 Rule Details

This rule helps maintain clean and readable Markdown files by limiting consecutive empty lines, ensuring consistent spacing and a professional appearance. Empty lines within code blocks and frontmatter (YAML, TOML, JSON) are ignored, allowing flexible formatting where needed.

By enforcing this rule, teams can maintain a consistent style in collaborative projects, prevent unnecessary diffs in version control, and ensure documents are easy to navigate.

Practical Scenarios

  1. Organized Documentation: When creating long documents with multiple sections, consistent spacing ensures the structure is easy to follow. This rule eliminates excessive blank lines, making the document more professional and readable.

  2. Improved Collaboration: In collaborative projects, maintaining consistent spacing helps team members quickly understand the document structure, reducing confusion and improving productivity.

  3. Streamlined Reviews: Consistent formatting minimizes unnecessary diffs in version control, making code reviews and document updates more efficient.

md
<!-- eslint markdown-preferences/no-multiple-empty-lines: 'error' -->

<!-- ✓ GOOD -->

# Heading

Paragraph

Another paragraph

<!-- ✗ BAD (multiple empty lines) -->

# Heading

Paragraph
md
---
# ✓ GOOD (frontmatter is excluded)
title: Example


---

Paragraph
md
<!-- eslint markdown-preferences/no-multiple-empty-lines: 'error' -->

<!-- ✓ GOOD (code block is excluded) -->

```
code block


Paragraph
```

🔧 Options

json
{
  "markdown-preferences/no-multiple-empty-lines": [
    "error",
    {
      "max": 1,
      "maxEOF": 0,
      "maxBOF": 0
    }
  ]
}
  • max: Maximum number of consecutive empty lines allowed between content blocks. Default is 1.
  • maxEOF: Maximum number of consecutive empty lines allowed at the end of the file. Default is 0.
  • maxBOF: Maximum number of consecutive empty lines allowed at the beginning of the file. Default is 0.

🚀 Version

This rule was introduced in eslint-plugin-markdown-preferences v0.10.0

🔍 Implementation