blob: 19d4adbff265f3a83c18ba0e949d4862fed6ce2e [file] [log] [blame]
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
echo "==> Checking that code complies with gofmt requirements..."
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
if [[ -n "${gofmt_files}" ]]; then
echo 'gofumpt needs running on the following files:'
echo "${gofmt_files}"
echo "You can use the command: \`make fmt\` to reformat code."
exit 1
fi