Skip to content

Generic/IncrementDecrementSpacing: handle more situations#46

Merged
jrfnl merged 1 commit intomasterfrom
feature/generic-incrementdecrementspacing-handle-more-cases
Dec 5, 2023
Merged

Generic/IncrementDecrementSpacing: handle more situations#46
jrfnl merged 1 commit intomasterfrom
feature/generic-incrementdecrementspacing-handle-more-cases

Conversation

@jrfnl
Copy link
Copy Markdown
Member

@jrfnl jrfnl commented Nov 9, 2023

Description

Recreation of upstream PR squizlabs/PHP_CodeSniffer#3626:

The Generic.WhiteSpace.IncrementDecrementSpacing sniff, so far, only handled incrementors/decrementors when they were directly before/after the variable they apply to.

This commit enhances the sniff to also allow for finding superfluous whitespace when incrementing/decrementing a property or an array item.

Includes unit tests.

Note: I've only made this change for PHP files as JS support will be dropped anyway, so it didn't feel like a good use of my time to work on that.

Suggested changelog entry

Generic/IncrementDecrementSpacing: detect spacing issues for more complex variables


From the conversation in the original issue:

For pre-increment, I can think of a further/future iteration for the sniff - checking whether a pre-increment is used on a static property with a fully qualified classname or namespace relative classname, but that is something I choose not to handle (yet) when I made this change last year. When that change would be added, then, yes, extra tests would be needed for pre-in/decrement.

++\ClassName::$prop;
++Relative\ClassName::$prop;
--namespace\Relative\ClassName::$prop;

The reason I did not make that change (yet) is that this would need a different patch for PHPCS 3.x vs PHPCS 4.x, which would make the merge more complex. Also see squizlabs/PHP_CodeSniffer#3041.

@jrfnl jrfnl added this to the 3.8.0 milestone Nov 9, 2023
@jrfnl jrfnl force-pushed the feature/generic-incrementdecrementspacing-handle-more-cases branch from 1a53ad2 to 3b44475 Compare November 11, 2023 03:30
The `Generic.WhiteSpace.IncrementDecrementSpacing` sniff, so far, only handled incrementors/decrementors when they were directly before/after the variable they apply to.

This commit enhances the sniff to also allow for finding superfluous whitespace when incrementing/decrementing a property or an array item.

Includes unit tests.
@jrfnl jrfnl force-pushed the feature/generic-incrementdecrementspacing-handle-more-cases branch from 3b44475 to ad5421c Compare December 5, 2023 15:23
@jrfnl jrfnl merged commit 4aafcb3 into master Dec 5, 2023
@jrfnl jrfnl deleted the feature/generic-incrementdecrementspacing-handle-more-cases branch December 5, 2023 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant