Skip to content

Commit b370961

Browse files
committed
chore: add clang format helper tool
1 parent 8904652 commit b370961

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

script/clang-format.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env bash
2+
3+
# clang format options
4+
method="-i"
5+
6+
while getopts "in" option; do
7+
case "${option}" in
8+
i) # format code
9+
method="-i"
10+
;;
11+
n) # dry run and changes formatting warnings to errors
12+
method="--dry-run --Werror"
13+
;;
14+
\?) # invalid option
15+
echo "invalid option, please use -i or -n."
16+
exit 1
17+
;;
18+
esac
19+
done
20+
21+
# array of folders to format
22+
native_path=(
23+
"app/src/main/jni/librime_jni/*.h"
24+
"app/src/main/jni/librime_jni/*.cc"
25+
)
26+
27+
# iterate over all files in current entry
28+
for entry in "${native_path[@]}"; do
29+
clang-format --verbose ${method} -style='file' ${entry}
30+
if [ "$?" -ne 0 ]; then
31+
echo "please format the code: make style-apply"
32+
exit 1
33+
fi
34+
done

0 commit comments

Comments
 (0)