Skip to content

Commit

Permalink
fix: skip unknown deps in dot formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Nov 4, 2024
1 parent 479ccc0 commit bdcb047
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/igniter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@ defmodule Igniter do
@doc "Returns a new igniter"
@spec new() :: t()
def new do

Check warning on line 104 in lib/igniter.ex

View workflow job for this annotation

GitHub Actions / ash-ci / mix dialyzer

no_return

Function new/0 has no local return.
%__MODULE__{rewrite: Rewrite.new(hooks: [Rewrite.Hook.DotFormatterUpdater])}
%__MODULE__{
rewrite:
Rewrite.new(
hooks: [Igniter.Rewrite.DotFormatterUpdater],
dot_formatter: Rewrite.DotFormatter.read!(ignore_unknown_deps: true)

Check warning on line 109 in lib/igniter.ex

View workflow job for this annotation

GitHub Actions / ash-ci / mix dialyzer

call

The function call read! will not succeed.
)
}
|> include_existing_elixir_file(".igniter.exs", required?: false)
|> parse_igniter_config()
end
Expand Down
33 changes: 33 additions & 0 deletions lib/igniter/rewrite/dot_formatter_updater.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
defmodule Igniter.Rewrite.DotFormatterUpdater do
@moduledoc false

alias Rewrite.DotFormatter

@behaviour Rewrite.Hook

@formatter ".formatter.exs"

@impl true
def handle(:new, project) do
{:ok, %{project | dot_formatter: dot_formatter(project)}}
end

def handle({action, files}, project) when action in [:added, :updated] do
if dot_formatter?(files) do
{:ok, %{project | dot_formatter: dot_formatter(project)}}
else
:ok
end
end

defp dot_formatter(project) do
case DotFormatter.read(project, ignore_unknown_deps: true) do
{:ok, dot_formatter} -> dot_formatter
{:error, _error} -> DotFormatter.default()
end
end

defp dot_formatter?(@formatter), do: true
defp dot_formatter?(files) when is_list(files), do: Enum.member?(files, @formatter)
defp dot_formatter?(_files), do: false
end
2 changes: 1 addition & 1 deletion lib/igniter/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ defmodule Igniter.Test do
|> Map.put(
:rewrite,
Rewrite.new(
hooks: [Rewrite.Hook.DotFormatterUpdater],
hooks: [Igniter.Rewrite.DotFormatterUpdater],
dot_formatter: igniter.rewrite.dot_formatter
)
)
Expand Down

0 comments on commit bdcb047

Please sign in to comment.