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

Generic/ArbitraryParenthesesSpacing: improve handling of switch-case scope closers #296

Merged
merged 1 commit into from
Jan 25, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jan 20, 2024

Description

Follow up on squizlabs/PHP_CodeSniffer#2826 which was fixed via squizlabs/PHP_CodeSniffer#2876.

The sniff explicitly only intends to handle arbitrary parentheses and tries to avoid clashes with sniffs handling the parentheses spacing of function calls and language construct invocations.

This is done by the sniff bowing out early when the token before the open parenthesis is a token which can be used in a (variable) function call or one of a select list of reserved keywords.

The previous PR tweaked the "bowing out" to allow the sniff to operate on arbitrary parentheses which directly follow the close curly brace of a a previous scope.

The additional condition added was, however, not limited to T_CLOSE_CURLY_BRACKET tokens.

This has led to a new false positive: When a die()/exit() is used within a switch-case statement, the die/exit keyword will be regarded as a scope closer for the case statement, in which case, the parentheses for the die/exit would now be treated as arbitrary instead of as belonging to the die/exit keyword.

This commit fixes this by limiting the previously introduced check for a scope closer to curly braces only.

Includes tests proving the bug and safeguarding the fix.

Suggested changelog entry

  • Generic/ArbitraryParenthesesSpacing : false positive for non-arbitrary parentheses when these follow the scope closer of a switch case.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

…scope closers

Follow up on squizlabs/PHP_CodeSniffer 2826 which was fixed via squizlabs/PHP_CodeSniffer 2876.

The sniff explicitly only intends to handle _arbitrary_ parentheses and tries to avoid clashes with sniffs handling the parentheses spacing of function calls and language construct invocations.

This is done by the sniff bowing out early when the token before the open parenthesis is a token which can be used in a (variable) function call or one of a select list of reserved keywords.

The previous PR tweaked the "bowing out" to allow the sniff to operate on arbitrary parentheses which directly follow the close curly brace of a a previous scope.

The additional condition added was, however, not limited to `T_CLOSE_CURLY_BRACKET` tokens.

This has led to a new false positive: When a `die()`/`exit()` is used within a `switch-case` statement, the `die`/`exit` keyword will be regarded as a scope closer for the `case` statement, in which case, the parentheses for the `die`/`exit` would now be treated as arbitrary instead of as belonging to the `die`/`exit` keyword.

This commit fixes this by limiting the previously introduced check for a scope closer to curly braces only.

Includes tests proving the bug and safeguarding the fix.
@jrfnl
Copy link
Member Author

jrfnl commented Jan 25, 2024

Rebased without changes to be sure. Merging once the build passes.

@jrfnl jrfnl force-pushed the feature/generic-arbitraryparenthesesspacing-bugfix branch from 1fee8d7 to 3527d83 Compare January 25, 2024 16:36
@jrfnl jrfnl merged commit 68bb4dc into master Jan 25, 2024
44 checks passed
@jrfnl jrfnl deleted the feature/generic-arbitraryparenthesesspacing-bugfix branch January 25, 2024 16:42
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