Offend parentheses for chained && expressions in Style/RedundantParentheses#14024
Merged
koic merged 1 commit intorubocop:masterfrom Mar 23, 2025
Merged
Conversation
koic
reviewed
Mar 23, 2025
| ^^^^^^^^ Don't use parentheses around a logical expression. | ||
|
|
||
| x || (y && z) && w | ||
| ^^^^^^^^ Don't use parentheses around a logical expression. |
Member
There was a problem hiding this comment.
Can you separate the test cases as much as possible?
koic
reviewed
Mar 23, 2025
4575cba to
81956b0
Compare
81956b0 to
88bb560
Compare
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #14012 (comment) to see if this change is acceptable.
Offends cases such as
(x && y) && zand autocorrects tox && y && zsince parentheses have no bearing on expression evaluation.I know that in some cases parentheses are redundant for the machine but not for the human since they might make the intention clearer; this cop already accepts redundant parentheses in cases such as:
rubocop/spec/rubocop/cop/style/redundant_parentheses_spec.rb
Lines 805 to 808 in 4ac46fa
In case we don't want to change existing behavior, I'm also okay with that, but then I'd like to change this PR so it at least adds an expectation that
(x && y) && zdoesn't offend (currently, this case isn't covered).Before submitting the PR make sure the following are checked:
[Fix #issue-number](if the related issue exists).master(if not - rebase it).bundle exec rake default. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.mdif the new code introduces user-observable changes. See changelog entry format for details.