Add newline to end of file: Difference between revisions
From Freephile Wiki
Created page with "For yaml files, there should always be a newline character at the end of the file. It's easy to overlook, and some editors are misconfigured to '''remove''' trailing newlines, meaning it can be a battle to keep your yaml syntactically correct. When you can't use tools like yamllint to fix things, here's a one-liner that does the job. <syntaxhighlight lang="bash"> find . -name "*.yaml" -exec sh -c 'if [ -n "$(tail -c 1 "$1")" ]; then echo "" >> "$1"; fi' _ {} \;..." |
No edit summary |
||
| Line 1: | Line 1: | ||
For [[yaml]] files, there should always be a newline character at the end of the file. It's easy to overlook, and some editors are misconfigured to '''remove''' trailing newlines, meaning it can be a battle to keep your yaml syntactically correct. When you can't use tools like [[yamllint]] to fix things, here's a one-liner that does the job. | For [[yaml]] files, there should always be a newline character at the end of the file. It's easy to overlook, and some editors are misconfigured to '''remove''' trailing newlines, meaning it can be a battle to keep your yaml syntactically correct. When you can't use tools like [[yamllint]] to fix things, here's a one-liner that does the job. | ||
<syntaxhighlight lang= | <syntaxhighlight lang=bash> | ||
find . -name "*.yaml" -exec sh -c 'if [ -n "$(tail -c 1 "$1")" ]; then echo "" >> "$1"; fi' _ {} \; | find . -name "*.yaml" -exec sh -c 'if [ -n "$(tail -c 1 "$1")" ]; then echo "" >> "$1"; fi' _ {} \; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 08:22, 26 September 2025
For yaml files, there should always be a newline character at the end of the file. It's easy to overlook, and some editors are misconfigured to remove trailing newlines, meaning it can be a battle to keep your yaml syntactically correct. When you can't use tools like yamllint to fix things, here's a one-liner that does the job.
find . -name "*.yaml" -exec sh -c 'if [ -n "$(tail -c 1 "$1")" ]; then echo "" >> "$1"; fi' _ {} \;