-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclang-format.sh
executable file
·53 lines (43 loc) · 1.18 KB
/
clang-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
#!/bin/sh
PROJECT_PATH="$(pwd)"
CLANG_FORMAT_BIN_PATH="clang-format"
AUTOCORRECT="YES"
cd "${PROJECT_PATH}"
if [ "$1" == "lint" ]; then
AUTOCORRECT="NO"
fi
CONTAINS_BAD_FILE='NO'
BAD_FILES=''
for folder in Source
do
OLDIFS=$IFS
IFS=$'\n'
files=$(find "${PROJECT_PATH}/${folder}" -type f \( -name "*.m" -or -name "*.h" -or -name "*.mm" \))
for file in $files
do
if [ $AUTOCORRECT == "YES" ]; then
"${CLANG_FORMAT_BIN_PATH}" -i -style=file "$file"
else
isvalid=$("${CLANG_FORMAT_BIN_PATH}" -style=file -output-replacements-xml "$file" | grep "<replacement " || true)
if [ "$isvalid" != "" ]; then
CONTAINS_BAD_FILE='YES'
if [ "${BAD_FILES}" == "" ]; then
BAD_FILES="${file}"
else
BAD_FILES="${BAD_FILES}\n${file}"
fi
fi
fi
done
IFS=$OLDIFS
done
if [ $CONTAINS_BAD_FILE == 'YES' ]; then
OLDIFS=$IFS
IFS=$'\n'
for file in $BAD_FILES
do
echo "Fix code style of $file, by executing 'sh ./clang-format.sh'"
done
IFS=$OLDIFS
exit 1
fi