While working on something else, I suddenly realized that there is no sniff to check the whitespace before/after incrementors/decrementors.
$i = 10;
--$i; // This is what would be valid.
-- $i; // This should be flagged and fixed.
-- /*comment*/ $i; // This should just be flagged.
$i++; // This is what would be valid.
$i ++; // This should be flagged and fixed.
$i /*comment*/ ++; // This should just be flagged.
I realize it is rare to encounter such code, but it is perfectly valid PHP code and PHP will just ignore the whitespace and comments and function as expected.
I haven't (yet) checked if there are any other sniffs which would get confused by this, but running the above code samples against all the included standards in PHPCS itself, doesn't throw any unexpected false positive/negatives.
@gsherwood Do you think its a good idea to add a new sniff for this ? I'm thinking Generic.WhiteSpace.IncrementDecrementSpacing.
And if so, should it be added to any of the existing rulesets ?
While working on something else, I suddenly realized that there is no sniff to check the whitespace before/after incrementors/decrementors.
I realize it is rare to encounter such code, but it is perfectly valid PHP code and PHP will just ignore the whitespace and comments and function as expected.
I haven't (yet) checked if there are any other sniffs which would get confused by this, but running the above code samples against all the included standards in PHPCS itself, doesn't throw any unexpected false positive/negatives.
@gsherwood Do you think its a good idea to add a new sniff for this ? I'm thinking
Generic.WhiteSpace.IncrementDecrementSpacing
. And if so, should it be added to any of the existing rulesets ?I'd be happy to create the sniff.