diff --git a/prettier.sh b/prettier.sh index 650226a..29bda76 100755 --- a/prettier.sh +++ b/prettier.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/bash set -uo pipefail IFS=$'\n\t' @@ -7,18 +7,21 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$DIR/_reformat-common.bash" +set -e + file="$1" -wrflog running against file "$file" +pushd "$(dirname "$file")" 2>&1 -if [[ "$WOULD_REFORMAT" = "would_reformat" ]] ; then +if [[ "$WOULD_REFORMAT" = "would_reformat" ]]; then + set +e out=$(npx prettier --check "$file" 2>&1 >/dev/null) retval="$?" - echo "$out" + set -e exit "$retval" fi -if [[ "$WOULD_REFORMAT" = "do_reformat" ]] ; then +if [[ "$WOULD_REFORMAT" = "do_reformat" ]]; then out=$(npx prettier --write "$file" 2>&1 >/dev/null) retval="$?"