]> git.lizzy.rs Git - dragonfireclient.git/blob - util/travis/lint.sh
Clang-format styles fixes since previous commit
[dragonfireclient.git] / util / travis / lint.sh
1 #! /bin/bash
2 function perform_lint() {
3         echo "Performing LINT..."
4         if hash clang-format-3.9 2>/dev/null; then
5                 CLANG_FORMAT=clang-format-3.9
6         else
7                 CLANG_FORMAT=clang-format
8         fi
9         echo "LINT: Using binary $CLANG_FORMAT"
10         CLANG_FORMAT_WHITELIST="util/travis/clang-format-whitelist.txt"
11
12         if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
13                 # Get list of every file modified in this pull request
14                 files_to_lint="$(git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE | grep '^src/[^.]*[.]\(cpp\|h\)$' | true)"
15         else
16                 # Check everything for branch pushes
17                 files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
18         fi
19
20         local errorcount=0
21         local fail=0
22         for f in ${files_to_lint}; do
23                 d=$(diff -u "$f" <(${CLANG_FORMAT} "$f") || true)
24
25                 if ! [ -z "$d" ]; then
26                         whitelisted=$(awk '$1 == "'$f'" { print 1 }' "$CLANG_FORMAT_WHITELIST")
27
28                         # If file is not whitelisted, mark a failure
29                         if [ -z ${whitelisted} ]; then
30                                 errorcount=$((errorcount+1))
31
32                                 printf "The file %s is not compliant with the coding style" "$f"
33                                 if [ ${errorcount} -gt 50 ]; then
34                                         printf "\nToo many errors encountered previously, this diff is hidden.\n"
35                                 else
36                                         printf ":\n%s\n" "$d"
37                                 fi
38
39                                 fail=1
40                         fi
41                 fi
42         done
43
44         if [ "$fail" = 1 ]; then
45                 echo "LINT reports failure."
46                 exit 1
47         fi
48
49         echo "LINT OK"
50 }
51