markdown-preferences/no-trailing-spaces
disallow trailing whitespace at the end of lines in Markdown files.
- 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
📖 Rule Details
This rule disallows trailing whitespace (spaces and tabs) at the end of lines in Markdown files.
While trailing spaces in Markdown can be used to create hard line breaks (when followed by a line break), they are often unintentional and can cause formatting inconsistencies. This rule helps maintain clean, consistent Markdown files by removing unnecessary trailing whitespace.
Note: This rule preserves intentional hard line breaks created with two trailing spaces followed by a line break.
<!-- eslint markdown-preferences/no-trailing-spaces: 'error' -->
<!-- ✓ GOOD: Two spaces for hard line break -->
foo
bar
<!-- ✓ GOOD: No trailing spaces -->
foo
bar
<!-- ✗ BAD: Trailing spaces on empty line -->
foo
bar
<!-- ✗ BAD: Trailing spaces not followed by content -->
foo
bar
<!--EOF-->
🔧 Options
{
"markdown-preferences/no-trailing-spaces": [
"error",
{
"skipBlankLines": false,
"ignoreComments": false
}
]
}
skipBlankLines
(optional): Whentrue
, the rule ignores trailing spaces on empty lines. Default isfalse
.ignoreComments
(optional): Whentrue
, the rule ignores trailing spaces in HTML comment lines. Default isfalse
.
skipBlankLines
(Default: false
)
When true
, the rule ignores trailing spaces on empty lines.
<!-- eslint markdown-preferences/no-trailing-spaces: ['error', { "skipBlankLines": false }] -->
<!-- ✗ BAD -->
<!--EOF-->
<!-- eslint markdown-preferences/no-trailing-spaces: ['error', { "skipBlankLines": true }] -->
<!-- ✓ GOOD -->
<!--EOF-->
ignoreComments
(Default: false
)
When true
, the rule ignores trailing spaces in HTML comment lines.
<!-- eslint markdown-preferences/no-trailing-spaces: ['error', { "ignoreComments": false }] -->
<!-- ✗ BAD -->
<!--
This is a comment
-->
<!-- eslint markdown-preferences/no-trailing-spaces: ['error', { "ignoreComments": true }] -->
<!-- ✓ GOOD -->
<!--
This is a comment
-->
💡 When to Use This Rule
Use this rule when you want to:
- Maintain consistent whitespace formatting in Markdown files
- Keep your version control diffs clean (trailing spaces often show up as noise)
- Ensure consistent code style across your team
🚀 Version
This rule was introduced in eslint-plugin-markdown-preferences v0.3.0