Last active
March 8, 2017 02:53
-
-
Save llimllib/acca10ef730384ee519631843e4c31b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# don't allow the commit if it contains any files that are not correctly | |
# formatted by prettier (https://github.com/jlongster/prettier/). | |
# Directly inspired by the gofmt precommit hook: | |
# https://golang.org/misc/git/pre-commit | |
# | |
# 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