Skip to content

Commit

Permalink
backport of commit 2ed4c7d (#24797)
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Cragun <[email protected]>
  • Loading branch information
1 parent 139e8e6 commit 470431a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions scripts/go-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ check_fmt() {
echo "==> Checking code formatting..."

declare -a malformed=()
readarray -t files <<< "$1"
if [ -n "$1" ] && [ "${#files[@]}" -ne 0 ]; then
IFS=" " read -r -a files <<< "$(tr '\n' ' ' <<< "$@")"
if [ -n "${files+set}" ] && [[ "${files[0]}" != "" ]]; then
echo "--> Checking changed files..."
for file in "${files[@]}"; do
if [ ! -f "$file" ]; then
Expand All @@ -19,7 +19,9 @@ check_fmt() {
fi

if echo "$file" | grep -v pb.go | grep -v vendor > /dev/null; then
if ! gofumpt -l "$file" > /dev/null; then
local output
if ! output=$(gofumpt -l "$file") || [ "$output" != "" ]; then
echo "--> ${file}"
malformed+=("$file")
continue
fi
Expand All @@ -29,7 +31,7 @@ check_fmt() {
done
else
echo "--> Checking all files..."
readarray -t malformed <<< "$(find . -name '*.go' | grep -v pb.go | grep -v vendor | xargs gofumpt -l)"
IFS=" " read -r -a malformed <<< "$(find . -name '*.go' | grep -v pb.go | grep -v vendor | xargs gofumpt -l)"
fi

if [ "${#malformed[@]}" -ne 0 ] && [ -n "${malformed[0]}" ] ; then
Expand Down Expand Up @@ -97,7 +99,7 @@ main() {
mod_tidy
;;
check-fmt)
check_fmt "${2-}"
check_fmt "${@:2}"
;;
check-version)
check_version "$2"
Expand Down

0 comments on commit 470431a

Please sign in to comment.