Skip to content

Commit

Permalink
Merge pull request #9371 from koic/fix_an_incorrect_autocorrect_for_s…
Browse files Browse the repository at this point in the history
…tyle_sole_nested_conditional

[Fix #9370] Fix an incorrect auto-correct for `Style/SoleNestedCondtional`
  • Loading branch information
koic authored Jan 14, 2021
2 parents 3dc4e62 + 0a53922 commit e5f926d
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 e5f926d

Please sign in to comment.