Initial import

This commit is contained in:
Michael Wolf
2020-05-22 10:44:52 -05:00
commit cf3493c9c5
4 changed files with 183 additions and 0 deletions

54
would-reformat.sh Executable file
View File

@@ -0,0 +1,54 @@
#!/bin/bash
set -uo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
file="$1"
source "$DIR/_reformat-common.sh"
file_type=$(sniff_file_type $file)
retval=0
success_retval=0
if [[ $file_type == "javascript" || \
$file_type == "vue" || \
$file_type == "typescript" || \
$file_type == "css" || \
$file_type == "php" ]] ; then
out=$(npx prettier --check $file 2>&1 > /dev/null)
retval="$?"
success_retval=0
would_reformat_retval=1
syntax_error_retval=2
elif [[ $file_type == "python" ]] ; then
out=$(pipx run black --check $file 2>/dev/null)
retval="$?"
success_retval=0
would_reformat_retval=1
syntax_error_retval=123
else
echo -n "ignoring"
exit 0
fi
if [[ x"$retval" == x"$success_retval" ]] ; then
echo -n "would not change"
exit 0
elif [[ x"$retval" == x"$would_reformat_retval" ]] ; then
echo -n "would change"
exit 1
elif [[ x"$retval" == x"$syntax_error_retval" ]] ; then
echo -n "syntax error"
exit 2
else
echo -n "problem running reformatter"
exit 3
fi
echo -n "ok"
exit 0