-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[4.0.0] Excluding/severity 0 should not load a rule #3894
Comments
@kkmuffme Thank you for creating this issue. This is, however, not a bug, but a feature request. In my opinion, if someone is willing to work on this, I think it may be a nice candidate for the 4.0 release, though things are not as simple as posed in the description.
Well, there is a difference between those two types of "excluding", which in my mind, explains/justifies the current behaviour. When With a When a severity change is made for an individual error code, PHPCS has no awareness of whether the sniff has only one error code or multiple, so will need to include the sniff anyway and handle the severity change at the point of throwing an error/warning. When a severity change is made for a complete sniff, category or standard, that is different and not loading the sniff would become an option, but that would only be possible if the ruleset processing is changed significantly. Currently, a ruleset is read top-to-bottom and processed as such as well. That means that each directive is read and then processed, before the next directive is read, i.e. the sniffs will be loaded once the directive including them is read. So: <rule ref="PSR1">
<exclude name="Generic"/>
<exclude name="Squiz.Classes.ValidClassName"/>
</rule> ... will read the While: <rule ref="PSR1"/>
<rule ref="PSR1.Classes.ClassDeclaration">
<severity>0</severity>
</rule> ... will first read the To make the change you are proposing, the ruleset would need to be read and interpreted completely first and only after the complete ruleset has been interpreted, sniffs should be loaded. As this is a significant change in how the ruleset is handled, which may have unforeseen consequences/side-effects, making this change in the 3.x series is not an option (IMO) and significant testing would need to be done (and unit tests written) to accept a change as proposed here for 4.0. I'm leaving this open for now in case anyone is interested in working on this. I do think this is an interesting proposal though, as this could have significant (positive) impact on the performance of PHPCS. As for the following:
You may want to run PHPCS with |
Yes, looks like it. Which means the config won't load any rules that have a severity below 5/8
The problem is that not all errors fall in the "deprecated" category, as especially PHP 8 has a couple new errors thrown where PHP 7 returned false instead, and snoozing those would potentially mask bugs/issues that need to be investigated. |
Describe the bug
Excluding a rule/setting severity 0, should NOT load the rule, if it hasn't been loaded yet.
To reproduce
exclude any rule in any ruleset.
Run with "-vv"
and see
Expected behavior
No processing of the rule.
Versions (please complete the following information)
PHP_CodeSniffer version 3.7.2 and before
Additional context
Just like phpcs-only/phpcbf-only="true" will not process the specified rule, excluding the rule shouldn't either.
This is important, because sometimes you want to use an external ruleset, where some rules don't work (loading them will throw PHP notices with your/newer PHP versions) or are slowing down phpcs a lot.
Currently the only way to do that is to copy the whole ruleset instead and not include those buggy rules, which creates bloated, hard to maintain code.
Please confirm:
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: