Skip to content

Commit

Permalink
Use organization coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
tigitz committed Jun 21, 2022
1 parent 3cf5ecd commit 0a4f18d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 236 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 0 additions & 27 deletions .github/workflows/coding-style.yml

This file was deleted.

4 changes: 1 addition & 3 deletions tools/ecs/composer.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
211 changes: 5 additions & 206 deletions tools/ecs/ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
]
);
};

0 comments on commit 0a4f18d

Please sign in to comment.