-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Squiz.PHP.EmbeddedPhp: fixer conflict with //
comment before PHP close tag
#1549
Comments
@gsherwood Any thoughts on which of the two possible solutions you'd prefer ? |
Sorry, I haven't had time to look at this at all, but a sniff-based fix would be preferred. |
@gsherwood Thanks for letting me know. The sniff based fix is quite straight forward & simple. |
Thanks for those PRs. |
Thanks for merging them & allowing the fix to also go into the 2.x branch ❤️ |
Summary
Code like this:
will cause a fixer conflict within the
Squiz.PHP.EmbeddedPhp
sniff when trying to fix theExpected 1 space before closing PHP tag;
error - errorcodeSquiz.PHP.EmbeddedPhp.SpacingBeforeClose
.The issues exists in both PHPCS 2.x as well as 3.x.
If at all possible, if would be very much appreciated if any fixes for this would also be accepted for the PHPCS 2.x branch as this issue was discovered as part of the WP Core project to get the codebase up to scratch coding standards wise.
Problem analysis
The fixer conflicts with itself.
The tokenizer will tokenize whitespace at the end of a
//
comment as part of theT_COMMENT
token, so the fixer just keeps adding more spaces between theT_COMMENT
and theT_CLOSE_TAG
which in the next fixer round is then tokenized again as being part of theT_COMMENT
resulting in the infinite loop.Possible solutions
There are two ways this could be fixed:
T_COMMENT
is followed on the same line by aT_CLOSE_PHP
token and in that case tokenizing any whitespace at the end of theT_COMMENT
asT_WHITESPACE
.The sniff based fix is actually quite simple and I've got the code ready for this - for both the 2.x as well as the 3.x branch - if that solution would be considered acceptable and I'd be happy to send you the PRs.
Relevant part of the
report-diff
outputThe text was updated successfully, but these errors were encountered: