deprecated-packages / symplify

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

[ECS] Possibility to change phpcs sub-rules severity? #667

Closed OndraM closed 6 years ago

OndraM commented 6 years ago

Hi Tomas once again 😳, in our ruleset.xml for PHP_CodeSniffer we apply some sniffs (like Generic.Commenting.DocComment), and then explicitly disable some of its rules (eg. Generic.Commenting.DocComment.ContentAfterOpen) by setting their severity to 0, so that we effectively use only part of the parent sniff. Is it possible to achieve something like this via the ECS configuration?

<!-- ruleset.xml -->

    <rule ref="Generic.Commenting.DocComment"/>
    <rule ref="Generic.Commenting.DocComment.ContentAfterOpen">
        <severity>0</severity>
    </rule>
    <rule ref="Generic.Commenting.DocComment.ContentBeforeClose">
        <severity>0</severity>
    </rule>
TomasVotruba commented 6 years ago

Hey Ondra,

severity can be replaced better way in imports.

More broad sets are included in more strict ones, see for e.g.:

OndraM commented 6 years ago

I may not understand, but how to set severity only for one type of error of one sniff, as in the example above? I didn't find anything similar in the referenced configs :-/

TomasVotruba commented 6 years ago

There is no such feature as severity in ECS. Code is either checked or not. Using severity levels and warning made simple thing complicated.

Use classic Symfony approach with yaml imports instead:

# simple-config.yml
services:
    SomeFixer: ~
# strict-config.yml
imports:
    { resource: 'simple-config.yml' }

services:
    CommentFixer: ~

Basically:

# instead of vendor/bin/phpcs ... --severity=0
vendor/bin/ecs check /src --config simple-config.yml

# instead of vendor/bin/phpcs ...
vendor/bin/ecs check /src --config strict-config.yml
TomasVotruba commented 6 years ago

Some more context...

OndraM commented 6 years ago

I think we still don't understand each other :)). Setting severity to zero is just a way how to skip some codes in PHP_CS config, which is what I want - I don't need actually the severity at all.

So I was actually talking about a way how ti ignore specific error code from the sniff, but keeping rest of the sniff active. I thought you can in ECS skip only whole sniffs or files, but you can ignore also the code from sniffs. So this looks great :tada: . Sorry I overlooked this initially :).

TomasVotruba commented 6 years ago

Oh. I README is recommended to read before use ;)

Good to know. I'll ask for the need next time, rather than code.