squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

No sniff to force spaces after `=` (assignment) operator #2425

Open vv12131415 opened 5 years ago

vv12131415 commented 5 years ago

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.

jrfnl commented 5 years ago

There are a couple of sniffs which operate in that area and which may help you:

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.

vv12131415 commented 5 years ago

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.