- Rewrite wrapper script to be in PHP instead of Bash, for Windows compat.
- Potentially write a separate PHP wrapper/replacement for
phpcs
, one that instantiates PHP_CodeSniffer and does custom handling of the results. - Allow subset to be done on a file level, to only check lines that have been staged or edited.
- Improve method for obtaining the ruleset.xml, and making it optional.
Last active
December 20, 2015 11:28
-
-
Save westonruter/6123121 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Run php files in the repo through phpcs, opting for a subset of only checking staged or modified files | |
# By @westonruter | |
status_filter='^.M' | |
status_filter_description="Linting modified files only" | |
while getopts ":sa" opt; do | |
case $opt in | |
s) | |
status_filter='^M' | |
status_filter_description="Linting staged files only" | |
;; | |
a) | |
status_filter='' | |
status_filter_description="Linting everything" | |
;; | |
esac | |
done | |
echo $status_filter_description | |
shift $((OPTIND-1)) | |
if [ $# == 0 ]; then | |
paths=$(pwd) | |
else | |
paths=$@ | |
fi | |
echo "Linting path(s) $paths" | |
if [ -z $status_filter ]; then | |
php_files=$(find $paths -type f -name '*.php') | |
else | |
php_files=$( | |
git status --porcelain -s $paths | | |
grep -E "$status_filter" | | |
cut -c4- | | |
grep -E '\.php$' | |
) | |
fi | |
project_dir=$(dirname $0) | |
if [ -n "$php_files" ]; then | |
phpcs --standard=$project_dir/codesniffer.ruleset.xml $php_files | |
else | |
echo "Nothing to lint" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment