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.
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
- Remove trailing spaces from the flagged lines.
- Enable "trim trailing whitespace on save" in your editor.
- Re-run
yamllintto confirm the rule passes.
sed -i 's/[ \t]*$//' values.yamlAdd the pre-commit trailing-whitespace hook
The pre-commit-hooks trailing-whitespace hook fixes this automatically before every commit.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespaceHow to prevent it
- Enable trim-on-save in your editor for all files.
- Add the
trailing-whitespacepre-commit hook. - Include an
.editorconfigwithtrim_trailing_whitespace = true.