script.sh 1013 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/bash -ex
  2. if grep -nrI '\s$' src *.yml *.txt *.md Doxyfile .gitignore .gitmodules .ci* dist/*.desktop \
  3. dist/*.svg dist/*.xml; then
  4. echo Trailing whitespace found, aborting
  5. exit 1
  6. fi
  7. # Default clang-format points to default 3.5 version one
  8. CLANG_FORMAT=clang-format-10.0
  9. $CLANG_FORMAT --version
  10. if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then
  11. # Get list of every file modified in this pull request
  12. files_to_lint="$(git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE | grep '^src/[^.]*[.]\(cpp\|h\)$' || true)"
  13. else
  14. # Check everything for branch pushes
  15. files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
  16. fi
  17. # Turn off tracing for this because it's too verbose
  18. set +x
  19. for f in $files_to_lint; do
  20. d=$(diff -u "$f" <($CLANG_FORMAT "$f") || true)
  21. if ! [ -z "$d" ]; then
  22. echo "!!! $f not compliant to coding style, here is the fix:"
  23. echo "$d"
  24. fail=1
  25. fi
  26. done
  27. set -x
  28. if [ "$fail" = 1 ]; then
  29. exit 1
  30. fi