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/DisallowSpaceIndent: flag heredoc/nowdoc closer using space indent #534

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 5, 2024

Description

This is the same fix for the Generic.WhiteSpace.DisallowSpaceIndent sniff as was previously made in squizlabs/PHP_CodeSniffer#3640 and #533 for the sister-sniff Generic.WhiteSpace.DisallowTabIndent.


Since PHP 7.3, heredoc/nowdoc closers may be indented. This indent can use either tabs or spaces and the indent is included in the T_END_HEREDOC/T_END_NOWDOC token contents as received from the PHP native tokenizer.

However, these tokens were not included in the tokens to look at for the Generic.WhiteSpace.DisallowSpaceIndent sniff, which could lead to false negatives.

Fixed now, includes tests.

And along the same lines as per #533:

  • The error for space indentation of heredoc/nowdoc closers is not auto-fixable to prevent the fixer creating parse errors as the indentation of the contents of the heredoc/nowdoc has to be the same as for the closer.
  • The error for space indentation of heredoc/nowdoc closers has its own error code to allow for selectively ignoring the indentation of heredoc/nowdoc closers.

Suggested changelog entry

Generic.WhiteSpace.DisallowSpaceIndent not reporting errors for PHP 7.3 flexible heredoc/nowdoc syntax

Related issues/external references

Types of changes

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

@jrfnl jrfnl added this to the 3.10.x Next milestone Jul 5, 2024
@jrfnl jrfnl changed the title Generic/DisallowSpaceIndent: flag heredoc/nowdoc closer using tab indent Generic/DisallowSpaceIndent: flag heredoc/nowdoc closer using space indent Jul 5, 2024
…ndent

This is the same fix for the `Generic.WhiteSpace.DisallowSpaceIndent` sniff as was previously made in squizlabs/PHP_CodeSniffer 3640 and 533 for the sister-sniff `Generic.WhiteSpace.DisallowTabIndent`.

---

Since PHP 7.3, heredoc/nowdoc closers may be indented.
This indent can use either tabs or spaces and the indent is included in the `T_END_HEREDOC`/`T_END_NOWDOC` token contents as received from the PHP native tokenizer.

However, these tokens were not included in the tokens to look at for the `Generic.WhiteSpace.DisallowSpaceIndent` sniff, which could lead to false negatives.

Fixed now, includes tests.

And along the same lines as per 533:
* The error for space indentation of heredoc/nowdoc closers is not auto-fixable to prevent the fixer creating parse errors as the indentation of the _contents_ of the heredoc/nowdoc has to be the same as for the closer.
* The error for space indentation of heredoc/nowdoc closers has its own error code to allow for selectively ignoring the indentation of heredoc/nowdoc closers.
@jrfnl jrfnl force-pushed the feature/generic-disallowspaceindent-flag-heredocnowdoc-indent branch from 27714f5 to 6d6cd7c Compare July 5, 2024 00:38
@jrfnl jrfnl merged commit 27678e7 into master Jul 9, 2024
48 checks passed
@jrfnl jrfnl deleted the feature/generic-disallowspaceindent-flag-heredocnowdoc-indent branch July 9, 2024 05:10
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