From 6f3cfbc10208407c3927a5e3b691e68b168dd604 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Thu, 4 Nov 2021 14:39:27 +0100 Subject: [PATCH] chore: add a script to find files without new line at EOF --- scripts/check-nl-at-eof.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 scripts/check-nl-at-eof.sh diff --git a/scripts/check-nl-at-eof.sh b/scripts/check-nl-at-eof.sh new file mode 100755 index 000000000..5d93d04ac --- /dev/null +++ b/scripts/check-nl-at-eof.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -euo pipefail + +cd -P -- "$(dirname -- "$0")/.." + +nl_at_eof() { + local file="$1" + if ! [ -f $file ]; then + return + fi + case "$file" in + *.png|*rebar3) + return + ;; + esac + local lastbyte + lastbyte="$(tail -c 1 "$file" 2>&1)" + if [ "$lastbyte" != '' ]; then + echo $file + fi +} + +while read -r file; do + nl_at_eof "$file" +done < <(git ls-files)