check_trailing_spaces.sh 563 B

1234567891011121314151617181920
  1. #!/bin/sh
  2. set -eu
  3. files_with_trailing_spaces=$(
  4. git grep -In "\\s$" \
  5. ':!doc/rules/*' \
  6. ':!tests/Fixtures/*' \
  7. | sort -fh
  8. )
  9. if [ "$files_with_trailing_spaces" ]
  10. then
  11. printf '\033[97;41mTrailing whitespaces detected:\033[0m\n'
  12. e=$(printf '\033')
  13. 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/"
  14. exit 3
  15. fi
  16. printf '\033[0;32mNo trailing whitespaces detected.\033[0m\n'