Skip to content

Commit

Permalink
Merge pull request rubocop#13062 from Earlopain/invertible-unless-emp…
Browse files Browse the repository at this point in the history
…ty-braces

Fix an error for `Style/InvertibleUnlessCondition` when using empty parenthesis as condition
  • Loading branch information
koic authored Jul 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 000bad7 + 6eb609b commit 539fa88
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#13062](https://github.com/rubocop/rubocop/pull/13062): Fix an error for `Style/InvertibleUnlessCondition` when using empty parenthesis as condition. ([@earlopain][])
4 changes: 2 additions & 2 deletions lib/rubocop/cop/style/invertible_unless_condition.rb
Original file line number Diff line number Diff line change
@@ -72,8 +72,8 @@ def on_if(node)

private

def invertible?(node)
case node.type
def invertible?(node) # rubocop:disable Metrics/CyclomaticComplexity
case node&.type
when :begin
invertible?(node.children.first)
when :send
12 changes: 12 additions & 0 deletions spec/rubocop/cop/style/invertible_unless_condition_spec.rb
Original file line number Diff line number Diff line change
@@ -147,4 +147,16 @@
foo if !condition
RUBY
end

it 'does not register an offense when using empty braces with `unless`' do
expect_no_offenses(<<~RUBY)
foo unless ()
RUBY
end

it 'does not register an offense when using empty braces with inverted `if`' do
expect_no_offenses(<<~RUBY)
foo if !()
RUBY
end
end

0 comments on commit 539fa88

Please sign in to comment.