Closed MartinMystikJonas closed 2 years ago
If you want some extension to be configurable, please open a feature request at that extension. It's possible to do it with the help of conditionalTags
section in .neon files, like here for example: https://github.com/phpstan/phpstan-src/blob/d866a66f6e43abac86c697f28dc780904dc5399b/conf/config.neon#L380-L390
One example is phpstan-strict-rules. We want to use few of these rules but not entire strict rule set. So I should open issue/PR in phpstan-strict-rules for config value to turn off all rules?
Now I see this issue is already there and closed https://github.com/phpstan/phpstan-strict-rules/issues/150
So if I want to use it with extension loader I should prepare PR and add config to turn or rules?
Yes please :)
Here's an example of a single rule converted to a new config parameter:
diff --git a/rules.neon b/rules.neon
index d70a911..07a7e2a 100644
--- a/rules.neon
+++ b/rules.neon
@@ -14,9 +14,15 @@ parameters:
reportMaybesInPropertyPhpDocTypes: true
featureToggles:
illegalConstructorMethodCall: %featureToggles.bleedingEdge%
+ strictRules:
+ booleansInConditions: true
+
+parametersSchema:
+ strictRules: structure([
+ booleansInConditions: bool()
+ ])
rules:
- - PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule
- PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule
- PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule
- PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule
@@ -55,6 +61,8 @@ rules:
conditionalTags:
PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule:
phpstan.rules.rule: %featureToggles.bleedingEdge%
+ PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule:
+ phpstan.rules.rule: %strictRules.booleansInConditions%
services:
-
@@ -78,3 +86,6 @@ services:
-
class: PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule
+
+ -
+ class: PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule
So this would allow to disable rules one by one. Would it be possible to add another config value to turn off all strict rules unless explicitly enabled? It might be more convenient for people that wants to use just few rules.
There could be a "turn-off-all-rules.neon" file in the repo.
@ondrejmirtes Would this be valid approach to configuration too?
strictRules:
enabled: true
booleansInConditions: %strictRules.enabled%
cast: %strictRules.enabled%
classes: %strictRules.enabled%
disallowedConstructs: %strictRules.enabled%
foreachLoop: %strictRules.enabled%
forLoop: %strictRules.enabled%
functions: %strictRules.enabled%
methods: %strictRules.enabled%
operators: %strictRules.enabled%
strictCalls: %strictRules.enabled%
switchConditions: %strictRules.enabled%
variableVariables: %strictRules.enabled%
All rules would be disabled by
strictRules:
enabled: false
and the rules could be enabled either by configs:
strictRules:
enabled: false
booleansInConditions: true
or by manually adding rules/services.
PR ready here: https://github.com/phpstan/phpstan-strict-rules/pull/182
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
In our setup we use just few handpicked rules from some opinionated extensions. When we use extension installer all rules from these extensions are included. It would ne nice to have option to disable loading of certain extensions.