-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add php-cs-fixer code style pre-commit hook
Check staged files for code style correctness and abort if any file fails a style check test. Reorganise repository to allow per-hook documentation.
- Loading branch information
Showing
5 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# PHP Code Style Fixer Pre-Commit | ||
|
||
To use this pre-commit hook, you will need to have [php-cs-fixer.phar](http://get.sensiolabs.org/php-cs-fixer.phar) somewhere in your path. | ||
|
||
This pre-commit hook will look at files being commited if the file | ||
|
||
- has a .php extension | ||
- is inside the local code pool, i.e. app/code/local | ||
- is not a controller (which do not obey PSR-0 class name -> path conventions) | ||
|
||
Qualifying files will be run through php-cs-fixer.phar to check for code style issues. If an issue is found, a diff of suggested changes will be displayed and the fixers that failed listed. The commit will then be aborted. | ||
|
||
To force a commit to bypass these checks run git commit with the --no-verify argument. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
$finder = Symfony\CS\Finder\DefaultFinder::create() | ||
->name('*.php') | ||
->name('*.phtml') | ||
->name('*.xml') | ||
->exclude(array( | ||
'lib', | ||
'shell', | ||
'app/Mage.php', | ||
'app/code/core', | ||
'app/code/community', | ||
'app/design/frontend/default', | ||
'app/design/frontend/enterprise/default', | ||
'app/design/frontend/base', | ||
'app/design/adminhtml/default') | ||
) | ||
->notName('*Controller.php') | ||
->notName('*ControllerTest.php') | ||
->in(__DIR__); | ||
|
||
return Symfony\CS\Config\Config::create() | ||
->finder($finder); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
ABORT_COMMIT=false | ||
|
||
while read -r FILE; do | ||
if [[ $FILE =~ 'app/code/local' ]]; then | ||
php-cs-fixer.phar fix --dry-run --diff -v $FILE | ||
if [ $? -gt 0 ]; then | ||
ABORT_COMMIT=true | ||
fi | ||
fi | ||
done < <(git diff-index --name-only --diff-filter=ACM --cached HEAD | \ | ||
egrep '\.(php)$' | egrep -v 'Controller.php$') | ||
|
||
if [ $ABORT_COMMIT = true ]; then | ||
echo "Code style errors found, aborting commit" | ||
exit 1 | ||
fi |
File renamed without changes.