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
7 CLANG_FORMAT=clang-format
9 echo "LINT: Using binary $CLANG_FORMAT"
10 CLANG_FORMAT_WHITELIST="util/travis/clang-format-whitelist.txt"
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)"
16 # Check everything for branch pushes
17 files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
22 for f in ${files_to_lint}; do
23 d=$(diff -u "$f" <(${CLANG_FORMAT} "$f") || true)
25 if ! [ -z "$d" ]; then
26 whitelisted=$(awk '$1 == "'$f'" { print 1 }' "$CLANG_FORMAT_WHITELIST")
28 # If file is not whitelisted, mark a failure
29 if [ -z ${whitelisted} ]; then
30 errorcount=$((errorcount+1))
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"
44 if [ "$fail" = 1 ]; then
45 echo "LINT reports failure."