-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint.sh
executable file
·48 lines (40 loc) · 929 Bytes
/
lint.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
#!/bin/bash
sourceFiles="libCombinatorEvolve/*pp"
red="\\\033[0;31m"
green="\\\033[0;32m"
endColor="\\\033[0m"
formatInPlace=0
for arg in "$@"
do
case $arg in
-i)
formatInPlace=1
shift
;;
*)
echo "Argument $arg is not recognized."
echo
echo "Usage: ./lint.sh [-i]"
echo "Analyze the C++ code with clang-format and cpplint."
echo
echo "Options:"
echo " -i Inplace edit files with clang-format."
exit 1
;;
esac
done
exitStatus=0
for file in $sourceFiles; do
diff=$(diff -U0 --label $file $file --label formatted <(clang-format $file))
if [ $formatInPlace -eq 1 ]; then
clang-format -i $file
fi
if [[ ! -z "$diff" ]]; then
printf -- "$(echo "$diff\n\n" | sed "s|^-|$red-|g" | sed "s|^+|$green+|g" | sed "s|$|$endColor|g")"
exitStatus=1
fi
done
if ! cpplint --quiet --extensions=hpp,cpp $sourceFiles; then
exitStatus=1
fi
exit $exitStatus