02.3Trailing whitespace

Trailing whitespace remover

Strip the spaces and tabs nobody sees at the ends of lines, the blank lines piled up at the end of a file and runs of empty lines, while keeping the two-space line breaks Markdown needs.

or drop a file on this box

Remove

1#·Release·notes↵
2↵
3Version·2.4·ships·today.··↵
4Thanks·to·everyone·who·tested·it.↵
5↵
6##·Fixed↵
7-·Tabs·in·YAML·files↵
8-·Line·endings·on·Windows↵
9↵
10Signed,··↵
11The·maintainers↵

Done: Trimmed 5 lines (10 characters), removed 1 blank line at the end, collapsed 3 blank lines, kept 2 Markdown hard breaks.

Why trailing whitespace matters

Spaces at the end of a line do nothing, until they do: they turn up as noise in every diff, fail linters and pre-commit hooks, and break shell line continuations, where a space after the backslash ends the command. Most editors can trim them on save; this tool cleans a file you already have.

  • Spaces and tabs at the end of lines are removed, and lines with nothing but whitespace become empty.
  • Unicode spaces such as the no-break space are only removed when you tick that option, because some text uses them on purpose.
  • Blank lines at the end are dropped; the last line keeps its line break.
  • Runs of blank lines anywhere in the file can be collapsed to one or two.
  • Markdown hard breaks: two or more spaces at the end of a line make a line break inside a paragraph. With the option on, they are kept (as exactly two spaces) wherever another line of the same paragraph follows, and removed where they do nothing.

Opening a .md file turns the Markdown option on for you. Line endings and the file’s encoding stay as they were.

Questions

How do I stop trailing whitespace coming back?

Set trim_trailing_whitespace = true in an .editorconfig file, which most editors honour. Keep it false for Markdown if you use two-space line breaks.

Does it change line endings?

No. Each line keeps its own ending, CRLF or LF, and a file keeps its encoding.

Is my text uploaded?

No. Everything happens in your browser.