]> git.lizzy.rs Git - dragonfireclient.git/blob - util/ci/lint.sh
Merge branch 'master' into master
[dragonfireclient.git] / util / ci / lint.sh
1 #! /bin/bash
2 function perform_lint() {
3         echo "Performing LINT..."
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         local errorcount=0
13         local fail=0
14         for f in ${files_to_lint}; do
15                 d=$(diff -u "$f" <(${CLANG_FORMAT} "$f") || true)
16
17                 if ! [ -z "$d" ]; then
18                         whitelisted=$(awk '$1 == "'$f'" { print 1 }' "$CLANG_FORMAT_WHITELIST")
19
20                         # If file is not whitelisted, mark a failure
21                         if [ -z "${whitelisted}" ]; then
22                                 errorcount=$((errorcount+1))
23
24                                 printf "The file %s is not compliant with the coding style" "$f"
25                                 if [ ${errorcount} -gt 50 ]; then
26                                         printf "\nToo many errors encountered previously, this diff is hidden.\n"
27                                 else
28                                         printf ":\n%s\n" "$d"
29                                 fi
30
31                                 fail=1
32                         fi
33                 fi
34         done
35
36         if [ "$fail" = 1 ]; then
37                 echo "LINT reports failure."
38                 exit 1
39         fi
40
41         echo "LINT OK"
42 }
43