Skip to content

Commit

Permalink
comment better
Browse files Browse the repository at this point in the history
  • Loading branch information
ckoch-cars committed Sep 20, 2021
1 parent e5d5331 commit bc0269b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ex_factor/remover.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule ExFactor.Remover do
|> Enum.reduce(acc, fn idx, acc ->
List.delete_at(acc, idx - 1)
end)
|> List.insert_at(function.start_line, comment(source_function, arity, function.defn))
|> List.insert_at(function.start_line - 1, comment(source_function, arity, function.defn))
end)
|> Enum.join("\n")
|> then(fn str -> write_file(source_path, str, source_module, dry_run) end)
Expand All @@ -49,7 +49,7 @@ defmodule ExFactor.Remover do
#
# Function: #{name}/#{arity} removed by ExFactor
# ExFactor only removes the function itself
# Other artifacts, including docs and module-level comments
# Other artifacts, including docs, test references, and module-level comments
# may remain for you to remove manually.
#
"""
Expand Down
32 changes: 32 additions & 0 deletions test/ex_factor/remover_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,38 @@ defmodule ExFactor.RemoverTest do
File.rm("test/support/source_module.ex")
end

test "remove the function leave a comment in place" do
content = """
defmodule ExFactorSampleModule do
# a comment and no aliases
_docp = "here's an arbitrary module underscore"
def pub1(arg1) do
:ok
end
end
"""

File.write("test/tmp/source_module.ex", content)
source_path = "test/tmp/source_module.ex"

opts = [
source_module: ExFactorSampleModule,
source_path: "test/tmp/source_module.ex",
source_function: :pub1,
arity: 1
]

Remover.remove(opts)

file = File.read!(source_path)
assert file =~ "defmodule ExFactorSampleModule do"
assert file =~ "_docp = \"here's an arbitrary module underscore"
assert file =~ "# Function: pub1/1 removed by ExFactor"
refute file =~ "def pub1(arg1) do"
File.rm("test/support/source_module.ex")
end

test "it rewrites the source file and removes code blocks when function is a string" do
module = """
defmodule ExFactorSampleModule do
Expand Down

0 comments on commit bc0269b

Please sign in to comment.