Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #13 from M6Web/feature/phpcbf
Browse files Browse the repository at this point in the history
New "--fix (-f)" mode to auto-correct violations
  • Loading branch information
mikaelrandy committed Jul 27, 2015
2 parents 7276a44 + cf151ab commit fa5cedc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
composer.lock
vendor
40 changes: 26 additions & 14 deletions coke
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,16 @@ params=""
options=""
standard=""
standardPath=""

composerCommand="vendor/squizlabs/php_codesniffer/scripts/phpcs"

command="phpcs";
if [ -e "$composerCommand" ]
then
command="$composerCommand"
fi

commandPath=""
composerPath="vendor/squizlabs/php_codesniffer/scripts/"
filesAllowed=""
filesIgnored=""

ignored=0
allowed=0
verbose=0
fix=0

function allow
{
Expand Down Expand Up @@ -89,8 +84,7 @@ function debug
fi
}

# Résolution des options

# Resolve options
while [ $# -ne 0 ]
do
CUR_PARAM="$1"
Expand All @@ -107,6 +101,9 @@ do
elif [ "${CUR_PARAM:2:14}" = "standard-path=" ]
then
standardPath="${CUR_PARAM:16}"
elif [ "${CUR_PARAM:2:5}" = "fix" ]
then
fix=1
else
params="$params $CUR_PARAM"
fi
Expand All @@ -116,6 +113,9 @@ do
v)
verbose=1
;;
f)
fix=1
;;
esac

options="$options ${CUR_PARAM}"
Expand All @@ -127,8 +127,20 @@ do
shift
done

# Resolve files to test
# Resolve commands path to use
if [ -d "$composerPath" ]
then
debug "Command path used is \"$composerPath\""
commandPath="$composerPath"
fi

if [ $fix -eq 1 ]
then
debug "Use phpcbf command instead of phpcs"
command="phpcbf"
fi

# Resolve files to test
if [ -e "$file" ]
then
output=$( grep "^[^\#]" $file )
Expand Down Expand Up @@ -180,7 +192,7 @@ fi
if [ -n "$standardPath" ]
then
debug "Change standard path to \"$standardPath\""
$command --config-set installed_paths $standardPath
$commandPath$command --config-set installed_paths $standardPath
fi

# Punch it!
Expand All @@ -189,7 +201,7 @@ if [ -n "$filesAllowed" ]
then
debug "Files allowed : \"$filesAllowed\""

$command $filesAllowed $filesIgnored $standard $options $params
$commandPath$command $filesAllowed $filesIgnored $standard $options $params

if [ $? -ne 0 ]
then
Expand All @@ -204,5 +216,5 @@ success "All files match with \"${standard:11}\" requirements"
if [ -n "$standardPath" ]
then
debug "Reset standard path"
$command --config-delete installed_paths
$commandPath$command --config-delete installed_paths
fi

0 comments on commit fa5cedc

Please sign in to comment.