Skip to content

Commit

Permalink
Configuration parameters to enable/disable rules
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMystikJonas authored and ondrejmirtes committed Aug 23, 2022
1 parent 6ec8ce7 commit f120c3b
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 48 deletions.
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ includes:
```
</details>

## Disabling rules

You can disable rules using configuration parameters:

```neon
parameters:
strictRules:
booleansInConditions: false
uselessCast: false
requireParentConstructorCall: false
disallowedConstructs: false
overwriteVariablesWithLoop: false
closureUsesThis: false
matchingInheritedMethodNames: false
numericOperandsInArithmeticOperators: false
strictCalls: false
switchConditionsMatchingType: false
noVariableVariables: false
```

## Enabling rules one-by-one

Expand All @@ -79,13 +98,19 @@ services:

### With extension-installer

Unfortunately, by using `phpstan/extension-installer` you can't enable it one by one, ***but you can [ignore specific errors](https://phpstan.org/user-guide/ignoring-errors) instead***.
When using `phpstan/extension-installer` you can disable automatic loading of all rules by:

```neon
parameters:
strictRules:
allRules: false
```

For example:
Then you can enable individual rules by adding them as services just like without extension-installer (see above) or re-enable them by configuration parameters:

```neon
parameters:
ignoreErrors:
- '#Construct empty\(\) is not allowed. Use more strict comparison.#'
- '#Call to function in_array\(\) requires parameter \#3 to be set.#'
strictRules:
allRules: false
booleansInConditions: true
```
253 changes: 210 additions & 43 deletions rules.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,59 +14,116 @@ parameters:
reportMaybesInPropertyPhpDocTypes: true
featureToggles:
illegalConstructorMethodCall: %featureToggles.bleedingEdge%
strictRules:
allRules: true
booleansInConditions: %strictRules.allRules%
uselessCast: %strictRules.allRules%
requireParentConstructorCall: %strictRules.allRules%
disallowedConstructs: %strictRules.allRules%
overwriteVariablesWithLoop: %strictRules.allRules%
closureUsesThis: %strictRules.allRules%
matchingInheritedMethodNames: %strictRules.allRules%
numericOperandsInArithmeticOperators: %strictRules.allRules%
strictCalls: %strictRules.allRules%
switchConditionsMatchingType: %strictRules.allRules%
noVariableVariables: %strictRules.allRules%

rules:
- PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule
- PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule
- PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule
- PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule
- PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule
- PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule
- PHPStan\Rules\Classes\RequireParentConstructCallRule
- PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule
- PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule
- PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule
- PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule
- PHPStan\Rules\ForeachLoop\OverwriteVariablesWithForeachRule
- PHPStan\Rules\ForLoop\OverwriteVariablesWithForLoopInitRule
- PHPStan\Rules\Functions\ClosureUsesThisRule
- PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule
- PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule
- PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule
- PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule
- PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule
- PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule
- PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule
- PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule
- PHPStan\Rules\Operators\OperandsInArithmeticModuloRule
- PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule
- PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule
- PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsRule
- PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsCallableRule
- PHPStan\Rules\StrictCalls\StrictFunctionCallsRule
- PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule
- PHPStan\Rules\VariableVariables\VariableMethodCallRule
- PHPStan\Rules\VariableVariables\VariableMethodCallableRule
- PHPStan\Rules\VariableVariables\VariableStaticMethodCallRule
- PHPStan\Rules\VariableVariables\VariableStaticMethodCallableRule
- PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule
- PHPStan\Rules\VariableVariables\VariableVariablesRule
parametersSchema:
strictRules: structure([
allRules: bool(),
booleansInConditions: bool()
uselessCast: bool()
requireParentConstructorCall: bool()
disallowedConstructs: bool()
overwriteVariablesWithLoop: bool()
closureUsesThis: bool()
matchingInheritedMethodNames: bool()
numericOperandsInArithmeticOperators: bool()
strictCalls: bool()
switchConditionsMatchingType: bool()
noVariableVariables: bool()
])

conditionalTags:
PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule:
phpstan.rules.rule: %featureToggles.bleedingEdge%
PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule:
phpstan.rules.rule: %strictRules.booleansInConditions%
PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule:
phpstan.rules.rule: %strictRules.booleansInConditions%
PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule:
phpstan.rules.rule: %strictRules.booleansInConditions%
PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule:
phpstan.rules.rule: %strictRules.booleansInConditions%
PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule:
phpstan.rules.rule: %strictRules.booleansInConditions%
PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule:
phpstan.rules.rule: %strictRules.booleansInConditions%
PHPStan\Rules\Cast\UselessCastRule:
phpstan.rules.rule: %strictRules.uselessCast%
PHPStan\Rules\Classes\RequireParentConstructCallRule:
phpstan.rules.rule: %strictRules.requireParentConstructorCall%
PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule:
phpstan.rules.rule: %strictRules.disallowedConstructs%
PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule:
phpstan.rules.rule: %strictRules.disallowedConstructs%
PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule:
phpstan.rules.rule: %strictRules.disallowedConstructs%
PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule:
phpstan.rules.rule: %strictRules.disallowedConstructs%
PHPStan\Rules\ForeachLoop\OverwriteVariablesWithForeachRule:
phpstan.rules.rule: %strictRules.overwriteVariablesWithLoop%
PHPStan\Rules\ForLoop\OverwriteVariablesWithForLoopInitRule:
phpstan.rules.rule: %strictRules.overwriteVariablesWithLoop%
PHPStan\Rules\Functions\ClosureUsesThisRule:
phpstan.rules.rule: %strictRules.closureUsesThis%
PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule:
phpstan.rules.rule: %strictRules.matchingInheritedMethodNames%
PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandsInArithmeticModuloRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule:
phpstan.rules.rule: %strictRules.numericOperandsInArithmeticOperators%
PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsRule:
phpstan.rules.rule: %strictRules.strictCalls%
PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsCallableRule:
phpstan.rules.rule: %strictRules.strictCalls%
PHPStan\Rules\StrictCalls\StrictFunctionCallsRule:
phpstan.rules.rule: %strictRules.strictCalls%
PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule:
phpstan.rules.rule: %strictRules.switchConditionsMatchingType%
PHPStan\Rules\VariableVariables\VariableMethodCallRule:
phpstan.rules.rule: %strictRules.noVariableVariables%
PHPStan\Rules\VariableVariables\VariableMethodCallableRule:
phpstan.rules.rule: %strictRules.noVariableVariables%
PHPStan\Rules\VariableVariables\VariableStaticMethodCallRule:
phpstan.rules.rule: %strictRules.noVariableVariables%
PHPStan\Rules\VariableVariables\VariableStaticMethodCallableRule:
phpstan.rules.rule: %strictRules.noVariableVariables%
PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule:
phpstan.rules.rule: %strictRules.noVariableVariables%
PHPStan\Rules\VariableVariables\VariableVariablesRule:
phpstan.rules.rule: %strictRules.noVariableVariables%

services:
-
class: PHPStan\Rules\BooleansInConditions\BooleanRuleHelper

-
class: PHPStan\Rules\Cast\UselessCastRule
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%
tags:
- phpstan.rules.rule

-
class: PHPStan\Rules\Operators\OperatorRuleHelper
-
Expand All @@ -78,3 +135,113 @@ services:

-
class: PHPStan\Rules\DisallowedConstructs\DisallowedLooseComparisonRule

-
class: PHPStan\Rules\BooleansInConditions\BooleanInBooleanAndRule

-
class: PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule

-
class: PHPStan\Rules\BooleansInConditions\BooleanInBooleanOrRule

-
class: PHPStan\Rules\BooleansInConditions\BooleanInElseIfConditionRule

-
class: PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule

-
class: PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule

-
class: PHPStan\Rules\Cast\UselessCastRule
arguments:
treatPhpDocTypesAsCertain: %treatPhpDocTypesAsCertain%

-
class: PHPStan\Rules\Classes\RequireParentConstructCallRule

-
class: PHPStan\Rules\DisallowedConstructs\DisallowedBacktickRule

-
class: PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule

-
class: PHPStan\Rules\DisallowedConstructs\DisallowedImplicitArrayCreationRule

-
class: PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule

-
class: PHPStan\Rules\ForeachLoop\OverwriteVariablesWithForeachRule

-
class: PHPStan\Rules\ForLoop\OverwriteVariablesWithForLoopInitRule

-
class: PHPStan\Rules\Functions\ClosureUsesThisRule

-
class: PHPStan\Rules\Methods\WrongCaseOfInheritedMethodRule

-
class: PHPStan\Rules\Operators\OperandInArithmeticPostDecrementRule

-
class: PHPStan\Rules\Operators\OperandInArithmeticPostIncrementRule

-
class: PHPStan\Rules\Operators\OperandInArithmeticPreDecrementRule

-
class: PHPStan\Rules\Operators\OperandInArithmeticPreIncrementRule

-
class: PHPStan\Rules\Operators\OperandsInArithmeticAdditionRule

-
class: PHPStan\Rules\Operators\OperandsInArithmeticDivisionRule

-
class: PHPStan\Rules\Operators\OperandsInArithmeticExponentiationRule

-
class: PHPStan\Rules\Operators\OperandsInArithmeticModuloRule

-
class: PHPStan\Rules\Operators\OperandsInArithmeticMultiplicationRule

-
class: PHPStan\Rules\Operators\OperandsInArithmeticSubtractionRule

-
class: PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsRule

-
class: PHPStan\Rules\StrictCalls\DynamicCallOnStaticMethodsCallableRule

-
class: PHPStan\Rules\StrictCalls\StrictFunctionCallsRule

-
class: PHPStan\Rules\SwitchConditions\MatchingTypeInSwitchCaseConditionRule

-
class: PHPStan\Rules\VariableVariables\VariableMethodCallRule

-
class: PHPStan\Rules\VariableVariables\VariableMethodCallableRule

-
class: PHPStan\Rules\VariableVariables\VariableStaticMethodCallRule

-
class: PHPStan\Rules\VariableVariables\VariableStaticMethodCallableRule

-
class: PHPStan\Rules\VariableVariables\VariableStaticPropertyFetchRule

-
class: PHPStan\Rules\VariableVariables\VariableVariablesRule

0 comments on commit f120c3b

Please sign in to comment.