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/ArrayIndent: improve code coverage and implement a few small improvements to the sniff code #487

Merged
merged 3 commits into from
May 14, 2024

Commits on May 14, 2024

  1. Generic/ArrayIndent: remove T_COMMA from list of tokens to ignore

    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
    rodrigoprimo authored and jrfnl committed May 14, 2024
    Configuration menu
    Copy the full SHA
    29b7411 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    d74b846 View commit details
    Browse the repository at this point in the history
  3. Generic/ArrayIndent: avoid extra calls to ArrayIndent::processMultiLi…

    …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.
    rodrigoprimo authored and jrfnl committed May 14, 2024
    Configuration menu
    Copy the full SHA
    3a2230c View commit details
    Browse the repository at this point in the history