Skip to content

Commit

Permalink
False positive for parentheses removal in splatted calls
Browse files Browse the repository at this point in the history
Ahem, this is yet-another-false-positive for the `omit_parentheses`
style of the `Style/MethodCallWithArgsParentheses` cop.

If you are splatting the result of a call, you may end up with the
following:

```ruby
app/controllers/foo/bar_controller.rb:4:68: C: Style/MethodCallWithArgsParentheses: Omit parentheses for method calls with arguments.
      render json: FieldSearch.with(search_params).map(&method(:serialize))
                                                              ^^^^^^^^^^^^
```
  • Loading branch information
gsamokovarov authored and bbatsov committed Dec 14, 2018
1 parent ef95bfd commit 3d4ba9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/method_call_with_args_parentheses.rb
Expand Up @@ -237,6 +237,7 @@ def call_in_literals?(node)
node.parent &&
(node.parent.pair_type? ||
node.parent.array_type? ||
splat?(node.parent) ||
ternary_if?(node.parent))
end

Expand Down
13 changes: 13 additions & 0 deletions spec/rubocop/cop/style/method_call_with_args_parentheses_spec.rb
Expand Up @@ -414,6 +414,19 @@ def foo
RUBY
end

it 'accepts parens in splat calls' do
expect_no_offenses(<<-RUBY)
foo(*bar(args))
foo(**quux(args))
RUBY
end

it 'accepts parens in block passing calls' do
expect_no_offenses(<<-RUBY)
foo(&method(:args))
RUBY
end

it 'auto-corrects single-line calls' do
original = <<-RUBY.strip_indent
top.test(1, 2, foo: bar(3))
Expand Down

0 comments on commit 3d4ba9c

Please sign in to comment.