From a7ca30f4cad0ae0e1d74799a01c21bdaf1ef884a Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Tue, 12 Nov 2024 14:31:18 +0100 Subject: [PATCH 1/4] add swoosh module --- lib/igniter/libs/swoosh.ex | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 lib/igniter/libs/swoosh.ex diff --git a/lib/igniter/libs/swoosh.ex b/lib/igniter/libs/swoosh.ex new file mode 100644 index 0000000..db1efc9 --- /dev/null +++ b/lib/igniter/libs/swoosh.ex @@ -0,0 +1,24 @@ +defmodule Igniter.Libs.Swoosh do + @moduledoc "Codemods & utilities for working with Swoosh" + + @doc "Lists all mailers found in the project." + @spec list_mailers(Igniter.t()) :: {Igniter.t(), [module()]} + def list_mailers(igniter) do + Igniter.Project.Module.find_all_matching_modules(igniter, fn _mod, zipper -> + move_to_mailer_use(igniter, zipper) != :error + end) + end + + @doc "Moves to the use statement in a module that matches `use Swoosh.Mailer`" + @spec move_to_mailer_use(Igniter.t(), Sourceror.Zipper.t()) :: + :error | {:ok, Sourceror.Zipper.t()} + def move_to_mailer_use(_igniter, zipper) do + Igniter.Code.Function.move_to_function_call(zipper, :use, 2, fn zipper -> + Igniter.Code.Function.argument_equals?( + zipper, + 0, + Swoosh.Mailer + ) + end) + end +end From b09aca9080b0fa68feb32f67016affc5bbbd540e Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Tue, 12 Nov 2024 15:29:51 +0100 Subject: [PATCH 2/4] Update lib/igniter/libs/swoosh.ex Co-authored-by: Zach Allaun --- lib/igniter/libs/swoosh.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/igniter/libs/swoosh.ex b/lib/igniter/libs/swoosh.ex index db1efc9..4c30b6f 100644 --- a/lib/igniter/libs/swoosh.ex +++ b/lib/igniter/libs/swoosh.ex @@ -1,7 +1,7 @@ defmodule Igniter.Libs.Swoosh do @moduledoc "Codemods & utilities for working with Swoosh" - @doc "Lists all mailers found in the project." + @doc "Lists all project modules that call `use Swoosh.Mailer`." @spec list_mailers(Igniter.t()) :: {Igniter.t(), [module()]} def list_mailers(igniter) do Igniter.Project.Module.find_all_matching_modules(igniter, fn _mod, zipper -> From 126e1254d42fe1b17b11942a650dd23cc0481cde Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Tue, 12 Nov 2024 15:31:53 +0100 Subject: [PATCH 3/4] remove unused param --- lib/igniter/libs/swoosh.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/igniter/libs/swoosh.ex b/lib/igniter/libs/swoosh.ex index 4c30b6f..5a098dc 100644 --- a/lib/igniter/libs/swoosh.ex +++ b/lib/igniter/libs/swoosh.ex @@ -10,9 +10,9 @@ defmodule Igniter.Libs.Swoosh do end @doc "Moves to the use statement in a module that matches `use Swoosh.Mailer`" - @spec move_to_mailer_use(Igniter.t(), Sourceror.Zipper.t()) :: + @spec move_to_mailer_use(Sourceror.Zipper.t()) :: :error | {:ok, Sourceror.Zipper.t()} - def move_to_mailer_use(_igniter, zipper) do + def move_to_mailer_use(zipper) do Igniter.Code.Function.move_to_function_call(zipper, :use, 2, fn zipper -> Igniter.Code.Function.argument_equals?( zipper, From 71f64e974ac675b3312940caf2d6d13fbe833834 Mon Sep 17 00:00:00 2001 From: Barnabas Jovanovics Date: Tue, 12 Nov 2024 15:34:52 +0100 Subject: [PATCH 4/4] fix callsite --- lib/igniter/libs/swoosh.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/igniter/libs/swoosh.ex b/lib/igniter/libs/swoosh.ex index 5a098dc..76ba7db 100644 --- a/lib/igniter/libs/swoosh.ex +++ b/lib/igniter/libs/swoosh.ex @@ -5,7 +5,7 @@ defmodule Igniter.Libs.Swoosh do @spec list_mailers(Igniter.t()) :: {Igniter.t(), [module()]} def list_mailers(igniter) do Igniter.Project.Module.find_all_matching_modules(igniter, fn _mod, zipper -> - move_to_mailer_use(igniter, zipper) != :error + move_to_mailer_use(zipper) != :error end) end