Start extracting language-specific formatters
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.dir-locals.el
|
||||
bin/
|
||||
node_modules/
|
||||
.root
|
||||
|
||||
@@ -2,6 +2,24 @@ function root() {
|
||||
echo "$(git rev-parse --show-toplevel)"
|
||||
}
|
||||
|
||||
wfroot() {
|
||||
dir="$1"
|
||||
cat "$dir/.root"
|
||||
}
|
||||
|
||||
function custom_formatter() {
|
||||
root="$1"
|
||||
file_type="$2"
|
||||
|
||||
maybe="$root/.would-reformat/$file_type"
|
||||
if [[ -f "$maybe" ]] ; then
|
||||
echo "$maybe"
|
||||
return
|
||||
fi
|
||||
|
||||
echo "use-default"
|
||||
}
|
||||
|
||||
function sniff_file_type() {
|
||||
ff=$1
|
||||
shift
|
||||
@@ -39,3 +57,8 @@ function sniff_file_type() {
|
||||
|
||||
echo $file_type
|
||||
}
|
||||
|
||||
|
||||
function wrflog() {
|
||||
echo "$@" >> /tmp/wrflog
|
||||
}
|
||||
|
||||
@@ -7,13 +7,18 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
here=$(pwd)
|
||||
|
||||
pushd $DIR
|
||||
rm -f .root
|
||||
echo "$(pwd)" > .root
|
||||
popd
|
||||
|
||||
ret=0
|
||||
|
||||
# If this use of readlink breaks, see
|
||||
# https://unix.stackexchange.com/questions/47710/find-only-destination-of-symlink
|
||||
# for discussion of alternatives.
|
||||
|
||||
for i in _reformat-common.sh do-reformat.sh would-reformat.sh; do
|
||||
for i in _reformat-common.bash do-reformat.sh would-reformat.sh .root; do
|
||||
if [[ -f "$here"/bin/"$i" ]] ; then
|
||||
dest=$(readlink bin/$i)
|
||||
if [[ x"$dest" == x"$DIR/$i" ]] ; then
|
||||
|
||||
28
prettier.sh
Executable file
28
prettier.sh
Executable file
@@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -uo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
source "$DIR/_reformat-common.bash"
|
||||
|
||||
file="$1"
|
||||
|
||||
wrflog running against file $file
|
||||
|
||||
out=$(npx prettier --check $file 2>&1 >/dev/null)
|
||||
|
||||
if [[ x"$WOULD_REFORMAT" = x"would_reformat" ]] ; then
|
||||
out=$(npx prettier --check $file 2>&1 >/dev/null)
|
||||
retval="$?"
|
||||
exit "$retval"
|
||||
fi
|
||||
|
||||
if [[ x"$WOULD_REFORMAT" = x"do_reformat" ]] ; then #
|
||||
out=$(npx prettier --write $file 2>&1 >/dev/null)
|
||||
retval="$?"
|
||||
exit "$retval"
|
||||
fi
|
||||
|
||||
exit 255
|
||||
@@ -5,12 +5,20 @@ IFS=$'\n\t'
|
||||
|
||||
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
source "$DIR/_reformat-common.bash"
|
||||
|
||||
wrflog asdf asdf asdf
|
||||
|
||||
file="$1"
|
||||
|
||||
source "$DIR/_reformat-common.sh"
|
||||
## fixme use realpath or something on "$file"
|
||||
|
||||
|
||||
|
||||
file_type=$(sniff_file_type $file)
|
||||
|
||||
wrflog got file_type $file_type
|
||||
|
||||
if [[ $file_type = "javascript" || \
|
||||
$file_type = "vue" || \
|
||||
$file_type = "typescript" || \
|
||||
@@ -22,7 +30,10 @@ if [[ $file_type = "javascript" || \
|
||||
$file_type == "css" || \
|
||||
$file_type == "scss" || \
|
||||
$file_type = "sh" ]]; then
|
||||
out=$(npx prettier --check $file 2>&1 >/dev/null)
|
||||
wrflog will run thing
|
||||
wrflog "$(wfroot $DIR)"
|
||||
wrflog "prettier: $(ls -l $(wfroot $DIR)/./prettier.sh)"
|
||||
out=$(WOULD_REFORMAT=would_reformat $(wfroot $DIR)/./prettier.sh $file 2>&1 > /dev/null)
|
||||
retval="$?"
|
||||
success_retval=0
|
||||
would_reformat_retval=1
|
||||
|
||||
Reference in New Issue
Block a user