lint.sh 987 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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/travis/clang-format-whitelist.txt"
  9. files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
  10. local errorcount=0
  11. local fail=0
  12. for f in ${files_to_lint}; do
  13. d=$(diff -u "$f" <(${CLANG_FORMAT} "$f") || true)
  14. if ! [ -z "$d" ]; then
  15. whitelisted=$(awk '$1 == "'$f'" { print 1 }' "$CLANG_FORMAT_WHITELIST")
  16. # If file is not whitelisted, mark a failure
  17. if [ -z "${whitelisted}" ]; then
  18. errorcount=$((errorcount+1))
  19. printf "The file %s is not compliant with the coding style" "$f"
  20. if [ ${errorcount} -gt 50 ]; then
  21. printf "\nToo many errors encountered previously, this diff is hidden.\n"
  22. else
  23. printf ":\n%s\n" "$d"
  24. fi
  25. fail=1
  26. fi
  27. fi
  28. done
  29. if [ "$fail" = 1 ]; then
  30. echo "LINT reports failure."
  31. exit 1
  32. fi
  33. echo "LINT OK"
  34. }