Create and use dart_format.sh wrapper script

This commit is contained in:
Michael Wolf
2023-09-30 18:05:36 -06:00
parent 50cbaa0454
commit f31cc2d4a2
2 changed files with 42 additions and 9 deletions

40
dart_format.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/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
# probably others too :(
syntax_error_retval=65
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=$(npx prettier --write "$file" 2>&1 >/dev/null)
retval="$?"
echo "$out"
exit "$retval"
fi
exit 255

View File

@@ -46,17 +46,10 @@ elif [[ $file_type == "golang" ]]; then
retval="$?"
set -e
elif [[ $file_type == "dart" ]]; then
success_retval=0
would_reformat_retval=1
# probably others too :(
syntax_error_retval=65
set +e
out=$(dart format -o none --set-exit-if-changed "$file")
exitval="$?"
out=$("$WF_ROOT"/./dart_format.sh "$file")
retval="$?"
set -e
retval="$exitval"
else
echo -n "ignoring"
exit 0