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).

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 for trailing spaces. When True (default), code blocks are checked. When False, fenced and indented code blocks are ignored, since some programming languages require trailing whitespace.

  • Default: true