From 57a1e89303e931006a8ff101959b77bb2975bd75 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Wed, 16 Mar 2016 15:00:28 -0700 Subject: [PATCH] check_format.sh: enforce newline at end of file Change-Id: I4fd1338ec3d95ffcd8a0727e87b845399676ccfa Signed-off-by: Daniel Verkamp --- scripts/check_format.sh | 3 +++ scripts/eofnl | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100755 scripts/eofnl diff --git a/scripts/check_format.sh b/scripts/check_format.sh index 8cd3c6009..44d43e8e3 100755 --- a/scripts/check_format.sh +++ b/scripts/check_format.sh @@ -30,4 +30,7 @@ else exit 0 fi +git ls-files -z '*.c' '*.cpp' '*.h' '*.txt' '*.md' '*.mk' '*.txt' '*.sh' '*.py' | \ + xargs -0 -P8 -n1 scripts/eofnl + exit 0 diff --git a/scripts/eofnl b/scripts/eofnl new file mode 100755 index 000000000..a193b5da4 --- /dev/null +++ b/scripts/eofnl @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Make sure file has a trailing newline + +f="$1" + +if [ -z "$f" ]; then + echo "usage: $0 " + exit 1 +fi + +if [[ -f "$f" && $(tail -c1 "$f") ]]; then + echo "$f: No newline at end of file" + echo '' >> "$f" + exit 1 +else + exit 0 +fi