Skip to content
Latchkey

yamllint "trailing spaces" error in CI

yamllint's trailing-spaces rule flags any line that ends in one or more spaces or tabs. It is a style error, not a parse error, but it fails the lint job.

What this error means

yamllint reports "trailing spaces (trailing-spaces)" at the column where the extra whitespace begins. The file looks fine but has invisible trailing characters.

yamllint
values.yaml
  3:18      error    trailing spaces (trailing-spaces)

Common causes

An editor left whitespace at the end of a line

Manual edits or a paste added spaces after the last visible character, which the rule detects.

No trailing-whitespace stripping in the toolchain

Without an editor setting or a pre-commit hook, trailing whitespace accumulates and only fails in CI.

How to fix it

Strip trailing whitespace

  1. Remove trailing spaces from the flagged lines.
  2. Enable "trim trailing whitespace on save" in your editor.
  3. Re-run yamllint to confirm the rule passes.
Terminal
sed -i 's/[ \t]*$//' values.yaml

Add the pre-commit trailing-whitespace hook

The pre-commit-hooks trailing-whitespace hook fixes this automatically before every commit.

.pre-commit-config.yaml
- repo: https://github.com/pre-commit/pre-commit-hooks
  rev: v4.6.0
  hooks:
    - id: trailing-whitespace

How to prevent it

  • Enable trim-on-save in your editor for all files.
  • Add the trailing-whitespace pre-commit hook.
  • Include an .editorconfig with trim_trailing_whitespace = true.

Frequently asked questions

What causes ""trailing spaces (trailing-spaces)""?
Manual edits or a paste added spaces after the last visible character, which the rule detects.
How do I fix "trailing spaces (trailing-spaces)"?
Strip trailing whitespace

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card