Skip to content

Commit

Permalink
Add specs that demonstrate bug in Style/SoleNestedConditional
Browse files Browse the repository at this point in the history
The first spec succeeds.

The second spec fails:

       -if !(foo || bar) && baz
       +if (!foo || bar) && baz
  • Loading branch information
magneland authored and bbatsov committed Jan 9, 2021
1 parent 72c6b95 commit d197cc4
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions spec/rubocop/cop/style/sole_nested_conditional_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,38 @@
RUBY
end

it 'registers an offense and corrects when using `unless` and `||` and parens in the outer condition' \
'and nested modifier condition ' do
expect_offense(<<~RUBY)
unless (foo || bar)
do_something if baz
^^ Consider merging nested conditions into outer `unless` conditions.
end
RUBY

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

it 'registers an offense and corrects when using `unless` and `||` without parens in the outer condition' \
'and nested modifier condition ' do
expect_offense(<<~RUBY)
unless foo || bar
do_something if baz
^^ Consider merging nested conditions into outer `unless` conditions.
end
RUBY

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

it 'registers an offense and corrects for multiple nested conditionals' do
expect_offense(<<~RUBY)
if foo
Expand Down

0 comments on commit d197cc4

Please sign in to comment.