Skip to content

trailing-spaces

What this rule does

Reports whitespace at the end of any line.

Why this matters

  • Invisible drift. Trailing whitespace is invisible in most editors but shows up as a change in every diff, polluting code review.
  • Editor normalisation. Many editors strip trailing whitespace on save; without this rule, contributors with different editor settings produce conflicting commits.

Configuration

[lint.rules.trailing-spaces]
level = "error"

This rule has no options beyond level.

Examples

✅ Allowed

---
key: value

(No spaces between value and the newline.)

❌ Reported

---
key: value···

(Where ··· represents trailing whitespace characters.)

🔧 After ryl check --fix

---
key: value

Automatic fixing

ryl check --fix strips trailing spaces and tabs from each line. The fix is partial by design: space-only lines inside literal/folded block scalars (|/>) are stripped only when their spaces are not part of the reference parser's value. Value-bearing spaces, including trailing spaces on nonblank block scalar content lines, stay and are not reported. Whitespace inside multi-line double-quoted scalars stays because removing it can change the value; its diagnostic remains. Multi-line single-quoted and plain scalars fold trailing whitespace away at parse time, so the fix can safely strip those.

An indentation-only final line is stripped without adding a scalar line break. For example, a: |+\r\n becomes a: |+\r\n; both load as an empty string.

The fix bails (leaves the file untouched) when the input cannot be parsed as YAML, so a broken document is never made worse.

Disable with:

[lint]
fixable = ["ALL"]
unfixable = ["trailing-spaces"]

ryl format applies the same fix, and no option of this rule conflicts with it. Trailing spaces inside a block scalar can remain findings after either fixer because removing them would change the scalar value. Later keys, sequence items and comments outside a block scalar have their trailing whitespace stripped, including within the same indented collection.

  • new-line-at-end-of-file — controls the trailing newline character.
  • empty-lines — controls fully blank lines (a separate concern from trailing whitespace on content lines).