Files
would-reformat/gofmt.sh
2023-09-30 17:49:00 -06:00

48 lines
790 B
Bash
Executable File

#!/bin/bash
set -uo pipefail
IFS=$'\n\t'
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$DIR/_reformat-common.bash"
set -e
file="$1"
pushd "$(dirname "$file")" 2>&1
if [[ "$WOULD_REFORMAT" = "would_reformat" ]]; then
would_reformat_retval=1
syntax_error_retval=2
set +e
out=$(gofmt -l "$file")
exitval="$?"
set -e
if [[ "$exitval" = "$syntax_error_retval" ]]; then
retval="$exitval"
elif [[ "$out" = "$file" ]]; then
retval="$would_reformat_retval"
else
# success
retval="$exitval"
fi
echo "$out"
exit "$retval"
fi
if [[ "$WOULD_REFORMAT" = "do_reformat" ]]; then
out=$(npx prettier --write "$file" 2>&1 >/dev/null)
retval="$?"
echo "$out"
exit "$retval"
fi
exit 255