markdown-preferences/hard-linebreak-style
enforce consistent hard linebreak style.
- ⚙️ This rule is included in
plugin.configs.recommended
. - 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
📖 Rule Details
This rule enforces a consistent hard linebreak style in Markdown files. In Markdown, there are two ways to create hard line breaks:
- Backslash style (
\
): A backslash at the end of a line - Spaces style: Two or more spaces at the end of a line
Both styles are valid in CommonMark, but using one consistently improves readability and maintainability.
Examples
Default Configuration ("backslash"
)
md
<!-- eslint markdown-preferences/hard-linebreak-style: 'error' -->
<!-- ✓ GOOD -->
This line ends with a backslash\
and continues here.
Another example with\
multiple line breaks.
<!-- ✗ BAD -->
This line ends with spaces
and continues here.
<!-- ✗ BAD -->
Mixed styles are not allowed\
this line uses spaces
inconsistently.
With "spaces"
Configuration
md
<!-- eslint markdown-preferences/hard-linebreak-style: ['error', { style: 'spaces' }] -->
<!-- ✓ GOOD -->
This line ends with spaces
and continues here.
Another example with
multiple line breaks.
<!-- ✗ BAD -->
This line ends with backslash\
and continues here.
When Not to Use
- If you don't need consistent hard linebreak styles in your project
- If you're working with existing content that deliberately uses mixed styles
- If you're using a different Markdown processor that has specific requirements
🔧 Options
json
{
"markdown-preferences/hard-linebreak-style": [
"error",
{
"style": "backslash" // or "spaces"
}
]
}
style
(optional): The style of hard linebreak to enforce. Can be"backslash"
(default) or"spaces"
.
style
("backslash" | "spaces"
)
The style of hard linebreak to enforce.
Available Options:
"backslash"
(default): Enforces the use of backslashes (\
) for hard linebreaks."spaces"
: Enforces the use of two or more spaces for hard linebreaks.
📚 Further Reading
👫 Related Rules
🚀 Version
This rule was introduced in eslint-plugin-markdown-preferences v0.1.0