Skip to content

Commit

Permalink
[Fix #8834] Fix a false positive for `Style/ParenthesesAsGroupedExpre…
Browse files Browse the repository at this point in the history
…ssion` (#8839)

Fixes #8834.

Fix a false positive for `Style/ParenthesesAsGroupedExpression` when
method argument parentheses are omitted and hash argument key is enclosed
in parentheses.

Co-authored-by: Bozhidar Batsov <bozhidar@batsov.com>
  • Loading branch information
koic and bbatsov committed Oct 8, 2020
1 parent 01cd876 commit 53c27fc
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 @@ -19,6 +19,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][])
* [#8830](https://github.com/rubocop-hq/rubocop/issues/8830): Fix bad autocorrect of `Style/StringConcatenation` when string includes double quotes. ([@tleish][])
* [#8807](https://github.com/rubocop-hq/rubocop/pull/8807): Fix a false positive for `Style/RedundantCondition` when using assignment by hash key access. ([@koic][])
* [#8848](https://github.com/rubocop-hq/rubocop/issues/8848): Fix a false positive for `Style/CombinableLoops` when using the same method with different arguments. ([@dvandersluis][])
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 53c27fc

Please sign in to comment.