]> git.lizzy.rs Git - dragonfireclient.git/blob - util/ci/clang-format.sh
Disable clang-format, clean up scripts
[dragonfireclient.git] / util / ci / clang-format.sh
1 #! /bin/bash
2
3 function setup_for_format() {
4         if [ -z "${CLANG_FORMAT}" ]; then
5                 CLANG_FORMAT=clang-format
6         fi
7         echo "LINT: Using binary $CLANG_FORMAT"
8         CLANG_FORMAT_WHITELIST="util/ci/clang-format-whitelist.txt"
9
10         files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
11 }
12
13 function check_format() {
14         echo "Checking format..."
15
16         setup_for_format
17
18         local errorcount=0
19         local fail=0
20         for f in ${files_to_lint}; do
21                 d=$(diff -u "$f" <(${CLANG_FORMAT} "$f") || true)
22
23                 if ! [ -z "$d" ]; then
24                         whitelisted=$(awk '$1 == "'$f'" { print 1 }' "$CLANG_FORMAT_WHITELIST")
25
26                         # If file is not whitelisted, mark a failure
27                         if [ -z "${whitelisted}" ]; then
28                                 errorcount=$((errorcount+1))
29
30                                 printf "The file %s is not compliant with the coding style" "$f"
31                                 if [ ${errorcount} -gt 50 ]; then
32                                         printf "\nToo many errors encountered previously, this diff is hidden.\n"
33                                 else
34                                         printf ":\n%s\n" "$d"
35                                 fi
36
37                                 fail=1
38                         fi
39                 fi
40         done
41
42         if [ "$fail" = 1 ]; then
43                 echo "LINT reports failure."
44                 exit 1
45         fi
46
47         echo "LINT OK"
48 }
49
50
51
52 function fix_format() {
53         echo "Fixing format..."
54
55         setup_for_format
56
57         for f in ${files_to_lint}; do
58                 whitelisted=$(awk '$1 == "'$f'" { print 1 }' "$CLANG_FORMAT_WHITELIST")
59                 if [ -z "${whitelisted}" ]; then
60                         echo "$f"
61                         $CLANG_FORMAT -i "$f"
62                 fi
63         done
64 }