markdownlint/doc/md009.md
David Anson a55d5499e2
Some checks are pending
Checkers / linkcheck (push) Waiting to run
Checkers / spellcheck (push) Waiting to run
CI / build (20, macos-latest) (push) Waiting to run
CI / build (20, ubuntu-latest) (push) Waiting to run
CI / build (20, windows-latest) (push) Waiting to run
CI / build (22, macos-latest) (push) Waiting to run
CI / build (22, ubuntu-latest) (push) Waiting to run
CI / build (22, windows-latest) (push) Waiting to run
CI / build (24, macos-latest) (push) Waiting to run
CI / build (24, ubuntu-latest) (push) Waiting to run
CI / build (24, windows-latest) (push) Waiting to run
CI / pnpm (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
TestRepos / build (latest, ubuntu-latest) (push) Waiting to run
UpdateTestRepos / update (push) Waiting to run
Update MD009/no-trailing-spaces with code_blocks parameter to allow reporting/fixing trailing spaces in indented/fenced code blocks (fixes #1181).
2025-10-11 17:28:04 -07:00

1.8 KiB

MD009 - Trailing spaces

Tags: whitespace

Aliases: no-trailing-spaces

Parameters:

  • br_spaces: Spaces for line break (integer, default 2)
  • code_blocks: Include code blocks (boolean, default false)
  • list_item_empty_lines: Allow spaces for empty lines in list items (boolean, default false)
  • strict: Include unnecessary breaks (boolean, default false)

Fixable: Some violations can be fixed by tooling

This rule is triggered on any lines that end with unexpected whitespace. To fix this, remove the trailing space from the end of the line.

The br_spaces parameter allows an exception to this rule for a specific number of trailing spaces, typically used to insert an explicit line break. The default value allows 2 spaces to indicate a hard break (<br> element). (You must set br_spaces to a value >= 2 for this parameter to take effect. Setting br_spaces to 1 behaves the same as 0, disallowing any trailing spaces.)

By default, trailing space is allowed in indented and fenced code blocks because some programming languages require that. To report such instances, set the code_blocks parameter to true.

By default, this rule will not trigger when the allowed number of spaces is used, even when it doesn't create a hard break (for example, at the end of a paragraph). To report such instances, set the strict parameter to true.

Text text text
text[2 spaces]

Using spaces to indent blank lines inside a list item is usually not necessary, but some parsers require it. Set the list_item_empty_lines parameter to true to allow this (even when strict is true):

- list item text
  [2 spaces]
  list item text

Rationale: Except when being used to create a line break, trailing whitespace has no purpose and does not affect the rendering of content.