Add shfmt.sh

This commit is contained in:
Michael Wolf
2024-04-03 11:29:32 -06:00
parent 7c503cecf7
commit e8771f1156

39
shfmt.sh Normal file
View File

@@ -0,0 +1,39 @@
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
# probably others too :(
syntax_error_retval=1
set +e
out=$(dart format -o none --set-exit-if-changed "$file"
retval="$?"
set -e
if [[ "$retval" = "$syntax_error_retval" ]]; then
retval=2
fi
exit "$retval"
fi
if [[ "$WOULD_REFORMAT" = "do_reformat" ]]; then
out=$(shfmt -w "$file" 2>&1 > /dev/null)
retval="$?"
echo "$out"
exit "$retval"
fi
exit 255