deprecated-packages / symplify

[DISCONTINUED] Check split packages in their own repositories :)
MIT License
621 stars 189 forks source link

[EasyCodingStandards] PhpCsFixer configuration errors #1746

Closed gubler closed 4 years ago

gubler commented 4 years ago

I updated to the -prefix PHAR for ECS and when I try to run it I get FixerIsNotConfigurableException for any special PhpCsFixer configuration.

For example, I have this in my ecs.yml:

services:
    PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer:
        syntax: short

And I get the error:

PHP Fatal error:  Uncaught Symplify\EasyCodingStandard\Exception\DependencyInjection\Extension\FixerIsNotConfigurableException: Fixer "PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer" is not configurable with configuration: {"syntax":"short"}. in phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/src/Yaml/CheckerConfigurationGuardian.php:21

I rolled back to the non -prefix version and I do not receive an error.

Please let me know if you want my full ecs.yml file.

TomasVotruba commented 4 years ago

Just released possible fix:

https://github.com/Symplify/Symplify/commit/f3c7be46b120b1359fe096b1e60881dfae000b8b#diff-db50a482ae36d9c82f649455710056fb

Could you try dev-master of prefixed version?

gubler commented 4 years ago

New errors :)

First, I got this:

Fatal error: Uncaught _HumbugBox0f4e8e911c87\Symfony\Component\Config\Exception\FileLocatorFileNotFoundException: The file "vendor/symplify/easy-coding-standard/config/set/clean-code.yaml" does not exist (in: /home/vagrant/code). in phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/config/FileLocator.php:60

I updated my ecs.yml to replace the imports: section with the new sets: section and that changed the error to:

PHP Fatal error:  Uncaught _HumbugBox0f4e8e911c87\Symfony\Component\DependencyInjection\Exception\RuntimeException: Cannot autowire service "Symplify\CodingStandard\Fixer\Php\ClassStringToClassConstantFixer": argument "$classLikeExistenceChecker" of method "__construct()" references class "Symplify\PackageBuilder\Types\ClassLikeExistenceChecker" but no such service exists. in phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/dependency-injection/Compiler/DefinitionErrorExceptionPass.php:49

Here is my current ecs.yml file for testing:

parameters:
    cache_directory: var/cache/ecs
    skip:
        PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\AssignmentInConditionSniff: ~
        PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer: ~
        PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer: ~
        PhpCsFixer\Fixer\Operator\ConcatSpaceFixer: ~
        PhpCsFixer\Fixer\Operator\IncrementStyleFixer: ~
        PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: ~
        PhpCsFixer\Fixer\Phpdoc\PhpdocAnnotationWithoutDotFixer: ~
        PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer: ~
        SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff.MissingTraversableParameterTypeHintSpecification: ~
        SlevomatCodingStandard\Sniffs\TypeHints\TypeHintDeclarationSniff.MissingTraversableReturnTypeHintSpecification: ~
        Symplify\CodingStandard\Sniffs\ControlStructure\SprintfOverContactSniff: ~
        SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff: ~
        Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff: ~
        SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff: ~
        PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer: ~
    exclude_files:
        - 'src/Kernel.php'
    sets:
        - 'clean-code'
        - 'common'
        - 'php70'
        - 'php71'
        - 'psr2'
        - 'psr12'
        - 'symfony'
        - 'symfony-risky'
services:
    # PHP 5.5
    Symplify\CodingStandard\Fixer\Php\ClassStringToClassConstantFixer: ~

    # Control Structures
    Symplify\CodingStandard\Fixer\Property\ArrayPropertyDefaultValueFixer: ~
    Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer: ~
    Symplify\CodingStandard\Fixer\ControlStructure\RequireFollowedByAbsolutePathFixer: ~

    # Spaces
    Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer: ~

    # Comments
    Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousDocBlockWhitespaceFixer: ~

    # Naming
    PhpCsFixer\Fixer\PhpUnit\PhpUnitMethodCasingFixer: ~

    # Debug
    Symplify\CodingStandard\Sniffs\Debug\DebugFunctionCallSniff: ~
    Symplify\CodingStandard\Sniffs\Debug\CommentedOutCodeSniff: ~

    # final classes
    PhpCsFixer\Fixer\ClassNotation\FinalInternalClassFixer: ~

    # multibyte
    PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer: ~

    # psr
    PhpCsFixer\Fixer\Basic\Psr0Fixer: ~
    PhpCsFixer\Fixer\Basic\Psr4Fixer: ~

    # psr-1
    PHP_CodeSniffer\Standards\PSR1\Sniffs\Classes\ClassDeclarationSniff: ~
    PHP_CodeSniffer\Standards\PSR1\Sniffs\Files\SideEffectsSniff: ~
    PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff: ~

    PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer: ~
    PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer: ~
    PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer: ~
    PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer: ~
    PhpCsFixer\Fixer\Import\OrderedImportsFixer:
        importsOrder:
            - 'class'
            - 'const'
            - 'function'
    PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer:
        space: 'none'
    PhpCsFixer\Fixer\Operator\NewWithBracesFixer: ~
    PhpCsFixer\Fixer\Basic\BracesFixer:
        'allow_single_line_closure': false
        'position_after_functions_and_oop_constructs': 'next'
        'position_after_control_structures': 'same'
        'position_after_anonymous_constructs': 'same'
    PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer:
        syntax: short
    PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer: ~
    PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer:
        elements:
            - 'const'
            - 'method'
            - 'property'
    PhpCsFixer\Fixer\Operator\TernaryOperatorSpacesFixer: ~
    PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer:
        space_before: 'none'
    PhpCsFixer\Fixer\Whitespace\NoTrailingWhitespaceFixer: ~

    PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer: ~
    PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer: ~
    PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer: ~

    # merge issets
    PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveIssetsFixer: ~
    PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer: ~

    # remove useless phpdoc
    PhpCsFixer\Fixer\FunctionNotation\PhpdocToReturnTypeFixer: ~
    PhpCsFixer\Fixer\Import\FullyQualifiedStrictTypesFixer: ~
    PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer: ~

    # arguable checkers, feel free to remove them
    Symplify\CodingStandard\Sniffs\ControlStructure\SprintfOverContactSniff: ~
    PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer:
        order:
            - 'use_trait'
    PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer: ~
    PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: ~
    PhpCsFixer\Fixer\Operator\ConcatSpaceFixer:
        spacing: 'one'
    PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer:
        statements:
            - 'return'

    # cognitive complexity - adjust level to your needs, starting from 100
    Symplify\CodingStandard\Sniffs\CleanCode\CognitiveComplexitySniff:
        maxCognitiveComplexity: 30
TomasVotruba commented 4 years ago

New errors :)

Yay :smile:

I updated my ecs.yml to replace the imports: section with the new sets: section and that changed the error to:

Correct solution! GJ

Cannot autowire service

That will be probably internal import config path problem. Good report, thanks!

TomasVotruba commented 4 years ago

Let's cover it with test: https://github.com/Symplify/EasyCodingStandardPrefixed/commit/7b50eb6fdf46164d7eb10afb6a255611003fec53

TomasVotruba commented 4 years ago

Could you re-try with current dev-master?

gubler commented 4 years ago

Composer update:

  - Removing symplify/easy-coding-standard-prefixed (dev-master ff2ea30)
  - Installing symplify/easy-coding-standard-prefixed (dev-master 7b50eb6): Downloading (100%)

Deleted the existing cache and the result of the run:

PHP Fatal error:  Uncaught _HumbugBox879a7d36aa5c\Symfony\Component\DependencyInjection\Exception\RuntimeException: Cannot autowire service "Symplify\CodingStandard\Fixer\Php\ClassStringToClassConstantFixer": argument "$classLikeExistenceChecker" of method "__construct()" references class "Symplify\PackageBuilder\Types\ClassLikeExistenceChecker" but no such service exists. in phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/dependency-injection/Compiler/DefinitionErrorExceptionPass.php:49
Stack trace:
#0 phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php(72): _HumbugBox879a7d36aa5c\Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue(Object(_HumbugBox879a7d36aa5c\Symfony\Component\DependencyInjection\Definition), true)
#1 phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/dependency-injection/Compiler/DefinitionErro in phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/dependency-injection/Compiler/DefinitionErrorExceptionPass.php on line 49

Fatal error: Uncaught _HumbugBox879a7d36aa5c\Symfony\Component\DependencyInjection\Exception\RuntimeException: Cannot autowire service "Symplify\CodingStandard\Fixer\Php\ClassStringToClassConstantFixer": argument "$classLikeExistenceChecker" of method "__construct()" references class "Symplify\PackageBuilder\Types\ClassLikeExistenceChecker" but no such service exists. in phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/dependency-injection/Compiler/DefinitionErrorExceptionPass.php on line 49

_HumbugBox879a7d36aa5c\Symfony\Component\DependencyInjection\Exception\RuntimeException: Cannot autowire service "Symplify\CodingStandard\Fixer\Php\ClassStringToClassConstantFixer": argument "$classLikeExistenceChecker" of method "__construct()" references class "Symplify\PackageBuilder\Types\ClassLikeExistenceChecker" but no such service exists. in phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/dependency-injection/Compiler/DefinitionErrorExceptionPass.php on line 49

Call Stack:
    0.0004     388024   1. {main}() /home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs:0
    0.1663    2307272   2. require('phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/bin/ecs') /home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs:6
    0.5495    7195616   3. Symplify\EasyCodingStandard\HttpKernel\EasyCodingStandardKernel->boot() phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/bin/ecs:68
    0.5495    7195616   4. Symplify\EasyCodingStandard\HttpKernel\EasyCodingStandardKernel->initializeContainer() phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/http-kernel/Kernel.php:113
    0.8911   12346784   5. _HumbugBox879a7d36aa5c\Symfony\Component\DependencyInjection\ContainerBuilder->compile() phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/http-kernel/Kernel.php:463
    0.9053   12358384   6. _HumbugBox879a7d36aa5c\Symfony\Component\DependencyInjection\Compiler\Compiler->compile() phar:///home/vagrant/code/vendor/symplify/easy-coding-standard-prefixed/ecs/vendor/symfony/dependency-injection/ContainerBuilder.php:620
TomasVotruba commented 4 years ago

Could you create reproducible repository on Github? I can't replicate it

TomasVotruba commented 4 years ago

You can also extend existing test case to fail: https://github.com/Symplify/EasyCodingStandardPrefixed/blob/7b50eb6fdf46164d7eb10afb6a255611003fec53/.github/workflows/parameters_sets.yaml#L24

That would be even better, as it could be part of our test suite

gnutix commented 4 years ago

Sorry for this unexpected comment (don't have time), but I just wanted to report I tried using the phar too today and encountered several issues :

  1. Symplify\EasyCodingStandard\Exception\DependencyInjection\Extension\FixerIsNotConfigurableException on PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer.allowed_mixed: true
  2. Symplify\EasyCodingStandard\Exception\DependencyInjection\Extension\InvalidSniffPropertyException on SlevomatCodingStandard\Sniffs\Commenting\ForbiddenCommentsSniff.forbiddenCommentPatterns: ['/^Created by PhpStorm\.$/']
  3. Symfony\Component\DependencyInjection\Exception\RuntimeException: Cannot autowire service "Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer": argument "$lineLengthTransformer" of method "__construct()" references class "Symplify\CodingStandard\TokenRunner\Transformer\FixerTransformer\LineLengthTransformer" but no such service exists. on Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer: ~
  4. And once I had removed all these (leaving basically only PhpCsFixer\* services), it ran successfully but changed the final on my Doctrine Entities (which, I guess, happened for the same reasons as on Rector, see https://github.com/rectorphp/rector/issues/1639) :
12) src/Entity/Task.php

    ---------- begin diff ----------
--- Original
+++ New
@@ -23,7 +23,7 @@
  * @ORM\Table(name="task")
  * @ORM\Entity
  */
-class Task
+final class Task
 {
    ----------- end diff -----------

Applied checkers:
 * PhpCsFixer\Fixer\ClassNotation\FinalClassFixer

Hope it helps in some way (I switched back to my Docker container for now).

TomasVotruba commented 4 years ago

Does it remain with the latest 8f88502 version? There have been some changes

gnutix commented 4 years ago

I downloaded https://github.com/symplify/easy-coding-standard-prefixed/blob/2b45db82bd136f1b43a28f6b86ee5b29fba1fabb/ecs.phar and it still bug on Fatal error: Uncaught Symplify\EasyCodingStandard\Exception\DependencyInjection\Extension\InvalidSniffPropertyException: Checker class "SlevomatCodingStandard\Sniffs\Commenting\ForbiddenCommentsSniff" in configuration was not found in phar:///home/gnutix/dev/.../ecs.phar/src/Yaml/CheckerConfigurationGuardian.php:29.

TomasVotruba commented 4 years ago

Good, that's better error. I'll unscope SlevomatCS Too

Thanks for testing, this is helpful

gubler commented 4 years ago

Sorry, I've been swamped with work and I won't be able to try and build a test until Saturday and even that is a bit questionable.

I will put something together when I can carve out the time.

TomasVotruba commented 4 years ago

@gnutix Slevomat was unscoped now, could you re-try dev-master?

gnutix commented 4 years ago

@TomasVotruba Tried with dev-master. Issues 1 and 2 are resolved, issues 3 and 4 remain.

TomasVotruba commented 4 years ago

These might be unrelated, or can drag for a longer time. Please create 2 new issues.

Ther narrower scope the better