Skip to content

Commit

Permalink
[Fix rubocop#9105] Fix an incorrect auto-correct for `Style/Redundant…
Browse files Browse the repository at this point in the history
…Condition`

Fixes rubocop#9105

This PR fixes an incorrect auto-correct for `Style/RedundantCondition`
when using operator method in `else`.
  • Loading branch information
koic committed Nov 26, 2020
1 parent fa0c3f0 commit 8d4f95a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
@@ -0,0 +1 @@
* [#9105](https://github.com/rubocop-hq/rubocop/issues/9105): Fix an incorrect auto-correct for `Style/RedundantCondition` when using operator method in `else`. ([@koic][])
3 changes: 2 additions & 1 deletion lib/rubocop/cop/style/redundant_condition.rb
Expand Up @@ -131,7 +131,8 @@ def require_parentheses?(node)
end

def without_argument_parentheses_method?(node)
node.send_type? && !node.arguments.empty? && !node.parenthesized?
node.send_type? &&
!node.arguments.empty? && !node.parenthesized? && !node.operator_method?
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/cop/style/redundant_condition_spec.rb
Expand Up @@ -82,6 +82,21 @@
RUBY
end

it 'registers an offense and corrects when using operator method in `else`' do
expect_offense(<<~RUBY)
if b
^^^^ Use double pipes `||` instead.
b
else
c + d
end
RUBY

expect_correction(<<~RUBY)
b || c + d
RUBY
end

it 'registers an offense and corrects complex one liners' do
expect_offense(<<~RUBY)
if b
Expand Down

0 comments on commit 8d4f95a

Please sign in to comment.