Skip to content

MD009 - no-trailing-spaces

Description

This rule detects trailing whitespace at the end of lines. It triggers on any lines that end with unexpected whitespace, with exceptions for intentional line breaks (typically 2 spaces). Code blocks and inline code spans are skipped unless code_blocks is enabled, and front matter is never checked.

Fixable: Yes

Rationale

Except when used to create a line break, trailing whitespace has no purpose and does not affect rendering. Trailing spaces create unnecessary clutter in source files and can cause inconsistencies across different editors and version control systems.

Configuration

br_spaces

Number of trailing spaces to allow for hard line breaks. When set to 2 or higher, lines ending with exactly this many spaces (preceded by a non-whitespace character) are allowed as they create
elements. Setting to 0 or 1 disables this exception.

  • Default: 2
code_blocks

Whether to check code blocks and inline code spans for trailing spaces. When False (default), fenced code blocks, indented code blocks, and whitespace inside inline code spans that wrap onto the next line are ignored, since that whitespace is code content and some programming languages require it. When True, they are checked and fixed like any other line.

  • Default: false