Skip to content

Commit

Permalink
Fix prettier throwing errors (ankidroid#12895)
Browse files Browse the repository at this point in the history
* Fix prettier throwing errors

* Don't run prettier if there is not JS modified files

Now pre-commit can be faster and throw less errors
  • Loading branch information
RobozinhoD authored Nov 30, 2022
1 parent 9d7aa46 commit c15cc96
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ runPrettier () {
return 0
fi

# Run prettier over all Javascript files
npx --yes prettier --ignore-unknown --write AnkiDroid/**/*.js
CHANGED_JS_FILES="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $2 ~ /\.js/ { print $2 }')"
if [ -z "$CHANGED_JS_FILES" ]; then
echo "No Javascript staged files. Hence, skipping pre-commit Prettier run."
return 0
fi;

# Prettify changed files
echo "$CHANGED_JS_FILES" | xargs npx prettier --ignore-unknown --write

echo "Completed npx prettier run."
echo "$CHANGED_JS_FILES" | while read -r file; do
Expand All @@ -67,5 +73,5 @@ runPrettier () {
}

runKtlint
runPrettier
runPrettier || :; # || to avoid cancelling the commit if there is an error with Prettier
echo "Completed the pre-commit hook."

0 comments on commit c15cc96

Please sign in to comment.