Skip to content

Commit

Permalink
Merge pull request #538 from skipkayhil/hm-fix-rm-first-module-method
Browse files Browse the repository at this point in the history
Fix removing first method in class
  • Loading branch information
Morriar authored Apr 17, 2024
2 parents fc2aa76 + 04ce81e commit ece6012
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/spoom/deadcode/remover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def delete_node_and_comments_and_sigs(context)
# Adjust the lines to remove to include following blank lines
after = context.next_node
if before.nil? && after && after.location.start_line > end_line + 1
end_line = after.location.end_line - 1
end_line = after.location.start_line - 1
elsif after.nil? && context.parent_node.location.end_line > end_line + 1
end_line = context.parent_node.location.end_line - 1
end
Expand Down
19 changes: 19 additions & 0 deletions test/spoom/deadcode/remover_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,25 @@ module Bar; end
RB
end

def test_deadcode_remover_removes_first_node_with_blank_lines
res = remove(<<~RB, "foo")
class Foo
def foo
end
def bar
end
end
RB

assert_equal(<<~RB, res)
class Foo
def bar
end
end
RB
end

def test_deadcode_remover_removes_node_with_blank_lines
res = remove(<<~RB, "bar")
class Foo
Expand Down

0 comments on commit ece6012

Please sign in to comment.