aboutsummaryrefslogtreecommitdiffstats
path: root/tools/check-whitespace.sh
blob: 63031bee86c8048fe2a7bbff1e0c964998f2c7f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/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" | \
		grep -E -v "/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"