-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eca25dd
commit b319971
Showing
12 changed files
with
767 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
defmodule ExFactor.Remover do | ||
@moduledoc """ | ||
Documentation for `ExFactor.Remover`. | ||
""" | ||
|
||
# alias ExFactor.Neighbors | ||
alias ExFactor.Parser | ||
|
||
|
||
def remove(source_path, fn_name, arity) do | ||
{_ast, block_contents} = Parser.all_functions(source_path) | ||
# [function | _] = block_contents | ||
# function = Enum.find(block_contents, &(&1.name == fn_name and &1.arity == arity && (&1.defn == :def || &1.defn == :defp))) | ||
fns_to_remove = Enum.filter(block_contents, & &1.name == fn_name) | ||
|> IO.inspect(label: "fns_to_remove") | ||
|
||
{_ast, line_list} = Parser.read_file(source_path) | ||
|
||
Enum.reduce(fns_to_remove, line_list, fn function, acc -> | ||
delete_range = function.start_line..function.end_line | ||
|> Enum.to_list() | ||
|> Enum.reverse | ||
|
||
delete_range | ||
|> Enum.reduce(acc, fn idx, acc -> | ||
List.delete_at(acc, idx - 1) | ||
end) | ||
|> List.insert_at(function.start_line, comment(fn_name, arity, function.defn)) | ||
end) | ||
|> Enum.join("\n") | ||
|> then(fn str -> File.write(source_path, str, [:write]) end) | ||
end | ||
|
||
defp comment(name, arity, "@spec") do | ||
""" | ||
# @spec: #{name}/#{arity} removed by ExFactor | ||
""" | ||
end | ||
defp comment(name, arity, _) do | ||
""" | ||
# | ||
# Function: #{name}/#{arity} removed by ExFactor | ||
# ExFactor only removes the function itself | ||
# Other artifacts, including docs and module-level comments | ||
# may remain for you to remove manually. | ||
# | ||
""" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.