[PR #1973] [CLOSED] fix(md012): do not flag blank lines adjacent to headings (fixes #990). #3691

Closed
opened 2026-03-07 20:14:59 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/DavidAnson/markdownlint/pull/1973
Author: @rvben
Created: 2/21/2026
Status: Closed

Base: nextHead: fix/md012-heading-adjacent-blanks


📝 Commits (1)

  • ccd26ce fix(md012): do not flag blank lines adjacent to headings (fixes #990).

📊 Changes

7 files changed (+106 additions, -4 deletions)

View changed files

📝 doc-build/md012.md (+4 -0)
📝 doc/Rules.md (+4 -0)
📝 doc/md012.md (+4 -0)
📝 lib/md012.mjs (+23 -4)
test/no-multiple-blanks-headings.md (+23 -0)
📝 test/snapshots/markdownlint-test-scenarios.mjs.md (+48 -0)
📝 test/snapshots/markdownlint-test-scenarios.mjs.snap (+0 -0)

📄 Description

Fixes #990.

When MD022 is configured with lines_above or lines_below greater than 1,
the required blank lines are also flagged by MD012, making the two rules
impossible to satisfy simultaneously.

This change pre-computes the blank lines immediately adjacent to each heading
and excludes them from MD012's check. Those blank lines are governed by
MD022, so MD012 defers to it. The adjacent-blank walk uses isBlankLine()
(the same helper MD022 uses) so both rules count heading-adjacent blank lines
consistently.

A new test fixture covers the case, and the rule documentation notes that
heading-adjacent blank lines are governed by MD022.

Note: this PR was developed with AI assistance. I'm disclosing this in line
with the contributing guidelines and leaving it to your discretion whether
to accept it.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/DavidAnson/markdownlint/pull/1973 **Author:** [@rvben](https://github.com/rvben) **Created:** 2/21/2026 **Status:** ❌ Closed **Base:** `next` ← **Head:** `fix/md012-heading-adjacent-blanks` --- ### 📝 Commits (1) - [`ccd26ce`](https://github.com/DavidAnson/markdownlint/commit/ccd26cef7f2ab683314c266532deea3e92f4b0dd) fix(md012): do not flag blank lines adjacent to headings (fixes #990). ### 📊 Changes **7 files changed** (+106 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `doc-build/md012.md` (+4 -0) 📝 `doc/Rules.md` (+4 -0) 📝 `doc/md012.md` (+4 -0) 📝 `lib/md012.mjs` (+23 -4) ➕ `test/no-multiple-blanks-headings.md` (+23 -0) 📝 `test/snapshots/markdownlint-test-scenarios.mjs.md` (+48 -0) 📝 `test/snapshots/markdownlint-test-scenarios.mjs.snap` (+0 -0) </details> ### 📄 Description Fixes #990. When `MD022` is configured with `lines_above` or `lines_below` greater than 1, the required blank lines are also flagged by `MD012`, making the two rules impossible to satisfy simultaneously. This change pre-computes the blank lines immediately adjacent to each heading and excludes them from `MD012`'s check. Those blank lines are governed by `MD022`, so `MD012` defers to it. The adjacent-blank walk uses `isBlankLine()` (the same helper `MD022` uses) so both rules count heading-adjacent blank lines consistently. A new test fixture covers the case, and the rule documentation notes that heading-adjacent blank lines are governed by `MD022`. Note: this PR was developed with AI assistance. I'm disclosing this in line with the contributing guidelines and leaving it to your discretion whether to accept it. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-07 20:14:59 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#3691
No description provided.