numam-spdk/scripts/eofnl
Daniel Verkamp e50cc5fd45 scripts/check_format: check trailing whitespace
Fix up the two existing instances of trailing whitespace in text files,
and add a check to enforce that no new trailing whitespace is added.

Change-Id: I2197bed69bb356142aa6d2e4e8261c7434dd358b
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/383291
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2017-10-24 17:35:23 -04:00

39 lines
552 B
Bash
Executable File

#!/usr/bin/env bash
# Make sure file has a trailing newline
f="$1"
if [ -z "$f" ]; then
echo "usage: $0 <file>"
exit 1
fi
if [ ! -f "$f" ]; then
exit 0
fi
if [[ $(tail -c1 "$f") ]]; then
echo "$f: No newline at end of file"
echo '' >> "$f"
exit 1
fi
if [[ ! $(tail -c2 "$f") ]]; then
echo "$f: Extra trailing newline"
exit 1
fi
if grep -q $'\r' "$f"; then
echo "$f: DOS-style newlines"
dos2unix "$f" &> /dev/null
exit 1
fi
if grep -q $'[\t ]$' "$f"; then
echo "$f: Trailing whitespace"
sed -i $'s/[ \t]*$//' "$f"
exit 1
fi
exit 0