Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use brick's organization coding standards #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Standards

on:
pull_request:
push:

jobs:
coding-standards:
name: Coding Standards
uses: brick/coding-standards/.github/workflows/coding-standards.yml@main
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this workflow run both ECS & Psalm from the coding standards repo, or do you want to separate them into different workflows? In the latter case, I'd prefer to keep the name coding-style if we're going to run ECS only.

I basically consider the coding standards repo as containing:

  • coding-style: ECS
  • static-analysis: Psalm

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah agreed, let's add psalm workflow to this repository and properly split things like you mentioned.

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this still be in tools/ecs? How will we handle this if we include Psalm in the coding-standards repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should stay isolated because brick/coding-standards is actually a composer package too that just wrap ECS and some additional packages for specific sniffers.

However you raise a good point about psalm. This meta package cannot group multiple tools into one package as it would fall into the dependency problem we tried to avoid in the first place.

The best option IMO would be to let each brick libraries require the tools independently and only use the coding-standards repo to share tools configuration files and github workflows.

This would bring some flexibility.

Downside is, every time there's a new tool version, each brick libraries have to be updated one by one. Could be automated at some point though.

AFAIU this what doctrine is doing.

},
"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,
]
);
};