Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature suggestion: sniff to check whitespace around incrementors/decrementors #2172

Closed
jrfnl opened this issue Sep 29, 2018 · 1 comment · Fixed by #2174
Closed

Feature suggestion: sniff to check whitespace around incrementors/decrementors #2172

jrfnl opened this issue Sep 29, 2018 · 1 comment · Fixed by #2174

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Sep 29, 2018

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 ?

I'd be happy to create the sniff.

@gsherwood
Copy link
Member

Thanks a lot for this. I've added it to the Squiz and PHPCS standards as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging a pull request may close this issue.

2 participants