yaml: wrong new line character: expected \n
β’ 161 words β’ 1 min β’ updated
β οΈ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.
Example upstream issue: https://github.com/sbaudoin/sonar-yaml/issues/24
How to reproduce:
- start with a helm chart in a git repository:
helm create foo - delete
values.yaml - commit it, create a github PR
- realize that later on you need to create an empty
values.yamlfile:touch values.yaml - commit it, push it
- realize that you need to add a comment to the YAML file
- use the github web UI to add a comment. Click edit, and add this comment:
yaml
# Purposely empty for `ct lint`.- commit it
- wait for CI checks to run
yamllintwill fail:
yaml: wrong new line character: expected \nThis error can also be observed in vim (with certain plug-ins).
What’s the issue? It’s a line ending problem: CR LF et al being different in Windows vs Linux / macOS.
How to fix it? Run dos2unix values.yaml, commit, profit.
You can get dos2unix e.g. via homebrew.
What’s the lesson? Avoid the github web UI to edit files, even when in a rush. β