Skip to content

Commit

Permalink
[Fix #9370] Fix an incorrect auto-correct for `Style/SoleNestedCondit…
Browse files Browse the repository at this point in the history
…ional`

Fixes #9370.

This PR fixes an incorrect auto-correct for `Style/SoleNestedConditional`
when using nested `unless` modifier multiple conditional.
  • Loading branch information
koic committed Jan 14, 2021
1 parent 860e681 commit 0a53922
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#9370](https://github.com/rubocop-hq/rubocop/issues/9370): Fix an incorrect auto-correct for `Style/SoleNestedConditional` when using nested `unless` modifier multiple conditional. ([@koic][])
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/sole_nested_conditional.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def arguments_range(node)
end

def wrap_condition?(node)
node.or_type? ||
node.and_type? || node.or_type? ||
(node.send_type? && node.arguments.any? && !node.parenthesized?)
end

Expand Down
15 changes: 15 additions & 0 deletions spec/rubocop/cop/style/sole_nested_conditional_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@
RUBY
end

it 'registers an offense and corrects when using nested `unless` modifier multiple conditional' do
expect_offense(<<~RUBY)
if foo
do_something unless bar && baz
^^^^^^ Consider merging nested conditions into outer `if` conditions.
end
RUBY

expect_correction(<<~RUBY)
if foo && !(bar && baz)
do_something
end
RUBY
end

it 'registers an offense and corrects when nested `||` operator condition' do
expect_offense(<<~RUBY)
if foo
Expand Down

0 comments on commit 0a53922

Please sign in to comment.