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

New Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence sniff #197

Merged
merged 8 commits into from
Feb 3, 2024
Merged

New Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence sniff #197

merged 8 commits into from
Feb 3, 2024

Conversation

TimWolla
Copy link
Contributor

@TimWolla TimWolla commented Dec 28, 2023

Description

This is a simple respin of squizlabs/PHP_CodeSniffer#3205 in the new home of PHP CodeSniffer. I've rebased the branch onto the latest master, the resulting diff should be identical, except for package.xml, which no longer exists, and the addition of the XML doc taken from PHPCSStandards/PHPCSExtra#271.

Suggested changelog entry

Add MixedBooleanOperatorSniff ++RequireExplicitBooleanOperatorPrecedence++ - Forbid mixing different binary boolean operators within a single expression without making precedence clear using parentheses.

Related issues/external references

Closes squizlabs/PHP_CodeSniffer#3205
Closes PHPCSStandards/PHPCSExtra#271

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context for others: this PR has already been extensively reviewed in PHPCSStandards/PHPCSExtra#271 .


@TimWolla Thank you for porting this PR over and all your work on it!

I just have two questions (and I'd be happy to fix this up myself as discussed off-GH):

  1. In Add Universal.CodeAnalysis.MixedBooleanOperator PHPCSExtra#271 we ended up renaming the sniff to RequireExplicitBooleanOperatorPrecedence. Is there a pertinent reason why that change was not made for this PR ?
    (this also means there is now a mismatch between the sniff name and the title attribute for the docs)
  2. In Add Universal.CodeAnalysis.MixedBooleanOperator PHPCSExtra#271 the sniff docblock contains some additional information about the choices made for this sniff, while here it contains a code sample. Any particular reason for that ?

Other than that, all good. 👍🏻

@TimWolla
Copy link
Contributor Author

TimWolla commented Feb 3, 2024

Is there a pertinent reason why that change was not made for this PR ?

No, this is an oversight. After the review I've copied over just the implementation and tests into squizlabs/PHP_CodeSniffer#3205, because of the differences in code style / namespace between PHPCSExtra and CodeSniffer itself and missed adjusting the "basename" of the Sniff - and this PR is just a respin of that older CodeSniffer PR.

In PHPCSStandards/PHPCSExtra#271 the sniff docblock contains some additional information about the choices made for this sniff, while here it contains a code sample. Any particular reason for that ?

Yes. Existing Sniffs in CodeSniffer itself contain a code sample within their docblocks. Here's an example: https://github.com/squizlabs/PHP_CodeSniffer/blob/c6c65ca0dc8608ba87631523b97b2f8d5351a854/src/Standards/Generic/Sniffs/CodeAnalysis/JumbledIncrementerSniff.php#L9-L23


and I'd be happy to fix this up myself as discussed off-GH

I'd appreciate if you could perform the last few changes yourself. This would ensure that the result looks exactly like you wish it to be, without a back-and-forth taking up valuable time for both of us - especially since CI would need explicit approval for every additional push I make. But please let me know if I can do something to make that process easier for you (e.g. squashing the existing commits in this PR or so).

@jrfnl
Copy link
Member

jrfnl commented Feb 3, 2024

@TimWolla Thanks for your response, I just wanted to verify/confirm, that was all. 👍🏻

I'll make those last changes myself and will rebase and squash the commits before merging.

@jrfnl jrfnl changed the title Add MixedBooleanOperatorSniff New Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence sniff Feb 3, 2024
@jrfnl jrfnl merged commit cd52283 into PHPCSStandards:master Feb 3, 2024
38 checks passed
@TimWolla TimWolla deleted the mixed-boolean-operator branch February 3, 2024 23:40
@TimWolla
Copy link
Contributor Author

TimWolla commented Feb 3, 2024

Thank you!

@jrfnl
Copy link
Member

jrfnl commented Feb 3, 2024

@TimWolla It took a little while, but we got there in the end! Thank you for working with me on this one.

@TimWolla
Copy link
Contributor Author

TimWolla commented Feb 3, 2024

It took a little while

3 years and 2 days since opening the first PR on the old CodeSniffer repository 😁

jrfnl pushed a commit that referenced this pull request Feb 3, 2024
…niff (#197)

This PR adds a sniff that detects mixed boolean operators (`&&`, `||`) within a single expression without making precedence clear using parentheses.
@jrfnl
Copy link
Member

jrfnl commented Feb 4, 2024

It took a little while

3 years and 2 days since opening the first PR on the old CodeSniffer repository 😁

Ouch... well, at least from when we moved it to PHPCSExtra (and active review started) till now is less than five months, so progress. ;-)

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

Successfully merging this pull request may close these issues.

2 participants