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 Style/RedundantParentheses with hash literal as first argument to yield #8214

Merged
merged 1 commit into from Jul 1, 2020
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
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