squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

--sniffs=PSR1.Classes.ClassDeclaration is no valid #550

Closed sunnyingit closed 9 years ago

sunnyingit commented 9 years ago

vendor/bin/phpcs --standard=PSR2 --sniffs=PSR1.Classes.ClassDeclaration --extensions=php app/models/Weixin.php

the report result is 3 | ERROR | Each class must be in a namespace of at least one level | | (a top-level vendor name)

aik099 commented 9 years ago

Any more detail you can provide?

jian-wu commented 9 years ago

@aik099, I can confirm that the PSR1.Classes.ClassDeclaration sniff cannot be excluded by using the command line --sniffs attribute. However, it can be achieved by using a ruleset override this way.

<rule ref="PSR1">
    <exclude name="PSR1.Classes.ClassDeclaration"/>
</rule>

However, if I don't want to exclude it entirely, it doesn't seem that I can easily lower its severity so it won't get reported. Below ruleset override doesn't take effect.

<rule ref="PSR1.Classes.ClassDeclaration">
    <severity>0</severity>
</rule>

The report still prints this error. Is there anymore specific details you need to get the investigation started?

Thanks.

gsherwood commented 9 years ago

You can't exclude sniffs on the command line. You can only limit the checking to specific sniffs.

And you can't change the severity of an entire sniff. You can only change the severity of individual messages within it (these are 4-part codes instead of the 3-part sniff codes).

jian-wu commented 9 years ago

Ahh, thanks. No wonder I can get this to work.

<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
    <severity>4</severity>
</rule>