Skip to content

no-trailing-whitespace

Reports spaces or tabs at the end of a line, from the first one to the line break. Tokens of the kinds the option ignore_kinds names (Markdown’s fenced code) are not looked at, and hard_break_spaces allows Markdown’s two-space line break.

Trailing white space cannot be seen, adds nothing, and many editors strip it, so a later edit shows a change on a line the author did not touch and makes diffs and blame noisy.

To fix, delete it.

Reported
<!DOCTYPE html>
<title>x</title>
<p>text
</p>
<p>fine</p>
lint:
rules:
no-trailing-whitespace:
level: warn # off (default), warn, error
options:
ignore_kinds: []
hard_break_spaces: 0
Option Type Default Description
ignore_kinds list [] Kinds of tokens whose trailing white space is not reported (the code of a fence).
hard_break_spaces int 0 With a value above 0, that many spaces or more at the end of a line that the next non-blank line follows are a hard line break and not reported (Markdown: 2).

Enabled by the presets: html/html-validate-recommended, cmake/cmake-lint, yaml/yamllint.

Suppress one line with sudsy-disable-next-line no-trailing-whitespace in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
cmake-lint C0303 full
html-eslint no-trailing-spaces full
html-validate no-trailing-whitespace partial also reported inside pre and raw text
yamllint trailing-spaces partial Also reports inside block scalars, where the content is data and the formatter keeps it.