Skip to content

Instantly share code, notes, and snippets.

@flaccus
Created November 15, 2022 02:14
Show Gist options
  • Save flaccus/1494c361514b6069036a5752d624e3c9 to your computer and use it in GitHub Desktop.
Save flaccus/1494c361514b6069036a5752d624e3c9 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# An hook script to apply prettier/rubocop rulse to what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
### PRETTIER
git diff --cached --name-only --diff-filter=d | xargs ./node_modules/.bin/prettier -c
code=$?
if [ $code != 0 ]; then
echo "Error running prettier. Please fix any issues and re-run."
exit 1
fi
### RUBOCOP
git diff --cached --name-only --diff-filter=d | xargs rubocop -a
code=$?
if [ $code != 0 ]; then
echo "Error running rubocop. Please fix any issues and re-run."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment