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

New Generic.WhiteSpace.IncrementDecrementSpacing sniff #2174

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Oct 1, 2018

New sniff to check that there are no spaces (or comments) between an incrementor/decrementor and the variable it applies to.

The sniff can examine both PHP as well as JS files for this, though I suspect there may be some false positive reports for JS at some point as T_STRING is quite a generic token to check for.

Includes unit tests.
Includes auto-fixer.
Includes code-consistency metrics.

I've made a conscious decision to not make the number of spaces accepted between the in/decrementor and the variable configurable as it is a widely accepted convention that there should be no spaces between them.
If it would be so desired, I can add a public property to make this configurable.

Fixes #2172

New sniff to check that there are no spaces (or comments) between an incrementor/decrementor and the variable it applies to.

The sniff can examine both PHP as well as JS files for this, though I suspect there may be some false positive reports for JS at some point as `T_STRING` is quite a generic token to check for.

Includes unit tests.
Includes auto-fixer.
Includes code-consistency metrics.

I've made a conscious decision to not make the number of spaces accepted between the in/decrementor and the variable configurable as it is a widely accepted convention that there should be no spaces between them.
If it would be so desired, I can add a public property to make this configurable.

Fixes 2172
@gsherwood gsherwood added this to the 3.4.0 milestone Oct 2, 2018
@jrfnl
Copy link
Contributor Author

jrfnl commented Oct 9, 2018

This sniff should probably be added to the PSR12 ruleset (in due time) as - in part inspired by this sniff -, a rule to that effect has now been added to the draft PSR12: php-fig/fig-standards#1089

@gsherwood gsherwood merged commit 1e1edb2 into squizlabs:master Oct 23, 2018
gsherwood added a commit that referenced this pull request Oct 23, 2018
@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
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

Feature suggestion: sniff to check whitespace around incrementors/decrementors
2 participants