Skip to content

Commit

Permalink
fix: error in codemod while formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Feb 3, 2025
1 parent b4c08af commit 0297dd1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/igniter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1362,9 +1362,13 @@ defmodule Igniter do
{:__block__, [], contents}
|> Sourceror.Zipper.zip()
# replace with nil
|> Igniter.Code.Common.remove(
&Igniter.Code.Function.function_call?(&1, :import_config, 1)
)
|> Sourceror.Zipper.traverse(fn zipper ->
if Igniter.Code.Function.function_call?(zipper, :import_config, 1) do
Sourceror.Zipper.replace(zipper, nil)
else
zipper
end
end)
|> Zipper.topmost_root()
|> Sourceror.to_string()
|> then(&Config.Reader.eval!("config/config.exs", &1, env: Mix.env()))
Expand Down
15 changes: 15 additions & 0 deletions test/igniter/project/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ defmodule Igniter.Project.ConfigTest do
""")
end

@tag :regression
test "it handles this final `if` statement while formatting modules" do
test_project()
|> Igniter.create_new_file("config/test.exs", """
import Config
if __DIR__ |> Path.join("dev.secret.exs") |> File.exists?(), do: import_config("dev.secret.exs")
import_config "host.exs"
""")
|> apply_igniter!()
|> Igniter.Project.Module.create_module(Foo.Bar, "def foo, do: 10")
|> Igniter.format(nil)
end

@tag :regression
test "it sets the spark formatter plugins" do
test_project()
Expand Down

0 comments on commit 0297dd1

Please sign in to comment.