-
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/SelfMemberReference: various bug fixes #2237
Squiz/SelfMemberReference: various bug fixes #2237
Conversation
8ad29d9
to
f610e5c
Compare
... when the double colon is preceded by whitespace/comments.
Prevent the sniff from not throwing the whitespace errors when the `NotUsed` error is also found.
…sed with whitespace/comments
f610e5c
to
be8e52e
Compare
I can confirm this PR fixes #2232. |
@marcospassos Thanks for testing! |
Thanks a lot for doing this. I agree that removing the whitespace checks in favour of the other sniff is a good idea. It is technically a BC break, but there is a direct replacement and this change would make the sniff more targeted. But the main fixer in there assumes it can remove whitespace and re-position things. If the sniff doesn't check whitespace, it also can't alter it. I went to unwind the whitespace checks and realised I didn't have enough time to fix the fixers that are in there, so I've left it for now. If anyone wants to give it a go, please do as I think it's a worthwhile change. |
You're welcome.
Can you clarify the above statement a bit more ? I'm not sure what you mean. |
After removing the two blocks looking at whitespace before/after, I noticed another fixer was also removing whitespace while fixing the non-self reference. Because the sniff would no longer be enforcing no whitespace around the double colon, it would need to also leave that whitespace there while fixing so it doesn't conflict with other rules. It may not be a complicated change, or I was seeing things, but I had to move on. I felt like I'd need a bunch more text cases to make sure comment and whitespace was retained by the sniff during all fixing. |
@gsherwood I'll look into this in more detail later (as part of the conflict checks), but a quick look at this tells me that this is not so much a bug in this sniff itself, but that the newly added unit tests expose existing bugs in other sniffs. |
This PR takes care of the issues identified in #2185 (comment) as well as some other bugs.
Note: As the sniff is now more directly targeted at the use of
self
in the right places, I would strongly recommend for the whitespace related errors -SpaceBefore
andSpaceAfter
- to be removed from this sniff.The
Squiz.WhiteSpace.ObjectOperatorSpacing
sniff already handles this anyway and handles this better.Relevant Commit Summary
Squiz/SelfMemberReference: prevent false positives icw anonymous classes
Fixes #2232
Squiz/SelfMemberReference: prevent false negatives for NotUsed error
... when the double colon is preceded by whitespace/comments.
Squiz/SelfMemberReference: don't hide one error behind another
Prevent the sniff from not throwing the whitespace errors when the
NotUsed
error is also found.Squiz/SelfMemberReference: allow for scoped namespace declarations
Squiz/SelfMemberReference: allow for namespace declarations interspersed with whitespace/comments
Loosely related to #2150
Squiz/SelfMemberReference: only strip leading namespace separator
... to prevent the name comparison breaking.
The PR includes unit tests for all fixes.