-
-
Notifications
You must be signed in to change notification settings - Fork 494
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
Rulesets: lower severity instead of excluding checks #1262
Rulesets: lower severity instead of excluding checks #1262
Conversation
Hard excluding check makes it impossible for a custom ruleset to re-enable a rule. By changing the severity instead, a custom ruleset can up the severity of a check to re-enable it. Note: whether this will work or not depends on the loading order of rules. No guarantees given. The fact that it may not work in certain circumstances, is something which should be addressed upstream.
So: <!-- in WordPress-Core/ruleset.xml -->
<rule ref="PSR2">
<exclude name="PSR2.ControlStructures.SwitchDeclaration.NotLower">
</rule> and <!-- in MyPlugin/.phpcs.xml.dist -->
<rule ref="WordPress"/>
<rule ref="PSR2.ControlStructures.SwitchDeclaration.NotLower"/> wouldn't work (as in, use the whole of PSR2)? |
@GaryJones Correct. Test it if you like. Once this PR is merged, the below, however, should start to work: <!-- in MyPlugin/.phpcs.xml.dist -->
<rule ref="WordPress"/>
<rule ref="PSR2.ControlStructures.SwitchDeclaration.NotLower">
<severity>5</severity>
</rule> |
SetupPHPCS 3.2.0 My test file: <?php
$var = 'string';
switch ($var) {
case 'value': break;
} The relevant bit of my <rule ref="PSR2.ControlStructures">
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BodyOnNextLineCASE"/>
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakNotNewLine"/>
<exclude name="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore"/>
</rule> ControlWith the three TestOverride the first exclusion by adding a change in severity afterwards. Relevant part of <rule ref="PSR2.ControlStructures">
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BodyOnNextLineCASE"/>
<exclude name="PSR2.ControlStructures.SwitchDeclaration.BreakNotNewLine"/>
<exclude name="Squiz.WhiteSpace.ScopeClosingBrace.ContentBefore"/>
</rule>
<rule ref="PSR2.ControlStructures.SwitchDeclaration.BodyOnNextLineCASE">
<severity>5</severity>
</rule> The result is that the Hypothesis
EvidenceRunning ConclusionI'm not sure if the There's a potential argument regarding giving readers of our code a hint as to what they need to do to un-exclude an error code, but equally there's an argument for the exclude being easier to understand for someone who doesn't know (or care) about severity levels. One suggestion (assuming my conclusion is valid): Keep the <!-- Excluded error codes can be un-excluded by changing the severity level. See https://... for more information. --> |
@GaryJones Your conclusion is correct. Including a sniff with Changing the exclusions to severity changes in the ruleset will make it much more intuitive and discoverable to users of custom rulesets how to overrule the exclude. |
So, if I'm understanding this right:
So if a sniff has been excluded, including it again won't cause it to give an error, because the severity will still be But by explicitly changing the severity to So @GaryJones example that doesn't work with the new change, also doesn't work now. I see no downside to this change. It might be nice if PHPCS improves this in the future, but until then I still think this change makes sense. |
As discussed in #1157 with conclusion written up in #1157 (comment) .
Hard excluding individual PHPCS rules makes it impossible for a custom ruleset to re-enable a rule.
By changing the severity instead, a custom ruleset can up the severity of a check to re-enable it.
Note: whether this will work or not depends on the loading order of rules. No guarantees given.
The fact that it may not work in certain circumstances, is something which should be addressed upstream.