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

[Fix #10979] Fix a false positive for Style/Style/RedundantParentheses #10981

Conversation

Tietew
Copy link
Contributor

@Tietew Tietew commented Aug 30, 2022

Fixes #10979.

This PR fixes a false positive for Style/RedundantParentheses when using parentheses with pin operator except for variables.

This PR also allows literals because:
foo in { bar: ^(1) } should be corrected to foo in { bar: 1 }.
foo in { bar: ^([1]) } should be corrected to foo in { bar: [1] }.
foo in { bar: ^([var]) } should be allowed because foo in { bar: [var] } performs capture.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@@ -29,6 +29,9 @@ class RedundantParentheses < Base
# @!method rescue?(node)
def_node_matcher :rescue?, '{^resbody ^^resbody}'

# @!method pin_operator?(node)
def_node_matcher :pin_operator?, '^(pin (begin !{lvar ivar cvar gvar}))'
Copy link
Member

Choose a reason for hiding this comment

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

The matcher name pin_operator? is abstract. How about the names allowed_pin_operator? or pin_operator_with_var?

…rentheses`

Fixes rubocop#10979.

This PR fixes a false positive for `Style/RedundantParentheses` when using parentheses with pin operator except for variables.
@Tietew Tietew force-pushed the fix_a_false_positive_for_style_redundant_parentheses branch from b7d58a0 to 45403e3 Compare August 30, 2022 03:58
@koic koic merged commit 3088078 into rubocop:master Aug 30, 2022
@Tietew Tietew deleted the fix_a_false_positive_for_style_redundant_parentheses branch August 30, 2022 04:33
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.

Style/RedundantParentheses false positive on a pin operator with expression
2 participants