-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OXDEV-8655 Integrate EasyCodingStandards with hooks
- Loading branch information
1 parent
e276572
commit 52142b8
Showing
4 changed files
with
122 additions
and
3 deletions.
There are no files selected for viewing
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,41 @@ | ||
#!/usr/bin/env bash | ||
|
||
# get bash colors and styles here: | ||
# http://misc.flogisoft.com/bash/tip_colors_and_formatting | ||
style_reset='\e[0m' | ||
style_red='\e[31m' | ||
style_green='\e[32m' | ||
style_bold='\e[1m' | ||
style_underline='\e[4m' | ||
style_dim='\e[2m' | ||
|
||
function __run() #(step, name, cmd) | ||
{ | ||
local output exitcode | ||
|
||
printf "[%s] %-20s" "$1" "$2" | ||
output=$(eval "$3" 2>&1) | ||
exitcode=$? | ||
|
||
if [[ 0 == "$exitcode" || 130 == "$exitcode" ]]; then | ||
echo -e " ${style_green}OK!${style_reset}" | ||
else | ||
echo -e " ${style_red}ERROR!${style_reset}" | ||
echo -e "\n${style_bold}Git commit was interrupted!${style_reset}" | ||
echo -e "${style_underline}$2${style_reset} run failed:" | ||
echo -e "${style_dim}$3${style_reset}${style_bold}$output${style_reset}\n" | ||
echo -e "Fix all the reported issues and try again. Or run commit command with \"--no-verify\" option to skip all configured pre-commit hooks." | ||
exit 1 | ||
fi | ||
} | ||
|
||
php="docker-compose exec -T php php" | ||
internalDir="source/Internal" | ||
testsDir="tests/" | ||
|
||
modified="git diff --cached --name-only --diff-filter=ACM | grep '.php$'" | ||
ecs="${php} vendor/bin/ecs check ${internalDir} ${testsDir} --no-diffs --no-progress-bar" | ||
|
||
echo -e "Running pre-commit hooks:" | ||
__run "1/2" "PHP lint" "${modified} | xargs -r ${php} -l" | ||
__run "2/2" "Easy Coding Standard" "${ecs}" |
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,12 @@ | ||
#!/bin/sh | ||
if [ ! -L .git/hooks ]; | ||
then | ||
echo ".git/hooks is not symlink" | ||
echo "copying .git/hooks to .git/old_hooks" | ||
mv .git/hooks .git/old_hooks | ||
|
||
echo "symlinking ../.git-hooks .git/hooks" | ||
ln -s ../.git-hooks .git/hooks | ||
else | ||
echo ".git/hooks is already a symlink" | ||
fi |
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
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,63 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright © OXID eSales AG. All rights reserved. | ||
* See LICENSE file for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer; | ||
use PhpCsFixer\Fixer\Comment\HeaderCommentFixer; | ||
use PhpCsFixer\Fixer\Import\OrderedImportsFixer; | ||
use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer; | ||
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer; | ||
use PhpCsFixer\Fixer\Whitespace\BlankLineBetweenImportGroupsFixer; | ||
use Symplify\EasyCodingStandard\Config\ECSConfig; | ||
|
||
return ECSConfig::configure() | ||
->withRules([ | ||
BlankLineBetweenImportGroupsFixer::class, | ||
]) | ||
->withPreparedSets( | ||
psr12: true, | ||
common: true, | ||
strict: true, | ||
) | ||
->withConfiguredRule( | ||
HeaderCommentFixer::class, | ||
[ | ||
'header' => 'Copyright © OXID eSales AG. All rights reserved. | ||
See LICENSE file for license details.', | ||
'location' => 'after_open', | ||
'comment_type' => 'PHPDoc' | ||
] | ||
) | ||
->withConfiguredRule( | ||
ClassAttributesSeparationFixer::class, | ||
[ | ||
'elements' => [ | ||
'property' => ClassAttributesSeparationFixer::SPACING_NONE, | ||
'const' => ClassAttributesSeparationFixer::SPACING_NONE, | ||
], | ||
] | ||
) | ||
->withConfiguredRule( | ||
OrderedImportsFixer::class, | ||
[ | ||
'sort_algorithm' => OrderedImportsFixer::SORT_ALPHA, | ||
'imports_order' => [ | ||
OrderedImportsFixer::IMPORT_TYPE_CLASS, | ||
OrderedImportsFixer::IMPORT_TYPE_FUNCTION, | ||
OrderedImportsFixer::IMPORT_TYPE_CONST, | ||
] | ||
] | ||
) | ||
->withSkip( | ||
[ | ||
NotOperatorWithSuccessorSpaceFixer::class, | ||
DeclareStrictTypesFixer::class => [ | ||
'*Interface.php', | ||
] | ||
], | ||
); |