Skip to content

Commit

Permalink
Fix Style/RedundantReturn cop for empty if body
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke authored and Neodelf committed Oct 15, 2016
1 parent 58c458b commit 0a724b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#3607](https://github.com/bbatsov/rubocop/pull/3607): Fix `Style/RedundantReturn` cop for empty if body. ([@pocke][])

## 0.44.1 (2016-10-13)

### Bugs fixed
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/redundant_return.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def check_if_node(node)
return if modifier_if?(node) || ternary?(node)

_cond, if_node, else_node = if_node_parts(node)
check_branch(if_node)
check_branch(if_node) if if_node
check_branch(else_node) if else_node
end

Expand Down
11 changes: 11 additions & 0 deletions spec/rubocop/cop/style/redundant_return_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@
expect(cop.offenses).to be_empty
end

it 'does not blow up on empty if body' do
src = ['def func',
' if x',
' elsif y',
' else',
' end',
'end']
inspect_source(cop, src)
expect(cop.offenses).to be_empty
end

it 'auto-corrects by removing redundant returns' do
src = ['def func',
' one',
Expand Down

0 comments on commit 0a724b7

Please sign in to comment.