markdown-preferences/atx-heading-closing-sequence-length
enforce consistent length for the closing sequence (trailing #s) 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
Enforces a consistent length for the closing sequence (trailing #s) in ATX headings (Markdown headings that start with #). This rule does not enforce whether a closing sequence is present or absent. If a closing sequence exists, its length is checked. If the length is incorrect, the number of trailing #s is automatically adjusted by inserting or removing #s as needed. The closing sequence is never removed entirely, and headings without a closing sequence are ignored by this rule. Setext headings (those using === or ---), and headings that consist only of # with no text, are also ignored.
Mode: closing sequence length matches heading level ("match-opening")
<!-- eslint markdown-preferences/atx-heading-closing-sequence-length: ["error", {"mode": "match-opening"}] -->
<!-- ✓ GOOD (with { "mode": "match-opening" }) -->
# Heading #
## Heading ##
<!-- ✗ BAD (with { "mode": "match-opening" }) -->
# Heading ###
## Heading #Mode: closing sequence length is always 2 ({ "mode": "length", "length": 2 })
<!-- eslint markdown-preferences/atx-heading-closing-sequence-length: ["error", {"mode": "length", "length": 2}] -->
<!-- ✓ GOOD (with { "mode": "length", "length": 2 }) -->
# Heading ##
## Heading ##
<!-- ✗ BAD (with { "mode": "length", "length": 2 }) -->
# Heading #
## Heading ###Mode: all headings have a total line length of 30 ({ "mode": "fixed-line-length", "length": 30 })
<!-- eslint markdown-preferences/atx-heading-closing-sequence-length: ["error", {"mode": "fixed-line-length", "length": 30}] -->
<!-- ✓ GOOD (with { "mode": "fixed-line-length", "length": 30 }) -->
# Short heading ##############
## Long heading ##############
<!-- ✗ BAD (with { "mode": "fixed-line-length", "length": 30 }) -->
# Short heading #
## Long heading ###Mode: all headings have the same number of trailing # as the first heading with a closing sequence ("consistent")
<!-- eslint markdown-preferences/atx-heading-closing-sequence-length: ["error", {"mode": "consistent"}] -->
<!-- ✓ GOOD (with { "mode": "consistent" }) -->
# Heading #
## Heading #
<!-- ✗ BAD (with { "mode": "consistent" }) -->
# Heading #
## Heading ##Mode: all headings are padded with trailing # so that each heading line has the same length as the shortest line that can fully contain the longest heading in the document ("consistent-line-length")
<!-- eslint markdown-preferences/atx-heading-closing-sequence-length: ["error", {"mode": "consistent-line-length"}] -->
<!-- ✓ GOOD (with { "mode": "consistent-line-length" }) -->
# Short ##########
## Long heading ##
<!-- ✗ BAD (with { "mode": "consistent-line-length" }) -->
# Short #
## Long heading ###🔧 Options
{
"markdown-preferences/atx-heading-closing-sequence-length": [
"error",
{
"mode": "match-opening"
}
]
}This rule accepts an object option with the following properties:
mode(required):"match-opening"(default): The number of trailing#s must match the number of leading#s (the heading level)."length": All ATX headings must have the specified number of trailing#s. Requires thelengthproperty."consistent": All ATX headings in the document must have the same number of trailing#as the first ATX heading with a closing sequence."consistent-line-length": All ATX headings must be padded with trailing#so that each heading line has the same length as the shortest line that can fully contain the longest heading in the document."fixed-line-length": All ATX headings must have the specified total line length, by padding with trailing#as needed. Requires thelengthproperty.
length(number, required for"length"and"fixed-line-length"): The required length for the closing sequence or the total line length.
📚 Further Reading
👫 Related Rules
🚀 Version
This rule was introduced in eslint-plugin-markdown-preferences v0.13.0