diff --git a/lib/igniter/code/keyword.ex b/lib/igniter/code/keyword.ex index d3ac8ff..63cb415 100644 --- a/lib/igniter/code/keyword.ex +++ b/lib/igniter/code/keyword.ex @@ -191,6 +191,9 @@ defmodule Igniter.Code.Keyword do {{:__block__, [], [key]}, value} end + [] -> + {{:__block__, [format: :keyword], [key]}, {:__block__, [], [value]}} + _ -> {key, value} end diff --git a/test/igniter/project/config_test.exs b/test/igniter/project/config_test.exs index de7d571..187f944 100644 --- a/test/igniter/project/config_test.exs +++ b/test/igniter/project/config_test.exs @@ -38,7 +38,7 @@ defmodule Igniter.Project.ConfigTest do end @tag :regression - test "it merges the spark formatter plugins" do + test "it sets the spark formatter plugins" do %{rewrite: rewrite} = Igniter.new() |> Igniter.Project.Config.configure( @@ -64,6 +64,35 @@ defmodule Igniter.Project.ConfigTest do """ end + @tag :regression + test "it merges the spark formatter plugins" do + %{rewrite: rewrite} = + Igniter.new() + |> Igniter.create_new_file("config/fake.exs", """ + import Config + config :spark, formatter: ["Ash.Resource": []] + """) + |> Igniter.Project.Config.configure( + "fake.exs", + :spark, + [:formatter, :"Ash.Resource", :section_order], + [:section], + updater: fn zipper -> + case Igniter.Code.List.prepend_new_to_list(zipper, :section) do + {:ok, zipper} -> {:ok, zipper} + :error -> {:ok, zipper} + end + end + ) + + config_file = Rewrite.source!(rewrite, "config/fake.exs") + + assert Source.get(config_file, :content) == """ + import Config + config :spark, formatter: ["Ash.Resource": [section_order: [:section]]] + """ + end + test "it merges with 2 arg version of existing config with a single path item" do %{rewrite: rewrite} = Igniter.new()