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 a false negative for Style/RedundantParentheses #10785

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
* [#10785](https://github.com/rubocop/rubocop/pull/10785): Fix a false negative for `Style/RedundantParentheses` when parens around a receiver of a method call with an argument. ([@koic][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/style/redundant_parentheses.rb
Expand Up @@ -81,7 +81,8 @@ def allowed_multiple_expression?(node)
end

def like_method_argument_parentheses?(node)
node.send_type? && node.arguments.size == 1 && !node.arithmetic_operation?
node.send_type? && node.arguments.one? &&
!node.arithmetic_operation? && node.first_argument.begin_type?
end

def empty_parentheses?(node)
Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/style/redundant_parentheses_spec.rb
Expand Up @@ -125,6 +125,17 @@
it_behaves_like 'plausible', '+(1.foo.bar)'
it_behaves_like 'plausible', '()'

it 'registers an offense for parens around a receiver of a method call with an argument' do
expect_offense(<<~RUBY)
(x).y(z)
^^^ Don't use parentheses around a method call.
RUBY

expect_correction(<<~RUBY)
x.y(z)
RUBY
end

it 'registers an offense for parens around an interpolated expression' do
expect_offense(<<~RUBY)
"\#{(foo)}"
Expand Down