Created
July 30, 2015 08:29
-
-
Save andriyun/8e65610eab0a3e808c29 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 | |
# PHP CodeSniffer pre-commit hook for git | |
# We should place it to server scripts directory to subfolder drupal-git-hooks and add hook symlink from | |
# repository .git directory to path/to/drupal-git-hooks | |
# ln -s -f /path/to/drupal-git-hooks .git/hooks | |
PHPCS_BIN=/usr/bin/phpcs | |
PHPCS_CODING_STANDARD=Drupal | |
PHPCS_IGNORE= | |
PHPCS_EXT=php,module,inc,install,test,profile,theme,js,css,info,txt | |
# simple check if code sniffer is set up correctly | |
if [ ! -x $PHPCS_BIN ]; then | |
echo "PHP CodeSniffer bin not found or executable -> $PHPCS_BIN" | |
exit 1 | |
fi | |
if [ "$PHPCS_EXT" != "" ]; then | |
EXT="--extensions=$PHPCS_EXT" | |
else | |
EXT="" | |
fi | |
FILES=sites/modules/custom/* | |
OUTPUT=$($PHPCS_BIN -s --standard=$PHPCS_CODING_STANDARD $EXT $FILES) | |
if [ "$OUTPUT" != "" ]; then | |
echo OUTPUT > module-sniffer-errors.txt; | |
echo "Please fix PHPSniffer errors in custom modules"; | |
exit 1 | |
fi | |
FILES=sites/themes/custom/* | |
if [ "$FILES" == "" ]; then | |
exit 0 | |
fi | |
OUTPUT=$($PHPCS_BIN -s --standard=$PHPCS_CODING_STANDARD $EXT $FILES) | |
if [ "$OUTPUT" != "" ]; then | |
echo OUTPUT > theme-sniffer-errors.txt; | |
echo "Please fix PHPSniffer errors in theme"; | |
exit 1 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment