-
Notifications
You must be signed in to change notification settings - Fork 16
/
check-style.sh
executable file
·66 lines (55 loc) · 1.47 KB
/
check-style.sh
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# config
COLS=100
FOLDER="."
FILES="*.rs"
# Exit script on the first error
set -o errexit -o nounset
ERROR=0
### Trailing Whitespaces ===========================
echo ""
echo "=== Searching for lines with trailing whitespace... ==================="
if egrep --include $FILES -rHn " +$" $FOLDER ; then
echo ""
echo "!!! Some lines were found. Please remove the trailing whitespace!"
ERROR=1
else
echo "=== None found! :-)"
fi
### Trailing newlines ===============================
echo ""
echo "=== Searching for files without trailing newline... ==================="
FOUND=0
for f in $(find $FOLDER -name $FILES); do
lastline=$(tail -n 1 $f; echo x)
lastline=${lastline%x}
if [ "${lastline: -1}" != $'\n' ] ; then
echo "! Has no single trailing newline: $f"
FOUND=1
fi
done
if [ $FOUND -eq 0 ] ; then
echo "=== None found! :-)"
else
echo ""
echo "!!! Some files were found. Please add a single trailing newline!"
ERROR=1
fi
### char limit ===================================
echo ""
echo "=== Searching for files with too long lines... ========================"
FOUND=0
for f in $(find $FOLDER -name $FILES); do
if [ $(wc -L $f | cut -d" " -f1) -gt $COLS ] ; then
echo "! Line with more than $COLS chars in $f"
FOUND=1
fi
done
if [ $FOUND -eq 0 ] ; then
echo "=== None found! :-)"
else
echo ""
echo "!!! Some files were found. Please shorten those lines!"
ERROR=1
fi
test $ERROR == 0