Repository navigation
Allow rules to be enabled and disabled individually - #374
Conversation
Add `phpunit.allRules` and one parameter per rule, following the convention established by phpstan/phpstan-strict-rules. All rules in rules.neon are now services tagged through conditionalTags, so `allRules: false` disables every rule and single rules can be turned back on by name. Default behaviour is unchanged: the Bleeding Edge and strictRulesInstalled conditions moved into the parameter defaults.
|
I'm not sure about it, but I think one time ondrej said he wanted to deprecate the option to select rules one by one on phpstan-strict-rules. |
I really like the elegance of this approach: I can start using an extension, disable all of its rules by default, and enable them one by one over time (or don't). I would really miss this functionality would it be removed from extensions that already support this. |
|
Found the post #339 (comment) But I let ondrej chose on this |
|
I was prepared to say the same thing: that the strict rules config approach predates being able to ignore errors cleanly by error identifier. But it looks like you actually like this approach even after identifiers. So I'll merge this and no longer plan to remove this possibility from strict-rules and here. |
|
Thank you. |
Thank you! |
Motivation
rules.neonis currently all or nothing. Nine rules are registered unconditionally underrules:, two more are tagged directly as services, and the remaining five are only gated on Bleeding Edge (and, for two of them, onphpstan-strict-rules). A project that wants some of the rules but not all of them has to leaverules.neonout and cherry-pick rule classes by hand. That means copying the service definitions of the rules that take constructor arguments, and it silently misses every rule added in a later release.phpstan/phpstan-strict-rulessolved this withstrictRules.allRulesplus one parameter per rule, andergebnis/phpstan-rulesandshipmonk/phpstan-rulesfollow the same idea. This pull request brings that convention tophpstan-phpunit.The discussion that led here is in sebastianbergmann/phpunit#7195 (comment): PHPUnit wants the type inference of this extension for its own test suite and wants to adopt the rules one at a time.
Usage
Disable a single rule:
Enable only selected rules:
Changes
extension.neongainsphpunit.allRules(defaulttrue) and one parameter per rule, named after the rule class without theRulesuffix (ClassCoversExistsRulebecomesclassCoversExists). Each one defaults to%phpunit.allRules%.rules.neonno longer has arules:section. Every rule is a service and gets thephpstan.rules.ruletag throughconditionalTagsfrom its own parameter.RuleTogglesTestcovers the configuration (see below).No PHP source in
src/changes.Backward compatibility
Default behaviour is unchanged. The Bleeding Edge and
strictRulesInstalledconditions moved fromconditionalTagsinto the parameter defaults, the same wayphpstan-strict-rulesdoes it forbooleansInLoopConditions:The set of enabled rules is therefore the same as before for all three combinations (plain, Bleeding Edge, Bleeding Edge with
phpstan-strict-rules), and the tests assert each of them.One thing is new and intended: setting such a parameter to
truereplaces the list, so the rule can be enabled explicitly without Bleeding Edge orphpstan-strict-rules.