syzkaller/tools/check-whitespace.sh
Dmitry Vyukov fab7609913 tools/check-whitespace.sh: check for trailing whitespaces
File types that we don't format automatically can end up
with such basic untidiness as trailing whitespaces.
Check for these. Remove all existing precedents.
2020-09-14 09:55:45 +02:00

32 lines
883 B
Bash
Executable File

#!/usr/bin/env bash
# Copyright 2020 syzkaller project authors. All rights reserved.
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
FILES=0
FAILED=""
RE="[[:space:]]$"
LAST_EMPTY=""
for F in $(find . -name "*.sh" -o -name "*.S" -o -name "*.py" -o -name "*.yml" -o -name "*.yaml" -o -name "*.md" | \
egrep -v "/vendor/|/gen/"); do
((FILES+=1))
L=0
while IFS= read -r LINE; do
((L+=1))
if [[ $LINE =~ $RE ]]; then
echo "$F:$L:1: Trailing whitespace at the end of the line. Please remove."
echo "$LINE"
FAILED="1"
fi
LAST_EMPTY=""
if [ "$LINE" == "" ]; then
LAST_EMPTY="1"
fi
done < "$F"
if [ "$LAST_EMPTY" != "" ]; then
echo "$F:$L:1: Trailing empty line at the end of the file. Please remove."
FAILED="1"
fi
done
if [ "$FAILED" != "" ]; then exit 1; fi
echo "$FILES files checked for whitespaces"