Skip to content

Commit

Permalink
make sure all files get checked and all errors are outputted
Browse files Browse the repository at this point in the history
  • Loading branch information
woutersioen committed Apr 28, 2013
1 parent 5b9e9bd commit e39c153
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

### php codesniffer

http://pear.php.net/package/PHP_CodeSniffer/redirected
[http://pear.php.net/package/PHP_CodeSniffer/redirected](http://pear.php.net/package/PHP_CodeSniffer/redirected)

You can install php codesniffer with these commands:

Expand All @@ -13,12 +13,12 @@ You can install php codesniffer with these commands:

### Fork coding standards in ~/.phpcs/Fork

This is based on this dotfiles setup: (https://github.com/WouterSioen/dotfiles).
This is based on this dotfiles setup: [https://github.com/WouterSioen/dotfiles](https://github.com/WouterSioen/dotfiles).
If you want to put it in another place, just change the --standard parameter in the phpcs command.

### esvalidate

https://github.com/duereg/esvalidate
[https://github.com/duereg/esvalidate](https://github.com/duereg/esvalidate)

Esvalidate is easy to install with the node package manager:

Expand Down
22 changes: 15 additions & 7 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,30 @@
# @version 1.0.0
# @author Wouter Sioen <[email protected]>

# create empty errors array
declare -a errors

# fetch all changed php files and validate them
files=$(git diff-index --name-only HEAD | grep -P '\.php$')
for file in $files; do

# first check if they are valid php files
output=`php -l $file | grep 'PHP Parse error'`
output=`php -l $file | grep 'Errors parsing'`

# if it did contain errors, we have output
if [ -n "$output" ]; then
echo "$file contains php syntax errors"
exit 1
errors=("${errors[@]}" "$output")
fi

# checks if the phpcs output contains '(0 errors, 0 warnings)'
output=`phpcs -v --standard="$HOME/.phpcs/Fork" --report=full $file | grep '| ERROR |'`
output=`phpcs --standard="$HOME/.phpcs/Fork" --report=full $file | grep '| ERROR |'`

# if it did contain errors, we have output
if [ -n "$output" ]; then
echo "$file fails coding standards"
echo $output
exit 1
phpcs --standard="$HOME/.phpcs/Fork" --report=full $file
errors=("${errors[@]}" "$output")
fi
done

Expand All @@ -43,6 +46,11 @@ for file in $files; do
if [ -n "$output" ]; then
echo "$file contains javascript syntax errors"
echo $output
exit 1
errors=("${errors[@]}" "$output")
fi
done
done

# if we have errors, exit with 1
if [ -n "errors" ]; then
exit 1
fi

0 comments on commit e39c153

Please sign in to comment.