2017-05-19 12:34:17 +00:00
|
|
|
#!/usr/bin/env bash
|
2023-03-15 16:00:52 +00:00
|
|
|
# Copyright (c) HashiCorp, Inc.
|
|
|
|
# SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-05-19 12:34:17 +00:00
|
|
|
echo "==> Checking that code complies with gofmt requirements..."
|
|
|
|
|
2023-07-11 14:44:40 +00:00
|
|
|
files=$(echo $1 | xargs)
|
|
|
|
if [ -n "$files" ]; then
|
|
|
|
echo "Checking changed files..."
|
|
|
|
gofmt_files="$(echo $1 | grep -v pb.go | grep -v vendor | xargs go run mvdan.cc/gofumpt -l)"
|
|
|
|
else
|
|
|
|
echo "Checking all files..."
|
|
|
|
gofmt_files="$(find . -name '*.go' | grep -v pb.go | grep -v vendor | xargs go run mvdan.cc/gofumpt -l)"
|
|
|
|
fi
|
|
|
|
|
2023-07-10 17:07:30 +00:00
|
|
|
if [[ -n "${gofmt_files}" ]]; then
|
|
|
|
echo 'gofumpt needs running on the following files:'
|
2017-05-19 12:34:17 +00:00
|
|
|
echo "${gofmt_files}"
|
|
|
|
echo "You can use the command: \`make fmt\` to reformat code."
|
|
|
|
exit 1
|
|
|
|
fi
|