check_trailing_spaces.sh 538 B

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