From 8246a26da179d016e49f9f15e32de489017ae3c0 Mon Sep 17 00:00:00 2001 From: tigitz Date: Tue, 21 Jun 2022 16:17:39 +0200 Subject: [PATCH] Use organization coding standards --- .github/workflows/coding-standards.yml | 10 ++ .github/workflows/coding-style.yml | 27 ---- tools/ecs/composer.json | 4 +- tools/ecs/ecs.php | 211 +------------------------ 4 files changed, 16 insertions(+), 236 deletions(-) create mode 100644 .github/workflows/coding-standards.yml delete mode 100644 .github/workflows/coding-style.yml diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 0000000..6985cd0 --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,10 @@ +name: Coding Style + +on: + pull_request: + push: + +jobs: + coding-standards: + name: Coding Standards + uses: brick/coding-standards/.github/workflows/coding-standards.yml@main diff --git a/.github/workflows/coding-style.yml b/.github/workflows/coding-style.yml deleted file mode 100644 index 78a89b7..0000000 --- a/.github/workflows/coding-style.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Coding Style - -on: - push: - pull_request: - -jobs: - easy-coding-standard: - name: Easy Coding Standard - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: "8.0" - - - name: Install composer dependencies - uses: "ramsey/composer-install@v2" - with: - working-directory: "tools/ecs" - - - name: Run ECS - run: tools/ecs/vendor/bin/ecs check --config tools/ecs/ecs.php diff --git a/tools/ecs/composer.json b/tools/ecs/composer.json index c391767..fe1b22b 100644 --- a/tools/ecs/composer.json +++ b/tools/ecs/composer.json @@ -1,8 +1,6 @@ { "require": { - "symplify/easy-coding-standard": "^10.3", - "slevomat/coding-standard": "^7.2", - "squizlabs/php_codesniffer": "^3.7" + "brick/coding-standards": "dev-main" }, "config": { "allow-plugins": { diff --git a/tools/ecs/ecs.php b/tools/ecs/ecs.php index ff31926..bbe1d87 100644 --- a/tools/ecs/ecs.php +++ b/tools/ecs/ecs.php @@ -3,87 +3,15 @@ declare(strict_types=1); use PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\FunctionCommentSniff; -use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer; -use PhpCsFixer\Fixer\ArrayNotation\NoMultilineWhitespaceAroundDoubleArrowFixer; -use PhpCsFixer\Fixer\ArrayNotation\NoTrailingCommaInSinglelineArrayFixer; -use PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer; -use PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer; -use PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer; -use PhpCsFixer\Fixer\Casing\LowercaseStaticReferenceFixer; -use PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer; -use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer; -use PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer; -use PhpCsFixer\Fixer\CastNotation\ModernizeTypesCastingFixer; -use PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer; -use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer; -use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer; -use PhpCsFixer\Fixer\Comment\CommentToPhpdocFixer; -use PhpCsFixer\Fixer\Comment\SingleLineCommentStyleFixer; -use PhpCsFixer\Fixer\ConstantNotation\NativeConstantInvocationFixer; -use PhpCsFixer\Fixer\ControlStructure\IncludeFixer; -use PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer; -use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer; -use PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer; -use PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer; -use PhpCsFixer\Fixer\FunctionNotation\PhpdocToParamTypeFixer; -use PhpCsFixer\Fixer\FunctionNotation\PhpdocToPropertyTypeFixer; -use PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer; -use PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer; -use PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer; -use PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer; -use PhpCsFixer\Fixer\Import\NoUnusedImportsFixer; -use PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer; -use PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer; -use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer; -use PhpCsFixer\Fixer\Operator\NewWithBracesFixer; -use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer; -use PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer; -use PhpCsFixer\Fixer\Operator\StandardizeIncrementFixer; -use PhpCsFixer\Fixer\Operator\TernaryOperatorSpacesFixer; -use PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer; -use PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer; -use PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer; -use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocAddMissingParamAnnotationFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocNoUselessInheritdocFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocOrderByValueFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocScalarFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocSeparationFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocSingleLineVarSpacingFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocTagCasingFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer; -use PhpCsFixer\Fixer\PhpTag\LinebreakAfterOpeningTagFixer; -use PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertFixer; -use PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertInternalTypeFixer; -use PhpCsFixer\Fixer\PhpUnit\PhpUnitExpectationFixer; -use PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer; -use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer; -use PhpCsFixer\Fixer\Semicolon\NoEmptyStatementFixer; -use PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer; -use PhpCsFixer\Fixer\Semicolon\SemicolonAfterInstructionFixer; -use PhpCsFixer\Fixer\Semicolon\SpaceAfterSemicolonFixer; -use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer; -use PhpCsFixer\Fixer\Strict\StrictComparisonFixer; -use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer; -use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer; use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer; -use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer; -use PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer; -use SlevomatCodingStandard\Sniffs\Commenting\DocCommentSpacingSniff; use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff; use SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff; +use SlevomatCodingStandard\Sniffs\Whitespaces\DuplicateSpacesSniff; use Symplify\EasyCodingStandard\Config\ECSConfig; -use Symplify\EasyCodingStandard\ValueObject\Set\SetList; return static function (ECSConfig $ecsConfig): void { + $ecsConfig->import(__DIR__ . '/vendor/brick/coding-standards/ecs.php'); + $libRootPath = __DIR__ . '/../../'; $ecsConfig->paths( @@ -119,137 +47,8 @@ // Keep a line between same use types, spacing around uses is done in other fixers UseSpacingSniff::class . '.IncorrectLinesCountBeforeFirstUse' => null, UseSpacingSniff::class . '.IncorrectLinesCountAfterLastUse' => null, - ]); - $ecsConfig->sets([ - SetList::PSR_12, + // Arrays in test data providers have values aligned in columns to ease readability + DuplicateSpacesSniff::class => [$libRootPath . '/tests'], ]); - - $ecsConfig->rules( - [ - NoUnusedImportsFixer::class, - BlankLineBeforeStatementFixer::class, - CastSpacesFixer::class, - CommentToPhpdocFixer::class, - DeclareStrictTypesFixer::class, - FunctionTypehintSpaceFixer::class, - LinebreakAfterOpeningTagFixer::class, - LowercaseStaticReferenceFixer::class, - LowercaseCastFixer::class, - MethodChainingIndentationFixer::class, - NativeFunctionCasingFixer::class, - NativeConstantInvocationFixer::class, - NewWithBracesFixer::class, - ModernizeTypesCastingFixer::class, - NoEmptyStatementFixer::class, - NoExtraBlankLinesFixer::class, - NoMultilineWhitespaceAroundDoubleArrowFixer::class, - NoSinglelineWhitespaceBeforeSemicolonsFixer::class, - ObjectOperatorWithoutWhitespaceFixer::class, - PhpUnitDedicateAssertFixer::class, - PhpUnitDedicateAssertInternalTypeFixer::class, - PhpUnitExpectationFixer::class, - NotOperatorWithSuccessorSpaceFixer::class, - PhpUnitStrictFixer::class, - PhpdocAddMissingParamAnnotationFixer::class, - PhpdocToParamTypeFixer::class, - PhpdocToPropertyTypeFixer::class, - PhpdocToReturnTypeFixer::class, - PhpdocAlignFixer::class, - NoEmptyPhpdocFixer::class, - PhpdocIndentFixer::class, - TrimArraySpacesFixer::class, - PhpdocNoEmptyReturnFixer::class, - StandardizeIncrementFixer::class, - IncludeFixer::class, - PhpdocNoUselessInheritdocFixer::class, - NoUnneededControlParenthesesFixer::class, - NoLeadingImportSlashFixer::class, - PhpdocOrderByValueFixer::class, - PhpdocReturnSelfReferenceFixer::class, - PhpdocScalarFixer::class, - PhpdocSeparationFixer::class, - PhpdocSingleLineVarSpacingFixer::class, - PhpdocTagCasingFixer::class, - PhpdocSummaryFixer::class, - PhpdocTrimFixer::class, - PhpdocTypesFixer::class, - PhpdocVarAnnotationCorrectOrderFixer::class, - BinaryOperatorSpacesFixer::class, - SingleQuoteFixer::class, - SemicolonAfterInstructionFixer::class, - ReturnTypeDeclarationFixer::class, - ShortScalarCastFixer::class, - SingleBlankLineBeforeNamespaceFixer::class, - SingleLineCommentStyleFixer::class, - PsrAutoloadingFixer::class, - SpaceAfterSemicolonFixer::class, - NoWhitespaceInBlankLineFixer::class, - StrictComparisonFixer::class, - TernaryOperatorSpacesFixer::class, - TernaryToNullCoalescingFixer::class, - VoidReturnFixer::class, - UnaryOperatorSpacesFixer::class, - WhitespaceAfterCommaInArrayFixer::class, - NoTrailingCommaInSinglelineArrayFixer::class, - TrailingCommaInMultilineFixer::class, - ] - ); - - $ecsConfig->ruleWithConfiguration(ListSyntaxFixer::class, ['syntax' => 'short']); - $ecsConfig->ruleWithConfiguration(MethodArgumentSpaceFixer::class, ['on_multiline' => 'ensure_fully_multiline']); - $ecsConfig->ruleWithConfiguration(OrderedClassElementsFixer::class, ['order' => ['use_trait', 'case', 'constant_public', 'constant_protected', 'constant_private', 'property_public', 'property_protected', 'property_private', 'construct', 'phpunit', 'method_public', 'magic', 'method_protected', 'method_private', 'destruct']]); - $ecsConfig->ruleWithConfiguration(ArraySyntaxFixer::class, ['syntax' => 'short']); - $ecsConfig->ruleWithConfiguration(PhpUnitTestCaseStaticMethodCallsFixer::class, ['call_type' => 'this']); - $ecsConfig->ruleWithConfiguration(PhpdocTypesOrderFixer::class, ['null_adjustment' => 'always_last']); - $ecsConfig->ruleWithConfiguration(NoSuperfluousPhpdocTagsFixer::class, ['allow_mixed' => true]); - $ecsConfig->ruleWithConfiguration(ClassAttributesSeparationFixer::class, ['elements' => ['method' => 'one', 'property' => 'one']]); - - // PHPCS - - $ecsConfig->rules( - [ - FunctionCommentSniff::class, - ] - ); - - $ecsConfig->ruleWithConfiguration( - DocCommentSpacingSniff::class, - [ - 'linesCountBetweenAnnotationsGroups' => 1, - 'annotationsGroups' => [ - '@todo', - '@internal,@deprecated', - '@link,@see,@uses', - '@dataProvider', - '@param', - '@return', - '@throws', - ], - ] - ); - - $ecsConfig->ruleWithConfiguration( - ReferenceUsedNamesOnlySniff::class, - [ - 'allowFallbackGlobalConstants' => false, - 'allowFallbackGlobalFunctions' => false, - 'allowFullyQualifiedGlobalClasses' => false, - 'allowFullyQualifiedGlobalConstants' => false, - 'allowFullyQualifiedGlobalFunctions' => false, - 'allowFullyQualifiedNameForCollidingClasses' => true, - 'allowFullyQualifiedNameForCollidingConstants' => true, - 'allowFullyQualifiedNameForCollidingFunctions' => true, - 'searchAnnotations' => true, - ] - ); - - $ecsConfig->ruleWithConfiguration( - UseSpacingSniff::class, - [ - 'linesCountAfterLastUse' => 0, - 'linesCountBetweenUseTypes' => 1, - 'linesCountBeforeFirstUse' => 0, - ] - ); };