Skip to content

Commit

Permalink
[Fix rubocop#6550] Prevent Layout/RescueEnsureAlignment from breaking…
Browse files Browse the repository at this point in the history
… on assigned begin-end

We were missing some test cases for this cop, and accidentally introduced a
regression in rubocop#6437.

This change adds a relevant test case and fixes the issue.
  • Loading branch information
Drenmi committed Dec 6, 2018
1 parent 440c0d2 commit f5acab0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#6550](https://github.com/rubocop-hq/rubocop/issues/6550): Prevent Layout/RescueEnsureAlignment cop from breaking on assigned begin-end. ([@drenmi][])

## 0.61.0 (2018-12-05)

### New features
Expand Down
4 changes: 3 additions & 1 deletion lib/rubocop/cop/layout/rescue_ensure_alignment.rb
Expand Up @@ -114,7 +114,9 @@ def alignment_source(node, starting_loc)

def alignment_node(node)
ancestor_node = ancestor_node(node)
return nil if ancestor_node.nil?

return ancestor_node if ancestor_node.nil? ||
ancestor_node.kwbegin_type?

assignment_node = assignment_node(ancestor_node)
return assignment_node unless assignment_node.nil?
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/layout/rescue_ensure_alignment_spec.rb
Expand Up @@ -354,6 +354,16 @@ def method2
RUBY
end

it 'accepts correctly aligned rescue in assigned begin-end block' do
expect_no_offenses(<<-RUBY)
foo = begin
bar
rescue BazError
qux
end
RUBY
end

context '>= Ruby 2.5', :ruby25 do
it 'accepts aligned rescue in do-end block' do
expect_no_offenses(<<-RUBY.strip_indent)
Expand Down

0 comments on commit f5acab0

Please sign in to comment.