Skip to content
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

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Nov 21, 2018

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 and SpaceAfter - 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.

@jrfnl jrfnl force-pushed the feature/2185-2232-squiz-selfmemberreference-bug-fixes branch from f610e5c to be8e52e Compare November 24, 2018 05:26
@marcospassos
Copy link
Contributor

I can confirm this PR fixes #2232.

@jrfnl
Copy link
Contributor Author

jrfnl commented Nov 25, 2018

@marcospassos Thanks for testing!

@gsherwood gsherwood added this to the 3.4.0 milestone Nov 26, 2018
@gsherwood gsherwood merged commit be8e52e into squizlabs:master Nov 26, 2018
gsherwood added a commit that referenced this pull request Nov 26, 2018
@gsherwood
Copy link
Member

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.

@jrfnl jrfnl deleted the feature/2185-2232-squiz-selfmemberreference-bug-fixes branch November 26, 2018 04:25
@jrfnl
Copy link
Contributor Author

jrfnl commented Nov 26, 2018

You're welcome.

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.

Can you clarify the above statement a bit more ? I'm not sure what you mean.
And is it this sniff or the other one for which the fixer would need adjusting ?

@gsherwood
Copy link
Member

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.

@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 4, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SelfMemberReference.NotUsed reports a violation inside anonymous classes
3 participants