markdown-preferences/atx-heading-closing-sequence β
enforce consistent use of closing sequence in ATX headings.
- βοΈ This rule is included in
plugin.configs.standard. - π§ The
--fixoption on the command line can automatically fix some of the problems reported by this rule.
π Rule Details β
ATX headings in Markdown are lines that start with 1β6 # characters, followed by a space and the heading text. According to the CommonMark specification, ATX headings may optionally end with a "closing sequence"βone or more # characters, which must be preceded by a space or tab, and may be followed by spaces or tabs until the end of the line.
For example, all of the following are valid ATX headings:
# Heading 1
# Heading 1 #
# Heading 1 ###The closing sequence is purely stylistic and has no effect on the rendered output. However, inconsistent use of closing sequences within a document or project can reduce readability and make automated formatting more difficult.
This rule enforces a consistent style for the presence or absence of closing sequences in ATX headings. You can configure it to either always require ("always") or always forbid ("never") the use of closing sequences.
Why enforce this?
- Consistency: Ensures all headings in your documentation or codebase follow the same style, improving readability and maintainability.
- Formatting: Helps avoid accidental trailing
#s in heading content, which can be confusing or look like typos. - Tooling: Makes it easier for automated tools and linters to process and format Markdown files.
When is this rule useful?
- When you want to enforce a uniform Markdown style across a team or project.
- When you want to prevent accidental or inconsistent use of closing
#s in headings. - When integrating with documentation generators or static site tools that expect a certain heading style.
Depending on your configuration, this rule will require ("always") or forbid ("never") the use of closing sequences in ATX headings.
Examples β
Default Configuration ("never") β
<!-- eslint markdown-preferences/atx-heading-closing-sequence: "error" -->
<!-- β GOOD -->
# Heading 1
## Heading 2
### Heading 3
<!-- β BAD -->
# Heading 1 #
## Heading 2 ##
### Heading 3 ###With "always" Configuration β
<!-- eslint markdown-preferences/atx-heading-closing-sequence: ["error", { "closingSequence": "always" }] -->
<!-- β GOOD -->
# Heading 1 #
## Heading 2 ##
### Heading 3 ###
<!-- β BAD -->
# Heading 1
## Heading 2
### Heading 3π§ Options β
This rule has one option:
{
"markdown-preferences/atx-heading-closing-sequence": [
"error",
{ "closingSequence": "never" }
]
}closingSequence... Specify the closing sequence style for ATX headings. Default is"never"."never"... Forbid closing sequence in ATX headings."always"... Require closing sequence in ATX headings.
π Further Reading β
π« Related Rules β
π Version β
This rule was introduced in eslint-plugin-markdown-preferences v0.13.0