script.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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
  9. ls /usr/bin
  10. $CLANG_FORMAT --version
  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)"
  14. else
  15. # Check everything for branch pushes
  16. files_to_lint="$(find src/ -name '*.cpp' -or -name '*.h')"
  17. fi
  18. # Turn off tracing for this because it's too verbose
  19. set +x
  20. for f in $files_to_lint; do
  21. d=$(diff -u "$f" <($CLANG_FORMAT "$f") || true)
  22. if ! [ -z "$d" ]; then
  23. echo "!!! $f not compliant to coding style, here is the fix:"
  24. echo "$d"
  25. fail=1
  26. fi
  27. done
  28. set -x
  29. if [ "$fail" = 1 ]; then
  30. exit 1
  31. fi