Teach do-reformat.sh to use the more extensible stuff

This commit is contained in:
Michael Wolf
2023-09-30 19:05:52 -06:00
parent 67027cd612
commit 87e15f87f3

View File

@@ -9,40 +9,25 @@ source "$DIR/_reformat-common.bash"
file="$1" file="$1"
PROJECT_ROOT=$(project_root "$file")
export PROJECT_ROOT="$PROJECT_ROOT"
WF_ROOT=$(wf_root)
export WF_ROOT="$WF_ROOT"
file_type=$(sniff_file_type "$file") file_type=$(sniff_file_type "$file")
export WOULD_REFORMAT=do_reformat export WOULD_REFORMAT=do_reformat
if [[ $file_type == "javascript" || wrapper=$(choose_wrapper "$file_type")
$file_type == "vue" ||
$file_type == "css" || wrflog got wrapper: $wrapper
$file_type == "typescript" ||
$file_type == "php" || set +e
$file_type == "html" || out=$("$wrapper" "$file" 2>&1 >/dev/null)
$file_type == "jsx" || retval="$?"
$file_type == "tsx" || set -e
$file_type == "css" ||
$file_type == "scss" || success_retval=0
$file_type == "sh" ]]; then
out=$("$(wf_root)"/./prettier.sh "$file")
retval="$?"
success_retval=0
elif [[ $file_type == "python" ]]; then
out=$(pipx run black "$file" 2>/dev/null && pipx run isort "$file" 2>/dev/null)
retval="$?"
success_retval=0
elif [[ $file_type == "golang" ]]; then
out=$(gofmt -w "$file" 2>/dev/null)
retval="$?"
success_retval=0
elif [[ $file_type == "dart" ]]; then
out=$(dart format "$file")
retval="$?"
success_retval=0
else
echo -n "ignoring"
exit 0
fi
if [[ "$retval" == "$success_retval" ]]; then if [[ "$retval" == "$success_retval" ]]; then
echo "$out" echo "$out"