From a804350b708e2e14d6539329a318fd1836bcdacb Mon Sep 17 00:00:00 2001 From: Mark Lee Date: Mon, 29 Apr 2024 15:20:14 -0700 Subject: [PATCH] fix(linters): prettier 3+ log level flag compatibility (#781) --- shell/linters/prettier.sh | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/shell/linters/prettier.sh b/shell/linters/prettier.sh index 35769109..6124e9da 100644 --- a/shell/linters/prettier.sh +++ b/shell/linters/prettier.sh @@ -9,15 +9,33 @@ source "$DIR/languages/nodejs.sh" # shellcheck disable=SC2034 extensions=(yaml yml json md ts) +PRETTIER="node_modules/.bin/prettier" + +prettier_log_level_flag() { + if [[ $("$PRETTIER" --version) =~ ^2 ]]; then + echo "--loglevel" + else + echo "--log-level" + fi +} + prettier_linter() { yarn_install_if_needed >/dev/null - find_files_with_extensions "${extensions[@]}" | xargs -n40 "node_modules/.bin/prettier" -l --log-level log + + local log_level_flag + log_level_flag="$(prettier_log_level_flag)" + + find_files_with_extensions "${extensions[@]}" | xargs -n40 "$PRETTIER" --list-different "$log_level_flag" log return $? } prettier_formatter() { yarn_install_if_needed >/dev/null - find_files_with_extensions "${extensions[@]}" | xargs -n40 "node_modules/.bin/prettier" --write --log-level warn + + local log_level_flag + log_level_flag="$(prettier_log_level_flag)" + + find_files_with_extensions "${extensions[@]}" | xargs -n40 "$PRETTIER" --write "$log_level_flag" warn } linter() {