mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-25 01:05:55 +03:00
[GH-ISSUE #1957] MD022: Consider adding parameter to require blank lines between front matter and first heading #2635
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#2635
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
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
@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
@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?
@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
MD022entirely disabled in our.markdownlint.jsonbecause of thisexact 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 samereason — 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:
We want MD022 to enforce blank lines around
## Purposeand other headings,but NOT flag the transition from the closing
---to the first heading.An optional parameter like
frontmatter_spacing: true/falseorlines_above_from_front_matter: 1would let us re-enable MD022 properly.Happy to help test or contribute a PR if the approach is agreed upon.
@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