-
-
Notifications
You must be signed in to change notification settings - Fork 56
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/ArrayIndent: improve code coverage and implement a few small improvements to the sniff code #487
Generic/ArrayIndent: improve code coverage and implement a few small improvements to the sniff code #487
Conversation
This change confuses me more. I mean, the |
12645d7
to
906f7a2
Compare
Thanks for checking this PR, @jrfnl.
Good point about using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks @rodrigoprimo !
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
…neArray() This commit fixes a small inefficiency when fixing the `CloseBraceNotNewLine` error. Previously, the sniff would add the newline and the number of spaces used for an array element (which is more than what should be used for the array closing brace). Then on a subsequent call to processMultiLineArray(), it would detect the wrong number of spaces for the closing brace and it would fix it. Now, the sniff will use the correct number of spaces when adding the newline.
906f7a2
to
3a2230c
Compare
Rebased without changes. Merging once the builds passes. |
Description
This PR improves the code coverage of the
Generic.Arrays.ArrayIndent
sniff and also implements the following minor improvements to the sniff code:Use two different variables to hold the values of the expected indentation for array elements and array closing brace. Before, the same variable was being used, and its value modified, which can be confusing.T_COMMA
from the list of tokens to ignore when looking for a token before the array opening brace. This was necessary in the past due to a bugFile::findStartOfStatement()
that has since been fixed.I believe
T_DOUBLE_ARROW
can be removed from the list as well. WithT_COMMA
, I could confirm that when this token was added to the ignore list, the provided test would fail without it. The test started passing when a bug inFile::findStartOfStatement()
was fixed.I was not able to do the same with
T_DOUBLE_ARROW
. This token was added to the list in 0425342. All the tests pass if I run PHPCS in the 0425342 revision without theT_DOUBLE_ARROW
token.Related issues/external references
Part of #146
Types of changes
PR checklist