Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/volt/js/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ defmodule Volt.JS.Format do
@discovery_keys ~w(root sources ignore)a

def load_config do
case Application.get_env(:volt, :format) do
nil -> load_json_config()
opts when is_list(opts) -> Keyword.drop(opts, @discovery_keys)
opts = Application.get_env(:volt, :format)

# The bundler reads the same key, where the value is an atom such as :esm.
# Only a keyword list carries formatter options.
if Keyword.keyword?(opts) do
Keyword.drop(opts, @discovery_keys)
else
load_json_config()
end
end

Expand Down
8 changes: 7 additions & 1 deletion lib/volt/js/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@ defmodule Volt.JS.Helpers do
end

defp discovery_config(nil), do: []
defp discovery_config(tool), do: Application.get_env(:volt, tool, [])

defp discovery_config(tool) do
config = Application.get_env(:volt, tool, [])

# The bundler reads :format as an atom, so it holds no discovery keys.
if Keyword.keyword?(config), do: config, else: []
end
end
6 changes: 6 additions & 0 deletions test/volt/js/format_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ defmodule Volt.JS.FormatTest do

assert Format.load_config() == [semi: false, print_width: 100]
end

test "load_config/0 ignores a bundle format set on the same key" do
Application.put_env(:volt, :format, :esm)

assert Format.load_config() == Format.load_json_config()
end
end
13 changes: 13 additions & 0 deletions test/volt/js/helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ defmodule Volt.JS.HelpersTest do
assert Helpers.discover_files(tool: :lint) == [Path.join(tmp_dir, "lint/source.ts")]
end

test "a bundle format on the same key holds no discovery options", %{tmp_dir: tmp_dir} do
Application.put_env(:volt, :format, :esm)

Application.put_env(:volt, :lint,
root: tmp_dir,
sources: ["lint/**/*.ts"],
ignore: []
)

assert Helpers.discover_format_files() == []
assert Helpers.discover_files(tool: :lint) == [Path.join(tmp_dir, "lint/source.ts")]
Comment on lines +56 to +57
end

defp restore_env(key, nil), do: Application.delete_env(:volt, key)
defp restore_env(key, value), do: Application.put_env(:volt, key, value)
end