gofmt 819 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  3. source "${SCRIPTDIR}/.validate"
  4. IFS=$'\n'
  5. files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' |
  6. grep -v '^vendor/' |
  7. grep -v '^cli/compose/schema/bindata.go' || true) )
  8. unset IFS
  9. badFiles=()
  10. for f in "${files[@]}"; do
  11. # we use "git show" here to validate that what's committed is formatted
  12. if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then
  13. badFiles+=( "$f" )
  14. fi
  15. done
  16. if [ ${#badFiles[@]} -eq 0 ]; then
  17. echo 'Congratulations! All Go source files are properly formatted.'
  18. else
  19. {
  20. echo "These files are not properly gofmt'd:"
  21. for f in "${badFiles[@]}"; do
  22. echo " - $f"
  23. done
  24. echo
  25. echo 'Please reformat the above files using "gofmt -s -w" and commit the result.'
  26. echo
  27. } >&2
  28. false
  29. fi