diff --git a/lib/common.ex b/lib/common.ex index e2206ba..b1ed3b4 100644 --- a/lib/common.ex +++ b/lib/common.ex @@ -57,6 +57,7 @@ defmodule Igniter.Common do |> Zipper.subtree() |> Zipper.root() |> Sourceror.to_string() + |> then(&"==code==\n#{&1}\n==code==\n") |> IO.puts() zipper @@ -539,8 +540,10 @@ defmodule Igniter.Common do |> Zipper.subtree() |> Zipper.root() |> case do - {:__block__, _, [_]} -> - Zipper.down(zipper) + {:__block__, _, _} -> + zipper + |> Zipper.down() + |> maybe_move_to_block() _ -> zipper diff --git a/lib/module.ex b/lib/module.ex index e64bcb5..d2fc041 100644 --- a/lib/module.ex +++ b/lib/module.ex @@ -4,6 +4,25 @@ defmodule Igniter.Module do Module.concat(module_name_prefix(), suffix) end + def proper_location(module_name) do + path = + module_name + |> Module.split() + |> Enum.map(&to_string/1) + |> Enum.map(&Macro.underscore/1) + + last = List.last(path) + leading = :lists.droplast(path) + + Path.join(["lib" | leading] ++ ["#{last}.ex"]) + end + + def parse(module_name) do + module_name + |> String.split(".") + |> Module.concat() + end + def module_name_prefix do Mix.Project.get!() |> Module.split() diff --git a/test/config_test.exs b/test/config_test.exs index 2b40f70..163d1ae 100644 --- a/test/config_test.exs +++ b/test/config_test.exs @@ -33,6 +33,31 @@ defmodule Igniter.ConfigTest do """ end + @tag :regression + test "it merges the spark formatter plugins" do + %{rewrite: rewrite} = + Igniter.new() + |> Igniter.Config.configure( + "fake.exs", + :spark, + [:formatter, :"Ash.Resource"], + [], + fn x -> + x + end + ) + |> Igniter.Config.configure("fake.exs", :spark, [:formatter, :"Ash.Domain"], [], fn x -> + x + end) + + config_file = Rewrite.source!(rewrite, "config/fake.exs") + + assert Source.get(config_file, :content) == """ + import Config + config :spark, formatter: ["Ash.Domain": [], "Ash.Resource": []] + """ + end + test "it merges with 2 arg version of existing config with a single path item" do %{rewrite: rewrite} = Igniter.new()