[GH-ISSUE #1957] MD022: Consider adding parameter to require blank lines between front matter and first heading #2635

Open
opened 2026-03-07 20:09:34 +03:00 by kerem · 4 comments
Owner

Originally created by @thompson-tomo on GitHub (Feb 14, 2026).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1957

What did you do?

My markdown looks like

---
title: page title
---
## Content

What did you expect to happen?

When I run markdownlint I expected a MD022 violation to have been raised due to no space before header.

What actually happened?

No violations were reported

Originally created by @thompson-tomo on GitHub (Feb 14, 2026). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1957 <!-- Thank you for taking the time to report an issue! When deciding where to open an issue, please note there are multiple projects under the markdownlint umbrella: - https://github.com/DavidAnson/markdownlint : This is the core JavaScript/Node.js library and is used by other tools. Most issues with implementation and rule behavior belong here. - https://github.com/igorshubovych/markdownlint-cli : This is the original CLI for markdownlint. Issues specific to CLI belong here. - https://github.com/DavidAnson/markdownlint-cli2 : This is a newer CLI for markdownlint and is used by other tools. Issues specific to CLI2 belong here. - https://github.com/DavidAnson/vscode-markdownlint : This is the Visual Studio Code extension for markdownlint. Issues specific to VS Code belong here. - https://github.com/DavidAnson/markdownlint-cli2-action : This is a GitHub Action for markdownlint. Issues specific to the Action belong here. - https://github.com/markdownlint/markdownlint : This is the original markdownlint implementation for Ruby. All Ruby-related issues belong here. Before creating an issue, it's a good practice to search existing issues for something similar. If your issue has already been reported, please update the existing one with any new information. It's also good to review the documentation for any relevant details. When describing an issue, the following information is helpful: - What did you do? - What did you expect to happen? - What actually happened? - What messages or errors were there? - How can the issue be reproduced? - What version were you using? - What operating system were you using? The simplest demonstration of a problem is the most helpful. Small examples can be pasted into the issue description. (Be sure to paste as code so GitHub doesn't render the example in Markdown.) For larger examples, linking to a repository or file is more appropriate. Before proposing a new rule, please review the existing suggestions: https://github.com/DavidAnson/markdownlint/issues?q=is%3Aissue+is%3Aopen+label%3A%22new+rule%22 Thank you! --> ## What did you do? My markdown looks like ```markdown --- title: page title --- ## Content ``` ## What did you expect to happen? When I run markdownlint I expected a MD022 violation to have been raised due to no space before header. ## What actually happened? No violations were reported
Author
Owner

@DavidAnson commented on GitHub (Feb 14, 2026):

Front matter like that is removed by tooling and not considered part of the Markdown document. As far as the parser is concerned, the document starts its first line with the heading.

I see why this looks like a failure of the rule, but I do not think it is meaningful in the context of the rule's intent which is to make sure that headings are always recognized as such.

https://github.com/DavidAnson/markdownlint/blob/main/doc/md022.md

<!-- gh-comment-id:3902176690 --> @DavidAnson commented on GitHub (Feb 14, 2026): Front matter like that is removed by tooling and not considered part of the Markdown document. As far as the parser is concerned, the document starts its first line with the heading. I see why this looks like a failure of the rule, but I do not think it is meaningful in the context of the rule's intent which is to make sure that headings are always recognized as such. https://github.com/DavidAnson/markdownlint/blob/main/doc/md022.md
Author
Owner

@thompson-tomo commented on GitHub (Feb 14, 2026):

I understand, but note for other rules we have an option to consider front matter. Could we do similar here and add an option to consider front matter?

<!-- gh-comment-id:3902757532 --> @thompson-tomo commented on GitHub (Feb 14, 2026): I understand, but note for other rules we have an option to consider front matter. Could we do similar here and add an option to consider front matter?
Author
Owner

@dgenio commented on GitHub (Feb 17, 2026):

+1 on this enhancement. I maintain a prompt library repo (my_prompts)
that uses YAML frontmatter extensively — every markdown file starts with --- delimited metadata.

We currently have MD022 entirely disabled in our .markdownlint.json because of this
exact interaction. We'd love to re-enable it with frontmatter awareness.

Our config also disables MD041 (first line should be top-level heading) for the same
reason — frontmatter is always line 1, not a heading. If this enhancement moves forward,
it might be worth considering a similar frontmatter-aware parameter for MD041 as well.

Concrete use case: we have ~30+ prompt files, all following this structure:

---
title: My Prompt
category: coding
tags: [python, testing]
version: "1.0.0"
---

## Purpose
...

We want MD022 to enforce blank lines around ## Purpose and other headings,
but NOT flag the transition from the closing --- to the first heading.
An optional parameter like frontmatter_spacing: true/false or
lines_above_from_front_matter: 1 would let us re-enable MD022 properly.

Happy to help test or contribute a PR if the approach is agreed upon.

<!-- gh-comment-id:3914770215 --> @dgenio commented on GitHub (Feb 17, 2026): +1 on this enhancement. I maintain a prompt library repo ([my_prompts](https://github.com/dgenio/my_prompts)) that uses YAML frontmatter extensively — every markdown file starts with `---` delimited metadata. We currently have `MD022` entirely disabled in our `.markdownlint.json` because of this exact interaction. We'd love to re-enable it with frontmatter awareness. Our config also disables `MD041` (first line should be top-level heading) for the same reason — frontmatter is always line 1, not a heading. If this enhancement moves forward, it might be worth considering a similar frontmatter-aware parameter for MD041 as well. Concrete use case: we have ~30+ prompt files, all following this structure: --- title: My Prompt category: coding tags: [python, testing] version: "1.0.0" --- ## Purpose ... We want MD022 to enforce blank lines around `## Purpose` and other headings, but NOT flag the transition from the closing `---` to the first heading. An optional parameter like `frontmatter_spacing: true/false` or `lines_above_from_front_matter: 1` would let us re-enable MD022 properly. Happy to help test or contribute a PR if the approach is agreed upon.
Author
Owner
<!-- gh-comment-id:3916034361 --> @DavidAnson commented on GitHub (Feb 17, 2026): MD041 reports no issues for the example above: https://dlaa.me/markdownlint/#%25m---%0Atitle%3A%20My%20Prompt%0Acategory%3A%20coding%0Atags%3A%20%5Bpython%2C%20testing%5D%0Aversion%3A%20%221.0.0%22%0A---%0A%0A%23%23%20Purpose%0A
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#2635
No description provided.