-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 8.0 | Tokenizer/PHP: stabilize comment tokenization
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
- Loading branch information
Showing
8 changed files
with
1,444 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?php | ||
|
||
/* testSingleLineSlashComment */ | ||
// Comment | ||
|
||
/* testSingleLineSlashCommentTrailing */ | ||
echo 'a'; // Comment | ||
|
||
/* testSingleLineSlashAnnotation */ | ||
// phpcs:disable Stnd.Cat | ||
|
||
/* testMultiLineSlashComment */ | ||
// Comment1 | ||
// Comment2 | ||
// Comment3 | ||
|
||
/* testMultiLineSlashCommentWithIndent */ | ||
// Comment1 | ||
// Comment2 | ||
// Comment3 | ||
|
||
/* testMultiLineSlashCommentWithAnnotationStart */ | ||
// phpcs:ignore Stnd.Cat | ||
// Comment2 | ||
// Comment3 | ||
|
||
/* testMultiLineSlashCommentWithAnnotationMiddle */ | ||
// Comment1 | ||
// @phpcs:ignore Stnd.Cat | ||
// Comment3 | ||
|
||
/* testMultiLineSlashCommentWithAnnotationEnd */ | ||
// Comment1 | ||
// Comment2 | ||
// phpcs:ignore Stnd.Cat | ||
|
||
|
||
/* testSingleLineStarComment */ | ||
/* Single line star comment */ | ||
|
||
/* testSingleLineStarCommentTrailing */ | ||
echo 'a'; /* Comment */ | ||
|
||
/* testSingleLineStarAnnotation */ | ||
/* phpcs:ignore Stnd.Cat */ | ||
|
||
/* testMultiLineStarComment */ | ||
/* Comment1 | ||
* Comment2 | ||
* Comment3 */ | ||
|
||
/* testMultiLineStarCommentWithIndent */ | ||
/* Comment1 | ||
* Comment2 | ||
* Comment3 */ | ||
|
||
/* testMultiLineStarCommentWithAnnotationStart */ | ||
/* @phpcs:ignore Stnd.Cat | ||
* Comment2 | ||
* Comment3 */ | ||
|
||
/* testMultiLineStarCommentWithAnnotationMiddle */ | ||
/* Comment1 | ||
* phpcs:ignore Stnd.Cat | ||
* Comment3 */ | ||
|
||
/* testMultiLineStarCommentWithAnnotationEnd */ | ||
/* Comment1 | ||
* Comment2 | ||
* phpcs:ignore Stnd.Cat */ | ||
|
||
|
||
/* testSingleLineDocblockComment */ | ||
/** Comment */ | ||
|
||
/* testSingleLineDocblockCommentTrailing */ | ||
$prop = 123; /** Comment */ | ||
|
||
/* testSingleLineDocblockAnnotation */ | ||
/** phpcs:ignore Stnd.Cat.Sniff */ | ||
|
||
/* testMultiLineDocblockComment */ | ||
/** | ||
* Comment1 | ||
* Comment2 | ||
* | ||
* @tag Comment | ||
*/ | ||
|
||
/* testMultiLineDocblockCommentWithIndent */ | ||
/** | ||
* Comment1 | ||
* Comment2 | ||
* | ||
* @tag Comment | ||
*/ | ||
|
||
/* testMultiLineDocblockCommentWithAnnotation */ | ||
/** | ||
* Comment | ||
* | ||
* phpcs:ignore Stnd.Cat | ||
* @tag Comment | ||
*/ | ||
|
||
/* testMultiLineDocblockCommentWithTagAnnotation */ | ||
/** | ||
* Comment | ||
* | ||
* @phpcs:ignore Stnd.Cat | ||
* @tag Comment | ||
*/ | ||
|
||
/* testSingleLineSlashCommentNoNewLineAtEnd */ | ||
// Slash ?> | ||
<?php | ||
|
||
/* testCommentAtEndOfFile */ | ||
/* Comment |
Oops, something went wrong.