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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.0 | Tokenizer/PHP: stabilize comment tokenization #3027

Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Jul 20, 2020

As described in issue #3002, in PHP 8 a trailing new line is no longer included in a T_COMMENT token.

This commit "forward-fills" the PHP 5/7 tokenization of T_COMMENT tokens for PHP 8, i.e. the PHP 8 comment tokenization is undone and changed back to how comments followed by a new line were tokenized in PHP 5/7.

Includes extensive unit tests. I'm hoping to have caught everything affected 馃

The initial set of unit tests StableCommentWhitespaceTest use Linux line endings \n.
The secondary set of unit tests StableCommentWhitespaceWinTest use Windows line endings \r\n to test that the fix is stable for files using different line ending.

For the tests with Windows line endings, both the test case file as well as the actual test file have been set up to use Windows line endings for all lines, not just the test data lines, to make it simpler to manage the line endings for the files.

The test file has been excluded from the line endings CS check for that reason and a directive has been added to the .gitattributes file to safeguard that the line endings of those files will remain Windows line endings.

Fixes #3002

This PR incidentally (well, not really) fixes the current build failure on PHP 8.

As described in issue 3002, in PHP 8 a trailing new line is no longer included in a `T_COMMENT` token.

This commit "forward-fills" the PHP 5/7 tokenization of `T_COMMENT` tokens to PHP 8.

Includes extensive unit tests. I'm hoping to have caught everything affected :fingers_crossed:

The initial set of unit tests `StableCommentWhitespaceTest` use Linux line endings `\n`.
The secondary set of unit tests `StableCommentWhitespaceWinTest` use Windows line endings `\r\n` to test that the fix is stable for files using different line ending.

For the tests with Windows line endings, both the test case file as well as the actual test file have been set up to use Windows line endings for all lines, not just the test data lines, to make it simpler to manage the line endings for the files.

The test file has been excluded from the line endings CS check for that reason and a directive has been added to the `.gitattributes` file to safeguard that the line endings of those files will remain Windows line endings.

Fixes 3002
@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Jul 23, 2020
@gsherwood gsherwood added this to the 3.5.6 milestone Jul 23, 2020
gsherwood added a commit that referenced this pull request Jul 23, 2020
@gsherwood gsherwood merged commit 32a4771 into squizlabs:master Jul 23, 2020
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Jul 23, 2020
@gsherwood
Copy link
Member

Thanks so much for this

@jrfnl jrfnl deleted the feature/3002-fix-comment-tokenization-php-8 branch July 23, 2020 07:54
@jrfnl
Copy link
Contributor Author

jrfnl commented Jul 23, 2020

Thanks for merging this. Should make live easier external standards which want to test on PHP 8 already (as well as the standards here of course).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

PHP 8.0: tokenization of trailing new line after comment token has changed
2 participants