check_trailing_spaces.sh 701 B

1234567891011121314151617181920212223
  1. #!/bin/sh
  2. files_with_trailing_spaces=$(
  3. find . \
  4. -type f \
  5. -not -path "./.git/*" \
  6. -not -path "./dev-tools/vendor/*" \
  7. -not -path "./vendor/*" \
  8. -not -path "./tests/Fixtures/*" \
  9. -exec grep -EIHn "\\s$" {} \; \
  10. | sort -fh
  11. )
  12. if [ "$files_with_trailing_spaces" ]
  13. then
  14. printf '\033[97;41mTrailing whitespaces detected:\033[0m\n'
  15. e=$(printf '\033')
  16. 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/"
  17. exit 3
  18. fi
  19. printf '\033[0;32mNo trailing whitespaces detected.\033[0m\n'