lint.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #! /bin/bash
  2. function perform_lint() {
  3. echo "Performing LINT..."
  4. if hash clang-format-5.0 2>/dev/null; then
  5. CLANG_FORMAT=clang-format-5.0
  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. files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
  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. if ! [ -z "$d" ]; then
  17. whitelisted=$(awk '$1 == "'$f'" { print 1 }' "$CLANG_FORMAT_WHITELIST")
  18. # If file is not whitelisted, mark a failure
  19. if [ -z ${whitelisted} ]; then
  20. errorcount=$((errorcount+1))
  21. printf "The file %s is not compliant with the coding style" "$f"
  22. if [ ${errorcount} -gt 50 ]; then
  23. printf "\nToo many errors encountered previously, this diff is hidden.\n"
  24. else
  25. printf ":\n%s\n" "$d"
  26. fi
  27. fail=1
  28. fi
  29. fi
  30. done
  31. if [ "$fail" = 1 ]; then
  32. echo "LINT reports failure."
  33. exit 1
  34. fi
  35. echo "LINT OK"
  36. }