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.WhiteSpace.OperatorSpacing false positives for some negation operators #2640

Merged
merged 1 commit into from Nov 12, 2019
Merged

Squiz.WhiteSpace.OperatorSpacing false positives for some negation operators #2640

merged 1 commit into from Nov 12, 2019

Conversation

grongor
Copy link
Contributor

@grongor grongor commented Oct 7, 2019

Not all tokens were handled, so I added them + refactored the code a bit.

I also added a bunch of test code to test all the possible (hopefully) variants.

On a side note: I think that the "fix tests" are somewhat broken. I would expect that the code I added won't be altered at all during the fixing process (because the sniffs should ignore it completely) but it seems that some other sniffs "fixes it" - is that right? Is that expected behaviour?

@jrfnl
Copy link
Contributor

jrfnl commented Oct 7, 2019

On a side note: I think that the "fix tests" are somewhat broken. I would expect that the code I added won't be altered at all during the fixing process (because the sniffs should ignore it completely) but it seems that some other sniffs "fixes it" - is that right? Is that expected behaviour?

The tests only consider this sniff and this sniff alone. If the fixer is being invoked on code where it shouldn't be during the unit tests, I suspect there's still something wrong with this PR.

@grongor
Copy link
Contributor Author

grongor commented Oct 7, 2019

The tests only consider this sniff and this sniff alone. If the fixer is being invoked on code where it shouldn't be, I suspect there's still something wrong with this PR.

Ok, I'll look into it in more detail ...

@grongor
Copy link
Contributor Author

grongor commented Oct 7, 2019

@jrfnl you were, there was a bug :) I was juggling code between 3 code style repositories all day today, so I missed it somehow :D thx ... now it should be alright :)

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Oct 9, 2019
@gsherwood gsherwood added this to the 3.5.2 milestone Oct 9, 2019
@gsherwood gsherwood moved this from Idea Bank to Backlog in PHPCS v3 Development Oct 9, 2019
@gsherwood gsherwood changed the title Fix OperatorSpacingSniff for negation operators Squiz.WhiteSpace.OperatorSpacing false positives for some negation operators Nov 12, 2019
gsherwood added a commit that referenced this pull request Nov 12, 2019
@gsherwood gsherwood merged commit 78ca525 into squizlabs:master Nov 12, 2019
PHPCS v3 Development automation moved this from Backlog to Ready for Release Nov 12, 2019
@gsherwood
Copy link
Member

Thanks a lot for these changes. This fix will be in 3.5.3.

jrfnl added a commit to jrfnl/PHP_CodeSniffer that referenced this pull request Nov 14, 2019
PR squizlabs#2640 made it so the `Squiz.WhiteSpace.OperatorSpacing` sniff now sets a property with the `$nonOperandTokens` from the `register()` method.

However, the PSR12 sniff for the same extends the Squiz sniff, but overloads the `register()` method to set different targets.

This means that the `$nonOperandTokens` array was empty and therefore the `isOperator()` method would nearly always return `true`, which was often incorrect.

Fixed by calling the `parent::register()` method before setting the `$targets` for the PSR12 sniff.

Includes adding unit tests to the PSR12 sniff related to the exclusions handled via the `isOperator()` method, to prevent breakage like this from being able to be merged in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

None yet

4 participants