Repository: phoenixframework/phoenix
Pull request #6191 (2025-04-11 14:54:58)

remove unused default argument in generated contexts
Relates to: https://github.com/elixir-lang/elixir/issues/14424


Patch:
diff --git a/installer/templates/phx_assets/app.css b/installer/templates/phx_assets/app.css
index 3ff6aabd2..d44948857 100644
--- a/installer/templates/phx_assets/app.css
+++ b/installer/templates/phx_assets/app.css
@@ -92,9 +92,9 @@
 }
 
 /* Add variants based on LiveView classes */
-@custom-variant phx-click-loading ([".phx-click-loading&", ".phx-click-loading &"]);
-@custom-variant phx-submit-loading ([".phx-submit-loading&", ".phx-submit-loading &"]);
-@custom-variant phx-change-loading ([".phx-change-loading&", ".phx-change-loading &"]);
+@custom-variant phx-click-loading (.phx-click-loading&, .phx-click-loading &);
+@custom-variant phx-submit-loading (.phx-submit-loading&, .phx-submit-loading &);
+@custom-variant phx-change-loading (.phx-change-loading&, .phx-change-loading &);
 
 /* Make LiveView wrapper divs transparent for layout */
 [data-phx-root-id] { display: contents }
diff --git a/priv/templates/phx.gen.context/access_no_schema.ex b/priv/templates/phx.gen.context/access_no_schema.ex
index 66b765e91..e24173435 100644
--- a/priv/templates/phx.gen.context/access_no_schema.ex
+++ b/priv/templates/phx.gen.context/access_no_schema.ex
@@ -39,7 +39,7 @@
       {:error, ...}
 
   """
-  def create_<%= schema.singular %>(attrs \\ %{}) do
+  def create_<%= schema.singular %>(attrs) do
     raise "TODO"
   end
 
diff --git a/priv/templates/phx.gen.context/access_no_schema_scope.ex b/priv/templates/phx.gen.context/access_no_schema_scope.ex
index 2ad0eaabf..eef5d57b3 100644
--- a/priv/templates/phx.gen.context/access_no_schema_scope.ex
+++ b/priv/templates/phx.gen.context/access_no_schema_scope.ex
@@ -47,7 +47,7 @@
       {:error, ...}
 
   """
-  def create_<%= schema.singular %>(%<%= inspect scope.alias %>{} = _scope, attrs \\ %{}) do
+  def create_<%= schema.singular %>(%<%= inspect scope.alias %>{} = _scope, attrs) do
     raise "TODO"
   end
 
diff --git a/priv/templates/phx.gen.context/schema_access.ex b/priv/templates/phx.gen.context/schema_access.ex
index 9bedfd035..b55b1d9bc 100644
--- a/priv/templates/phx.gen.context/schema_access.ex
+++ b/priv/templates/phx.gen.context/schema_access.ex
@@ -42,7 +42,7 @@
       {:error, %Ecto.Changeset{}}
 
   """
-  def create_<%= schema.singular %>(attrs \\ %{}) do
+  def create_<%= schema.singular %>(attrs) do
     %<%= inspect schema.alias %>{}
     |> <%= inspect schema.alias %>.changeset(attrs)
     |> Repo.insert()
diff --git a/priv/templates/phx.gen.context/schema_access_scope.ex b/priv/templates/phx.gen.context/schema_access_scope.ex
index 5e4a71fc4..1f415317e 100644
--- a/priv/templates/phx.gen.context/schema_access_scope.ex
+++ b/priv/templates/phx.gen.context/schema_access_scope.ex
@@ -67,7 +67,7 @@
       {:error, %Ecto.Changeset{}}
 
   """
-  def create_<%= schema.singular %>(%<%= inspect scope.alias %>{} = scope, attrs \\ %{}) do
+  def create_<%= schema.singular %>(%<%= inspect scope.alias %>{} = scope, attrs) do
     with {:ok, <%= schema.singular %> = %<%= inspect schema.alias %>{}} <-
            %<%= inspect schema.alias %>{}
            |> <%= inspect schema.alias %>.changeset(attrs, scope)


Test patch:
diff --git a/test/mix/tasks/phx.gen.context_test.exs b/test/mix/tasks/phx.gen.context_test.exs
index fb55f5d8e..a018f4a42 100644
--- a/test/mix/tasks/phx.gen.context_test.exs
+++ b/test/mix/tasks/phx.gen.context_test.exs
@@ -494,7 +494,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do
             assert file =~ "def subscribe_posts(%Scope{} = scope)"
             assert file =~ "def get_post!(%Scope{} = scope, id)"
             assert file =~ "def list_posts(%Scope{} = scope)"
-            assert file =~ "def create_post(%Scope{} = scope, attrs \\\\ %{})"
+            assert file =~ "def create_post(%Scope{} = scope, attrs)"
             assert file =~ "def update_post(%Scope{} = scope, %Post{} = post, attrs)"
             assert file =~ "def delete_post(%Scope{} = scope, %Post{} = post)"
             assert file =~ "def change_post(%Scope{} = scope, %Post{} = post, attrs \\\\ %{})"