Skip to content

Commit

Permalink
fix rescue assignment check on begin block assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
formigarafa committed Mar 6, 2019
1 parent fe6da44 commit 1d58f96
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/rubocop/cop/layout/rescue_ensure_alignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def alignment_source(node, starting_loc)
node.loc.begin
when :def, :defs, :class, :module
node.loc.name
when :lvasgn
node.child_nodes.first.loc.begin
else
# It is a wrapper with access modifier.
node.child_nodes.first.loc.name
Expand All @@ -114,11 +116,15 @@ def alignment_source(node, starting_loc)
def alignment_node(node)
ancestor_node = ancestor_node(node)

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

assignment_node = assignment_node(ancestor_node)
return assignment_node if same_line?(ancestor_node, assignment_node)

if assignment_node && same_line?(ancestor_node, assignment_node)
return assignment_node
end

return ancestor_node if ancestor_node.kwbegin_type?

access_modifier_node = access_modifier_node(ancestor_node)
return access_modifier_node unless access_modifier_node.nil?
Expand Down

0 comments on commit 1d58f96

Please sign in to comment.