deb.open-vault/scripts/gofmtcheck.sh

22 lines
689 B
Bash
Raw Normal View History

2024-04-20 12:23:50 +00:00
#!/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