Skip to content

Commit

Permalink
Fix RedundantParentheses yielding hash literal
Browse files Browse the repository at this point in the history
  • Loading branch information
karlwithak committed Jun 30, 2020
1 parent a5b980d commit 6889e9c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@
* [#8195](https://github.com/rubocop-hq/rubocop/issues/8195): Fix an error for `Style/RedundantFetchBlock` when using `#fetch` with empty block. ([@koic][])
* [#8193](https://github.com/rubocop-hq/rubocop/issues/8193): Fix a false positive for `Style/RedundantRegexpCharacterClass` when using `[\b]`. ([@owst][])
* [#8205](https://github.com/rubocop-hq/rubocop/issues/8205): Fix a false positive for `Style/RedundantRegexpCharacterClass` when using a leading escaped `]`. ([@owst][])
* [#8208](https://github.com/rubocop-hq/rubocop/issues/8208): Fix `Style/RedundantParentheses` with hash literal as first argument to `yield`. ([@karlwithak][])

### Changes

Expand Down Expand Up @@ -4631,3 +4632,4 @@
[@avrusanov]: https://github.com/avrusanov
[@mauro-oto]: https://github.com/mauro-oto
[@fatkodima]: https://github.com/fatkodima
[@karlwithak]: https://github.com/karlwithak
8 changes: 7 additions & 1 deletion lib/rubocop/cop/style/redundant_parentheses.rb
Expand Up @@ -205,7 +205,9 @@ def only_begin_arg?(args)
end

def first_argument?(node)
first_send_argument?(node) || first_super_argument?(node)
first_send_argument?(node) ||
first_super_argument?(node) ||
first_yield_argument?(node)
end

def_node_matcher :first_send_argument?, <<~PATTERN
Expand All @@ -216,6 +218,10 @@ def first_argument?(node)
^(super equal?(%0) ...)
PATTERN

def_node_matcher :first_yield_argument?, <<~PATTERN
^(yield equal?(%0) ...)
PATTERN

def call_chain_starts_with_int?(begin_node, send_node)
recv = first_part_of_call_chain(send_node)
recv&.int_type? && (parent = begin_node.parent) &&
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/style/redundant_parentheses_spec.rb
Expand Up @@ -278,4 +278,12 @@ def x
})
RUBY
end

it 'accepts parentheses in yield call with hash' do
expect_no_offenses(<<~RUBY)
yield ({
foo: bar,
})
RUBY
end
end

0 comments on commit 6889e9c

Please sign in to comment.