Skip to content

Instantly share code, notes, and snippets.

@llimllib llimllib/
Last active Mar 8, 2017

What would you like to do?
# don't allow the commit if it contains any files that are not correctly
# formatted by prettier (
# Directly inspired by the gofmt precommit hook:
# This code is BSD licensed.
# To use, store as .git/hooks/pre-commit inside your repository and make sure
# it has execute permissions. It will not handle files with spaces in their
# name.
jsfiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.js$')
[ -z "$jsfiles" ] && exit 0
diffs=$(node_modules/.bin/prettier -l $jsfiles | tr '\n' ' ')
[ -z "$diffs" ] && exit 0
echo >&2 "Javascript files must be formatted with prettier. Please run:"
echo >&2 "prettier --write $(echo $jsfiles | tr '\n' ' ')"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.