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

Style/RedundantParentheses does not add offense when safe navigation is used. #7515

Closed
geshwho opened this issue Nov 19, 2019 · 1 comment · Fixed by #7516
Closed

Style/RedundantParentheses does not add offense when safe navigation is used. #7515

geshwho opened this issue Nov 19, 2019 · 1 comment · Fixed by #7516
Labels

Comments

@geshwho
Copy link
Contributor

geshwho commented Nov 19, 2019

Given the following example:
(code&.upcase).to_s
Rubocop will not mark the parentheses as redundant.

However, with this similar example:
(code.upcase).to_s
Rubocop will correctly mark the parentheses as redundant.

Happy to help with a PR if this is in fact a bug.


Expected behavior

As far as I can tell, there is no reason not to mark such parentheses as redundant:

Style/RedundantParentheses: Don't use parentheses around a method call.
  (code&.upcase).to_s,
  ^^^^^^^^^^^^^^

Actual behavior

Rubocop does not mark any offenses

Steps to reproduce the problem

  1. Create a test file, e.g. test.rb
(code&.upcase).to_s
  1. With default configuration run rubocop --only Style/RedundantParentheses test.rb and notice no offenses

  2. Optionally, modify the contents of test.rb to:

(code.upcase).to_s
  1. Rerun rubocop --only Style/RedundantParentheses test.rb and note that the parentheses are flagged

RuboCop version

$ rubocop --version
0.76.0 (using Parser 2.6.5.0, running on ruby 2.3.8 x86_64-darwin18)
@geshwho
Copy link
Contributor Author

geshwho commented Nov 20, 2019

Thanks, @koic!

koic added a commit to koic/rubocop that referenced this issue Nov 22, 2019
Fixes rubocop#7515.

This PR fixes a false negative for `Style/RedundantParentheses` when
calling a method with safe navigation operator.
koic added a commit that referenced this issue Nov 22, 2019
…undant_parentheses

[Fix #7515] Fix a false negative for `Style/RedundantParentheses`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants