github.com/shiroyuki/docker@v1.9.0/hack/make/validate-gofmt (about) 1 #!/bin/bash 2 3 source "${MAKEDIR}/.validate" 4 5 IFS=$'\n' 6 files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' || true) ) 7 unset IFS 8 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 17 if [ ${#badFiles[@]} -eq 0 ]; then 18 echo 'Congratulations! All Go source files are properly formatted.' 19 else 20 { 21 echo "These files are not properly gofmt'd:" 22 for f in "${badFiles[@]}"; do 23 echo " - $f" 24 done 25 echo 26 echo 'Please reformat the above files using "gofmt -s -w" and commit the result.' 27 echo 28 } >&2 29 false 30 fi