Skip to content

Commit

Permalink
[Fix rubocop#8834] Fix a false positive for `Style/ParenthesesAsGroup…
Browse files Browse the repository at this point in the history
…edExpression`

Fixes rubocop#8834.

Fix a false positive for `Style/ParenthesesAsGroupedExpression` when
method argument parentheses are omitted and hash argument key is enclosed
in parentheses.
  • Loading branch information
koic committed Oct 2, 2020
1 parent f3af4e2 commit e68e1e3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -14,6 +14,7 @@
* [#8514](https://github.com/rubocop-hq/rubocop/issues/8514): Correct multiple `Style/MethodDefParentheses` per file. ([@rdunlop][])
* [#8825](https://github.com/rubocop-hq/rubocop/issues/8825): Fix crash in `Style/ExplicitBlockArgument` when code is called outside of a method. ([@ghiculescu][])
* [#8354](https://github.com/rubocop-hq/rubocop/issues/8354): Detect regexp named captures in `Style/CaseLikeIf` cop. ([@dsavochkin][])
* [#8834](https://github.com/rubocop-hq/rubocop/issues/8834): Fix a false positive for `Style/ParenthesesAsGroupedExpression` when method argument parentheses are omitted and hash argument key is enclosed in parentheses. ([@koic][])

### Changes

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb
Expand Up @@ -43,7 +43,7 @@ def valid_context?(node)
end

node.operator_method? || node.setter_method? || chained_calls?(node) ||
operator_keyword?(node)
operator_keyword?(node) || node.first_argument.hash_type?
end

def first_argument_starts_with_left_parenthesis?(node)
Expand Down
Expand Up @@ -51,6 +51,13 @@
RUBY
end

it 'does not register an offense when when method argument parentheses are omitted and ' \
'hash argument key is enclosed in parentheses' do
expect_no_offenses(<<~RUBY)
transition (foo - bar) => value
RUBY
end

it 'accepts a method call without arguments' do
expect_no_offenses('func')
end
Expand Down

0 comments on commit e68e1e3

Please sign in to comment.