check_trailing_spaces.sh 579 B

1234567891011121314
  1. #!/bin/bash
  2. files_with_trailing_spaces=$(find . -type f -not -path "./.git/*" -not -path "./dev-tools/vendor/*" -not -path "./vendor/*" -not -path "./tests/Fixtures/*" -exec egrep -nH " $" {} \;)
  3. if [[ $files_with_trailing_spaces ]]
  4. then
  5. echo -e "\e[97;41mTrailing spaces detected:\e[0m"
  6. e=$(printf '\033')
  7. echo "${files_with_trailing_spaces}" | sed -E "s/^\.\/([^:]+):([0-9]+):(.*[^ ])( +)$/${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}[41m\4${e}[0m/"
  8. exit 1
  9. fi
  10. echo -e "\e[0;32mNo trailing spaces detected.\e[0m"