open-vault/scripts/gofmtcheck.sh
hc-github-team-secure-vault-core f87b781ebc
backport of commit a9778be3f2735ea242c5ea05a2a805fa18e7df4f (#21756)
Co-authored-by: Mike Palmiotto <mike.palmiotto@hashicorp.com>
2023-07-11 14:44:40 +00:00

22 lines
689 B
Bash
Executable file

#!/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