Skip to content

Commit 8a48e61

Browse files
authored
Merge pull request #13782 from Earlopain/else-alignment-numblock
Fix an error `Layout/ElseAlignment` when `else` is part of a numblock
2 parents 1127fc0 + bf06024 commit 8a48e61

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#13782](https://github.com/rubocop/rubocop/pull/13782): Fix an error `Layout/ElseAlignment` when `else` is part of a numblock. ([@earlopain][])

lib/rubocop/cop/layout/else_alignment.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def base_range_of_rescue(node)
9292
case parent.type
9393
when :def, :defs then base_for_method_definition(parent)
9494
when :kwbegin then parent.loc.begin
95-
when :block
95+
when :block, :numblock
9696
assignment_node = assignment_node(parent)
9797
if same_line?(parent, assignment_node)
9898
assignment_node.source_range

spec/rubocop/cop/layout/else_alignment_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,21 @@ def my_func
582582
RUBY
583583
end
584584

585+
it 'accepts a correctly aligned else from numblock' do
586+
expect_no_offenses(<<~RUBY)
587+
array_like.each do
588+
_1
589+
puts 'do something error prone'
590+
rescue SomeException
591+
puts 'error handling'
592+
rescue
593+
puts 'error handling'
594+
else
595+
puts 'normal handling'
596+
end
597+
RUBY
598+
end
599+
585600
it 'accepts a correctly aligned else with assignment' do
586601
expect_no_offenses(<<~RUBY)
587602
result = array_like.each do |n|

0 commit comments

Comments
 (0)