Detect Missing EOF

While editing files on GitHub/Gitlab, missing an empty line at the bottom of a file in the buffer will result in no newline at the end of file. In the case of regular text files, this isn’t consistent with the POSIX standards.

for file in `git ls-files`; do
  grep -Iq . $file && if ! newline_at_eof $file; then; else echo $file; fi

Fred has provided a shell script for detecting EOF on Stack Overflow. I’ve replaced bash with sh because I’m using Zsh.

if [ -z "$(tail -c 1 "$1")" ]
    echo "Newline at end of file!"
    exit 1
    echo "No newline at end of file!"
    exit 0

No comment

Your email address will not be published. Required fields are marked *.