Skip to content

Commit

Permalink
fix(linters): prettier 3+ log level flag compatibility (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
malept authored Apr 29, 2024
1 parent 85e7704 commit a804350
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions shell/linters/prettier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit a804350

Please sign in to comment.