-
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
Sniff to check whitespace around namespace separators #2150
Comments
A similar issue was fixed in PSR2.Namespaces.NamespaceDeclaration as part of bug #2095 A sniff sounds like a good idea. Fixes would be great. |
That might well have been the issue which inspired me to look into the handling of this. Expect some PRs soon. |
I'm going to close this issue. I did work on this at the time, but it was more complicated than I anticipated. All the same, as whitespace and comments within namespaced names will now become a parse error in PHP 8.0, a sniff for this was needed for the PHPCompatibility PHPCS standard anyway and with the benefit of two more years of sniff writing, I have finished the sniff and will pull it to PHPCompatibility in the near future. It will be available as part of the PHPCompatibility 10.0.0 release. |
While working on something else, I suddenly realized that there is no sniff to check the whitespace around namespace separator tokens
\
and that some other sniffs get terribly confused and throw false positives/incorrect error messages when they encounter whitespace and/or comments within a namespace name.I realize it is rare to encounter such code, but it is perfectly valid PHP code and PHP will just ignore the whitespace and comments and function as expected. Also see: https://3v4l.org/EFgCp
While not explicit in the textual guidelines, using whitespace and comments within a namespace name does appear to be forbidden in PSR-2 based on all the example code.
The sniffs which currently throw false positives when they encounter such code - based on a cursory analysis - are
PSR2.Classes.ClassDeclaration
andSquiz.Classes.ClassDeclaration
.@gsherwood Do you think its a good idea to add a new sniff for this ? I'm thinking
Generic.WhiteSpace.NamespaceSeparatorSpacing
with a public$ignoreNewlines
property which defaults tofalse
.And if so, should it be added to any of the existing rulesets ?
I'd be happy to create the sniff and fix the other two I mentioned above (I actually already started to do so), but figured this warranted an issue to discuss before I opened a PR.
The text was updated successfully, but these errors were encountered: