Run files through prettier; add rudimentary .sh support
This commit is contained in:
@@ -21,6 +21,8 @@ function sniff_file_type() {
|
|||||||
file_type="jsx"
|
file_type="jsx"
|
||||||
elif [[ $ff == *.tsx ]]; then
|
elif [[ $ff == *.tsx ]]; then
|
||||||
file_type="tsx"
|
file_type="tsx"
|
||||||
|
elif [[ $ff = *.sh ]]; then
|
||||||
|
file_type="sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo $file_type
|
echo $file_type
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
set -uo pipefail
|
set -uo pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
source "$DIR/_reformat-common.sh"
|
source "$DIR/_reformat-common.sh"
|
||||||
|
|
||||||
@@ -18,11 +18,12 @@ if [[ $file_type == "javascript" || \
|
|||||||
$file_type == "php" || \
|
$file_type == "php" || \
|
||||||
$file_type == "html" || \
|
$file_type == "html" || \
|
||||||
$file_type == "jsx" || \
|
$file_type == "jsx" || \
|
||||||
$file_type == "tsx" ]] ; then
|
$file_type == "tsx" || \
|
||||||
|
$file_type == "sh" ]]; then
|
||||||
out=$(npx prettier --write $file)
|
out=$(npx prettier --write $file)
|
||||||
retval="$?"
|
retval="$?"
|
||||||
success_retval=0
|
success_retval=0
|
||||||
elif [[ $file_type == "python" ]] ; then
|
elif [[ $file_type == "python" ]]; then
|
||||||
out=$(pipx run black $file 2>/dev/null)
|
out=$(pipx run black $file 2>/dev/null)
|
||||||
retval="$?"
|
retval="$?"
|
||||||
success_retval=0
|
success_retval=0
|
||||||
@@ -31,7 +32,7 @@ else
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ x"$retval" == x"$success_retval" ]] ; then
|
if [[ x"$retval" == x"$success_retval" ]]; then
|
||||||
echo "$out"
|
echo "$out"
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
set -uo pipefail
|
set -uo pipefail
|
||||||
IFS=$'\n\t'
|
IFS=$'\n\t'
|
||||||
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
file="$1"
|
file="$1"
|
||||||
|
|
||||||
@@ -11,20 +11,21 @@ source "$DIR/_reformat-common.sh"
|
|||||||
|
|
||||||
file_type=$(sniff_file_type $file)
|
file_type=$(sniff_file_type $file)
|
||||||
|
|
||||||
if [[ $file_type == "javascript" || \
|
if [[ $file_type = "javascript" || \
|
||||||
$file_type == "vue" || \
|
$file_type = "vue" || \
|
||||||
$file_type == "typescript" || \
|
$file_type = "typescript" || \
|
||||||
$file_type == "css" || \
|
$file_type = "css" || \
|
||||||
$file_type == "php" || \
|
$file_type = "php" || \
|
||||||
$file_type == "html" || \
|
$file_type = "html" || \
|
||||||
$file_type == "jsx" || \
|
$file_type = "jsx" || \
|
||||||
$file_type == "tsx" ]] ; then
|
$file_type = "tsx" || \
|
||||||
out=$(npx prettier --check $file 2>&1 > /dev/null)
|
$file_type = "sh" ]]; then
|
||||||
|
out=$(npx prettier --check $file 2>&1 >/dev/null)
|
||||||
retval="$?"
|
retval="$?"
|
||||||
success_retval=0
|
success_retval=0
|
||||||
would_reformat_retval=1
|
would_reformat_retval=1
|
||||||
syntax_error_retval=2
|
syntax_error_retval=2
|
||||||
elif [[ $file_type == "python" ]] ; then
|
elif [[ $file_type == "python" ]]; then
|
||||||
out=$(pipx run black --check $file 2>/dev/null)
|
out=$(pipx run black --check $file 2>/dev/null)
|
||||||
retval="$?"
|
retval="$?"
|
||||||
success_retval=0
|
success_retval=0
|
||||||
@@ -36,13 +37,13 @@ else
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ x"$retval" == x"$success_retval" ]] ; then
|
if [[ x"$retval" == x"$success_retval" ]]; then
|
||||||
echo -n "would not change"
|
echo -n "would not change"
|
||||||
exit 0
|
exit 0
|
||||||
elif [[ x"$retval" == x"$would_reformat_retval" ]] ; then
|
elif [[ x"$retval" == x"$would_reformat_retval" ]]; then
|
||||||
echo -n "would change"
|
echo -n "would change"
|
||||||
exit 1
|
exit 1
|
||||||
elif [[ x"$retval" == x"$syntax_error_retval" ]] ; then
|
elif [[ x"$retval" == x"$syntax_error_retval" ]]; then
|
||||||
echo -n "syntax error"
|
echo -n "syntax error"
|
||||||
echo
|
echo
|
||||||
echo "$out"
|
echo "$out"
|
||||||
|
|||||||
Reference in New Issue
Block a user