Skip to content

Commit

Permalink
update(Remover): Handle end line better
Browse files Browse the repository at this point in the history
Handle undefined end-lines
  • Loading branch information
ckoch-cars committed Aug 20, 2022
1 parent 0f4bacf commit 2da2e37
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/ex_factor/remover.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule ExFactor.Remover do

Enum.reduce(fns_to_remove, line_list, fn function, acc ->
delete_range =
function.start_line..function.end_line
function.start_line..get_end_line(function)
|> Enum.to_list()
|> Enum.reverse()

Expand All @@ -42,6 +42,15 @@ defmodule ExFactor.Remover do
|> then(fn str -> write_file(fns_to_remove, source_path, str, source_module, dry_run) end)
end

defp get_end_line(function) do
function
|> Map.get(:end_line, :unkown)
|> case do
:unknown -> function.start_line
line -> line
end
end

defp guard_mismatch!(module_string, source_path) when is_binary(module_string) do
source_path
|> File.read!()
Expand Down

0 comments on commit 2da2e37

Please sign in to comment.