PHP 8.0 | Tokenizer/PHP: stabilize comment tokenization #3027
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.