-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Don't include trailing newline in comment token #5182
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
Conversation
This seems like a reasonable improvement and should work in edge cases (e.g. files without trailing newlines). I'd assume any tools using token_get_all() are already handling whitespace after comment tokens (e.g. tolerant-php-parser, php-parser, php_codesniffer). It'd be worth checking if PHP_CodeSniffer and |
cc @sebastianbergmann re php-token-stream |
This seems like a sane improvement to me, improving the consistency of tokenization.
I expect unit test will start breaking as PHPCS does not have any special handling of |
If it is accepted, PHPCS would need to re-attach the newline to the comment token - to effectively reverse this change - in order to maintain backwards compatibility with existing sniffs. If PHPCS backfilled this new behaviour to older PHP versions by splitting the token, any sniffs that rely on this existing structure would need to be modified, and that would be considered a serious breaking change. I'd need to reserve that for a major release. Personally, I found the inclusion of the newline strange when I first encountered it, but not overly problematic. I'd be just as happy leaving it as-is. |
@jrfnl Thanks for the ping. |
PHP CS Fixer already does this internally so I don't think it would be a big deal to be compatible with the change proposed here. |
Thanks for the ping @carusogabriel ! |
Don't include trailing newline for
#
and//
style comments inT_COMMENT
tokens. Instead leave it to the followingT_WHITESPACE
.Logically the newline doesn't belong to the comment, and having it there adds the need for ugly special-cases in tooling (as pretty much nothing else includes a trailing newline -- the opening tag and heredocs do, but due to the way they work it's less problematic there.)