-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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.Arrays.ArrayIndent has conflicting logic #3100
Comments
rodrigoprimo
added a commit
to rodrigoprimo/PHP_CodeSniffer
that referenced
this issue
May 9, 2024
This commit removes T_COMMA from a list of tokens to ignore when searching for the non-empty token before the start of the array. T_COMMA was added to this list in 1697fac to fix a bug. See squizlabs/PHP_CodeSniffer#3100 for more details. Back when this fix was introduced, it was necessary to ignore commas due to a bug in findStartOfStatement() that would cause this method to return the wrong token when passed the last token in a statement. This bug has been fixed afterwards in ef80e53 and ignoring commas is not necessary anymore. Now, the call to findStartOfStatement() in https://github.com/squizlabs/PHP_CodeSniffer/blob/4cf6badaf0c177acaf295e2178f4383e2ea71b20/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php#L67 correctly finds the start of the statement when passed the comma that marks the end of the statement. A test was added 1697fac. It would fail if running an older version of PHPCS without ignoring commas, but now it passes: https://github.com/squizlabs/PHP_CodeSniffer/pull/3101/files#diff-f786a9f6c41b82204dc89de2c02437c0e44401d580b02fcbde6278ea03f25693R83-R90
jrfnl
pushed a commit
to rodrigoprimo/PHP_CodeSniffer
that referenced
this issue
May 14, 2024
This commit removes T_COMMA from a list of tokens to ignore when searching for the non-empty token before the start of the array. T_COMMA was added to this list in 1697fac to fix a bug. See squizlabs/PHP_CodeSniffer#3100 for more details. Back when this fix was introduced, it was necessary to ignore commas due to a bug in findStartOfStatement() that would cause this method to return the wrong token when passed the last token in a statement. This bug has been fixed afterwards in ef80e53 and ignoring commas is not necessary anymore. Now, the call to findStartOfStatement() in https://github.com/squizlabs/PHP_CodeSniffer/blob/4cf6badaf0c177acaf295e2178f4383e2ea71b20/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php#L67 correctly finds the start of the statement when passed the comma that marks the end of the statement. A test was added 1697fac. It would fail if running an older version of PHPCS without ignoring commas, but now it passes: https://github.com/squizlabs/PHP_CodeSniffer/pull/3101/files#diff-f786a9f6c41b82204dc89de2c02437c0e44401d580b02fcbde6278ea03f25693R83-R90
jrfnl
pushed a commit
to PHPCSStandards/PHP_CodeSniffer
that referenced
this issue
May 14, 2024
This commit removes T_COMMA from a list of tokens to ignore when searching for the non-empty token before the start of the array. T_COMMA was added to this list in 1697fac to fix a bug. See squizlabs/PHP_CodeSniffer#3100 for more details. Back when this fix was introduced, it was necessary to ignore commas due to a bug in findStartOfStatement() that would cause this method to return the wrong token when passed the last token in a statement. This bug has been fixed afterwards in ef80e53 and ignoring commas is not necessary anymore. Now, the call to findStartOfStatement() in https://github.com/squizlabs/PHP_CodeSniffer/blob/4cf6badaf0c177acaf295e2178f4383e2ea71b20/src/Standards/Generic/Sniffs/Arrays/ArrayIndentSniff.php#L67 correctly finds the start of the statement when passed the comma that marks the end of the statement. A test was added 1697fac. It would fail if running an older version of PHPCS without ignoring commas, but now it passes: https://github.com/squizlabs/PHP_CodeSniffer/pull/3101/files#diff-f786a9f6c41b82204dc89de2c02437c0e44401d580b02fcbde6278ea03f25693R83-R90
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
The fix for #2882 (0425342) introduces conflicting logic in the
Generic.Arrays.ArrayIndent
sniff.Code sample
Custom ruleset
None
To reproduce
Steps to reproduce the behavior:
phpcs -s --standard=Squiz --sniffs=Generic.Arrays.ArrayIndent test.php
:phpcs -s --standard=Squiz --sniffs=Generic.Arrays.ArrayIndent test.php
:phpcbf --standard=Squiz --sniffs=Generic.Arrays.ArrayIndent test.php
:Expected behavior
There's no conflict, and the file is auto-fixed.
Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: