Skip to content

Commit

Permalink
CI: Improve message about ending with a newline
Browse files Browse the repository at this point in the history
A newline in a text file serves as a terminator, not a separator. This
means every line, including the last one, should end with a newline.

If a file is committed without a trailing newline, editors that do add
one will create an unnecessary diff when the file is later edited. These
spurious diffs can clutter reviews, making it harder to identify actual
changes, especially when many files are involved.

A newline at the end of the file also facilitates file concatenation.
Without it, the first line of the second file will merge with the last
line of the first file, creating a single line.

See https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline
  • Loading branch information
jserv committed Dec 2, 2024
1 parent 35ddf50 commit 1d990a9
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions .ci/check-newline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ while IFS= read -rd '' f; do
tail -c1 < "$f" | read -r _ || show=1
if [ $show -eq 1 ]; then
echo "Warning: No newline at end of file $f"
echo "See https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline"
ret=1
show=0
fi
Expand Down

0 comments on commit 1d990a9

Please sign in to comment.