forked from googlefonts/PFE-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-format.sh
executable file
·67 lines (61 loc) · 1.37 KB
/
check-format.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
67
#!/bin/bash
#
# Use this script to automatically format the c++ files in
# this repository.
FIX=0
while test $# -gt 0; do
case "$1" in
--fix)
shift
FIX=1
;;
esac
done
FAILED=0
FORMAT_MESSAGE="is formatted incorrectly. Use ./check-format.sh --fix to format all source files."
# C++ Formatting
for f in $(find ./ -name "*.cc") $(find ./ -name "*.h"); do
clang-format --style=Google --output-replacements-xml $f | grep -q "<replacement "
if [ $? -eq 0 ]; then
if [ $FIX -eq 1 ]; then
clang-format --style=Google -i $f
else
echo $f $FORMAT_MESSAGE
FAILED=1
fi
fi
done
# Python Formatting
for f in $(find ./ -name "*.py"); do
if [[ $f = */range_request_* ]]; then
continue
fi
if [[ $f = */emscripten_toolchain* ]]; then
continue
fi
yapf --style="{based_on_style: google, indent_width: 2}" -d $f \
if [ $? -ne 0 ]; then
if [ $FIX -eq 1 ]; then
yapf --style="{based_on_style: google, indent_width: 2}" -i $f
else
echo $f $FORMAT_MESSAGE
FAILED=1
fi
fi
python3 -m pylint -s no \
-d R0903,E0401,E0611,fixme \
--no-docstring-rgx=".+Test|test_" \
--docstring-min-length=5 \
--indent-string=" " \
$f
if [ $? -ne 0 ]; then
echo "pylint failed for $f"
echo ""
FAILED=1
fi
done
if [ $FAILED -eq 1 ]; then
exit -1
else
echo "Formatting is correct :)"
fi