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

Universal/PrecisionAlignment: bug fix - improved handling of heredoc/nowdoc closers #124

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 29, 2022

This commit fixes two bugs:

  1. When a heredoc/nowdoc closer (PHP 7.3+ flexible syntax) is indented with tabs, PHPCS does not replace tabs with spaces in the token.
    This means the token 'length' key will also be tab-based, which leads to incorrrect calculations and false positives with incorrect fixes.
    Fixed now by handling tab replacement in heredoc/nowdoc closer tokens in the sniff itself.
  2. A heredoc/nowdoc closer using flexible syntax is not allowed to have a larger indent than any of the content of the heredoc/nowdoc. Doing so results in a parse error.
    With the "best guess" rounding of the indent, the sniff had a risk of introducing these kind of parse errors.
    Fixed now by always rounding the expected indent down to the nearest tabstop for these tokens.

Includes additional unit tests to cover the changes.

…/nowdoc closers

This commit fixes two bugs:
1. When a heredoc/nowdoc closer (PHP 7.3+ flexible syntax) is indented with tabs, PHPCS does not replace tabs with spaces in the token.
    This means the token `'length'` key will also be tab-based, which leads to incorrrect calculations and false positives with incorrect fixes.
    Fixed now by handling tab replacement in heredoc/nowdoc closer tokens in the sniff itself.
2. A heredoc/nowdoc closer using flexible syntax is not allowed to have a larger indent than any of the content of the heredoc/nowdoc. Doing so results in a parse error.
    With the "best guess" rounding of the indent, the sniff had a risk of introducing these kind of parse errors.
    Fixed now by always rounding the expected indent down to the nearest tabstop for these tokens.

Includes additional unit tests to cover the changes.
@jrfnl jrfnl added this to the 1.0.0-alpha4 milestone Jul 29, 2022
@jrfnl jrfnl merged commit 82daa02 into develop Jul 29, 2022
@jrfnl jrfnl deleted the universal/whitespace-precisionalignment-bugfix-flexible-heredoc-nowdoc branch July 29, 2022 14:21
@jrfnl jrfnl changed the title WhiteSpace/PrecisionAlignment: bug fix - improved handling of heredoc/nowdoc closers Universal/PrecisionAlignment: bug fix - improved handling of heredoc/nowdoc closers Oct 13, 2022
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.

None yet

1 participant