-
-
Save Cheffheid/5d06d7872a4d8ac6c1354af9d8f6305a to your computer and use it in GitHub Desktop.
ESLint / PHPCS Git Pre Commit Hook
This file contains 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
# Ruthlessly stolen from Wes Bos' ESLint pre commit hook, and expanded to also run PHPCS. | |
#!/bin/bash | |
jsfiles=$(git diff --cached --name-only | grep '\.jsx\?$') | |
# Only do something if we have JS files. | |
if [[ $jsfiles != "" ]] ; then | |
jsfailed=0 | |
for jsfile in ${jsfiles}; do | |
git show :$jsfile | eslint $jsfile | |
if [[ $? != 0 ]] ; then | |
jsfailed=1 | |
fi | |
done; | |
if [[ $jsfailed != 0 ]] ; then | |
echo "ESLint failed, git commit denied!" | |
exit $jsfailed | |
fi | |
fi | |
phpfiles=$(git diff --cached --name-only | grep '\.php\?$') | |
# Only do something if we have PHP files. | |
if [[ $phpfiles != "" ]] ; then | |
phpfailed=0 | |
for phpfile in ${phpfiles}; do | |
git show :$phpfile | phpcs --standard=WordPress-Extra $phpfile | |
if [[ $? != 0 ]] ; then | |
phpfailed=1 | |
fi | |
done; | |
if [[ $phpfailed != 0 ]] ; then | |
echo "PHPCS failed, git commit denied!" | |
exit $phpfailed | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment