0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-19 19:42:17 +02:00

Fix prettier throwing errors (#12895)

* 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
This commit is contained in:
Robozinho 2022-11-29 21:30:07 -03:00 committed by GitHub
parent 9d7aa468a7
commit c15cc962aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,8 +55,14 @@ runPrettier () {
return 0 return 0
fi fi
# Run prettier over all Javascript files CHANGED_JS_FILES="$(git --no-pager diff --name-status --no-color --cached | awk '$1 != "D" && $2 ~ /\.js/ { print $2 }')"
npx --yes prettier --ignore-unknown --write AnkiDroid/**/*.js 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 "Completed npx prettier run."
echo "$CHANGED_JS_FILES" | while read -r file; do echo "$CHANGED_JS_FILES" | while read -r file; do
@ -67,5 +73,5 @@ runPrettier () {
} }
runKtlint runKtlint
runPrettier runPrettier || :; # || to avoid cancelling the commit if there is an error with Prettier
echo "Completed the pre-commit hook." echo "Completed the pre-commit hook."