Open vv12131415 opened 5 years ago
There are a couple of sniffs which operate in that area and which may help you:
PSR12.Operators.OperatorSpacing
- will check the spacing before and after assignment operators to be at least 1 space, but will also do so for a lot of other operators. Spacing being wider will be silently ignored.Squiz.WhiteSpace.OperatorSpacing
- will check the spacing before and after assignment operators to be 1 space, but will also do so for a lot of other operators. For "spacing after" it enforces precisely one space, for "spacing before" it will silently ignore wider spacing to allow for alignment.
Whether new lines are allowed is configurable.Generic.Formatting.MultipleStatementAlignment
- will try to align the assignment operators for consecutive lines (spacing before). If consecutive lines do not contain assignments, it expects one space.
The maxPadding
after the operator is configurable.If either of the first two sniffs is what you are looking for, but you want to restrict it to assignment operators, you could extend the sniff and just overload the register()
method to register just and only assignment operators.
You can find an example of how to do that here - in the example, the sniffs adds even more operators: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/WordPress/Sniffs/WhiteSpace/OperatorSpacingSniff.php
Hope this helps.
it would be nice if the first 2 rules would be configurable, something like
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="chop" value="rtrim"/>
<element key="close" value="closedir"/>
</property>
</properties>
</rule>
but the property should be called as, ignoreOperators
and in the elements you will put all the operators that you want to ignore.
Following https://github.com/doctrine/coding-standard/pull/117 I've found that there is a rule to force spaces before
=
(assignment) operator, but no rule for after condition.