From e68e1e374178d546bf742b5759a13e138b954571 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 3 Oct 2020 02:56:16 +0900 Subject: [PATCH] [Fix #8834] Fix a false positive for `Style/ParenthesesAsGroupedExpression` Fixes #8834. Fix a false positive for `Style/ParenthesesAsGroupedExpression` when method argument parentheses are omitted and hash argument key is enclosed in parentheses. --- CHANGELOG.md | 1 + lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb | 2 +- .../cop/lint/parentheses_as_grouped_expression_spec.rb | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 90ff270650c..9cc04db5242 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb b/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb index c70e734846c..9c4bcaf6219 100644 --- a/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb +++ b/lib/rubocop/cop/lint/parentheses_as_grouped_expression.rb @@ -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) diff --git a/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb b/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb index 2af707467be..e8cee91c2fb 100644 --- a/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb +++ b/spec/rubocop/cop/lint/parentheses_as_grouped_expression_spec.rb @@ -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