#!/bin/bash set -euo pipefail IFS=$'\n\t' DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ## This should be rarely if ever necessary, but here it is: # source "$DIR/_wrflog.sh" # wrflog before sourcing common funcs, I think i am in dir: $(pwd) source "$DIR/_reformat-common.bash" file="$1" export PROJECT_ROOT=$(project_root "$file") export WF_ROOT=$(wf_root) ## fixme use realpath or something on "$file" file_type=$(sniff_file_type "$file") export WOULD_REFORMAT=would_reformat if [[ $file_type = "javascript" || $file_type = "vue" || $file_type = "typescript" || $file_type = "css" || $file_type = "php" || $file_type = "html" || $file_type = "js" || $file_type = "ts" || $file_type == "css" || $file_type == "scss" || $file_type = "sh" ]]; then set +e out=$("$WF_ROOT"/./prettier.sh "$file" 2>&1 >/dev/null) retval="$?" set -e elif [[ $file_type == "python" ]]; then set +e out=$("$WF_ROOT"/./isort-and-black.sh "$file" 2>&1 >/dev/null) retval="$?" set -e elif [[ $file_type == "golang" ]]; then set +e out=$("$WF_ROOT"/./gofmt.sh "$file") retval="$?" set -e elif [[ $file_type == "dart" ]]; then set +e out=$("$WF_ROOT"/./dart_format.sh "$file") retval="$?" set -e else echo -n "ignoring" exit 0 fi success_retval=0 would_reformat_retval=1 syntax_error_retval=2 if [[ "$retval" == "$success_retval" ]]; then echo -n "would not change" exit 0 elif [[ "$retval" == "$would_reformat_retval" ]]; then echo -n "would change" exit 1 elif [[ "$retval" == "$syntax_error_retval" ]]; then echo -n "syntax error" echo echo "$out" exit 2 else echo -n "problem running reformatter" exit 3 fi echo -n "ok" exit 0