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 CLANG_FORMAT_WHITELIST="util/travis/clang-format-whitelist.txt"
11 if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
12 # Get list of every file modified in this pull request
13 files_to_lint="$(git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE | grep '^src/[^.]*[.]\(cpp\|h\)$' | true)"
15 # Check everything for branch pushes
16 files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
21 for f in ${files_to_lint}; do
22 d=$(diff -u "$f" <(${CLANG_FORMAT} "$f") || true)
24 if ! [ -z "$d" ]; then
25 whitelisted=$(egrep -c "^${f}" "${CLANG_FORMAT_WHITELIST}")
27 # If file is not whitelisted, mark a failure
28 if [ ${whitelisted} -eq 0 ]; then
29 errorcount=$((errorcount+1))
31 printf "The file %s is not compliant with the coding style" "$f"
32 if [ ${errorcount} -gt 50 ]; then
33 printf "\nToo many errors encountered previously, this diff is hidden.\n"
43 if [ "$fail" = 1 ]; then
44 echo "LINT reports failure."