Skip to content

Commit

Permalink
Fix RuboCop crash with empty brackets in Style/Next cop (rubocop#3372)
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke authored and Neodelf committed Oct 15, 2016
1 parent 1aae481 commit 3ee2689
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [#3347](https://github.com/bbatsov/rubocop/issues/3347): Prevent infinite loop in `Style/TernaryParentheses` cop when used together with `Style/RedundantParentheses`. ([@drenmi][])
* [#3209](https://github.com/bbatsov/rubocop/issues/3209): Remove faulty line length check from `Style/GuardClause` cop. ([@drenmi][])
* [#3366](https://github.com/bbatsov/rubocop/issues/3366): Make `Style/MutableConstant` cop aware of splat assignments. ([@drenmi][])
* [#3372](https://github.com/bbatsov/rubocop/pull/3372): Fix RuboCop crash with empty brackets in `Style/Next` cop. ([@pocke][])

### Changes

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/next.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def ends_with_condition?(body)
end

def simple_if_without_break?(node)
return false unless node
return false unless if_without_else?(node)
return false if style == :skip_modifier_ifs && modifier_if?(node)
return false if !modifier_if?(node) && !min_body_length?(node)
Expand Down
7 changes: 7 additions & 0 deletions spec/rubocop/cop/style/next_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,13 @@
expect(cop.offenses).to be_empty
end

it 'does not crash with empty brackets' do
inspect_source(cop, ['loop do',
' ()',
'end'])
expect(cop.offenses).to be_empty
end

context 'MinBodyLength: 3' do
let(:cop_config) do
{ 'MinBodyLength' => 3 }
Expand Down

0 comments on commit 3ee2689

Please sign in to comment.