github.com/bazelbuild/remote-apis-sdks@v0.0.0-20240425170053-8a36686a6350/check-gofmt.sh (about)

     1  #!/bin/bash
     2  
     3  # Source: https://github.com/golang/go/blob/88da9ccb98ffaf84bb06b98c9a24af5d0a7025d2/misc/git/pre-commit
     4  
     5  if [ "$#" -lt 1 ]; then
     6    exit 0
     7  fi
     8  
     9  unformatted=$(gofmt -l $@)
    10  [ -z "$unformatted" ] && exit 0
    11  
    12  # Some files are not gofmt'd. Print message and fail.
    13  
    14  echo >&2 "Go files must be formatted with gofmt. Please run:"
    15  for fn in $unformatted; do
    16  	echo >&2 "  gofmt -w $PWD/$fn"
    17  done
    18  
    19  exit 1