Skip to content

Commit

Permalink
[Fix rubocop#8864] Fix false positive for Style/RedundantBegin with…
Browse files Browse the repository at this point in the history
… a postfix `while` or `until`
  • Loading branch information
dvandersluis committed Oct 8, 2020
1 parent db37bea commit 38bd12e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,7 @@
### Bug fixes

* [#8782](https://github.com/rubocop-hq/rubocop/issues/8782): Fix incorrect autocorrection for `Style/TernaryParentheses` with `defined?`. ([@dvandersluis][])
* [#8864](https://github.com/rubocop-hq/rubocop/issues/8864): Fix false positive for `Style/RedundantBegin` with a postfix `while` or `until`. ([@dvandersluis][])

## 0.93.0 (2020-10-08)

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/style/redundant_begin.rb
Expand Up @@ -86,6 +86,7 @@ def on_block(node)

def on_kwbegin(node)
return if node.parent&.assignment?
return if node.parent&.post_condition_loop?

first_child = node.children.first
return if first_child.rescue_type? || first_child.ensure_type?
Expand Down
18 changes: 18 additions & 0 deletions spec/rubocop/cop/style/redundant_begin_spec.rb
Expand Up @@ -204,6 +204,24 @@ def method
RUBY
end

it 'does not register an offense when using `begin` with `while`' do
expect_no_offenses(<<~RUBY)
begin
do_first_thing
some_value = do_second_thing
end while some_value
RUBY
end

it 'does not register an offense when using `begin` with `until`' do
expect_no_offenses(<<~RUBY)
begin
do_first_thing
some_value = do_second_thing
end until some_value
RUBY
end

context '< Ruby 2.5', :ruby24 do
it 'accepts a do-end block with a begin-end' do
expect_no_offenses(<<~RUBY)
Expand Down

0 comments on commit 38bd12e

Please sign in to comment.