validate-gofmt 697 B

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