check_trailing_spaces.sh 709 B

123456789101112131415161718192021222324
  1. #!/bin/sh
  2. set -eu
  3. files_with_trailing_spaces=$(
  4. find . \
  5. -type f \
  6. -not -path "./.git/*" \
  7. -not -path "./dev-tools/vendor/*" \
  8. -not -path "./vendor/*" \
  9. -not -path "./tests/Fixtures/*" \
  10. -exec grep -EIHn "\\s$" {} \; \
  11. | sort -fh
  12. )
  13. if [ "$files_with_trailing_spaces" ]
  14. then
  15. printf '\033[97;41mTrailing whitespaces detected:\033[0m\n'
  16. e=$(printf '\033')
  17. echo "${files_with_trailing_spaces}" | sed -E "s/^\\.\\/([^:]+):([0-9]+):(.*[^\\t ])?([\\t ]+)$/${e}[0;31m - in ${e}[0;33m\\1${e}[0;31m at line ${e}[0;33m\\2\\n ${e}[0;31m>${e}[0m \\3${e}[41;1m\\4${e}[0m/"
  18. exit 3
  19. fi
  20. printf '\033[0;32mNo trailing whitespaces detected.\033[0m\n'