Repository: phoenixframework/phoenix
Pull request #4496 (2021-09-24 08:57:51)

Replace `Enum.map` + `Enum.join` with `Enum.map_join`
Relaced `Enum.map` + `Enum.join` combinations with `Enum.map_join`.


Patch:
diff --git a/lib/mix/phoenix.ex b/lib/mix/phoenix.ex
index 41293a386..39d3b000a 100644
--- a/lib/mix/phoenix.ex
+++ b/lib/mix/phoenix.ex
@@ -331,7 +331,7 @@ defmodule Mix.Phoenix do
         Mix.shell().info"""
         The following files conflict with new files to be generated:
 
-        #{conflicts |> Enum.map(&"  * #{&1}") |> Enum.join("\n")}
+        #{Enum.map_join(conflicts, "\n", &"  * #{&1}")}
 
         See the --web option to namespace similarly named resources
         """
diff --git a/lib/mix/tasks/phx.gen.auth.ex b/lib/mix/tasks/phx.gen.auth.ex
index 65c12cad1..23d1c8df5 100644
--- a/lib/mix/tasks/phx.gen.auth.ex
+++ b/lib/mix/tasks/phx.gen.auth.ex
@@ -435,8 +435,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth do
       missing =
         context
         |> potential_layout_file_paths()
-        |> Enum.map(&"  * #{&1}")
-        |> Enum.join("\n")
+        |> Enum.map_join("\n", &"  * #{&1}")
 
       Mix.shell().error("""
 
@@ -585,8 +584,7 @@ defmodule Mix.Tasks.Phx.Gen.Auth do
 
     string
     |> String.split("\n")
-    |> Enum.map(&(indent <> &1))
-    |> Enum.join("\n")
+    |> Enum.map_join("\n", &(indent <> &1))
   end
 
   defp timestamp do
diff --git a/lib/mix/tasks/phx.gen.auth/injector.ex b/lib/mix/tasks/phx.gen.auth/injector.ex
index 15e6e0ae1..c5ecf7f1b 100644
--- a/lib/mix/tasks/phx.gen.auth/injector.ex
+++ b/lib/mix/tasks/phx.gen.auth/injector.ex
@@ -257,7 +257,6 @@ defmodule Mix.Tasks.Phx.Gen.Auth.Injector do
 
     string
     |> String.split("\n")
-    |> Enum.map(&(indent <> &1))
-    |> Enum.join("\n")
+    |> Enum.map_join("\n", &(indent <> &1))
   end
 end
diff --git a/lib/mix/tasks/phx.gen.embedded.ex b/lib/mix/tasks/phx.gen.embedded.ex
index 446e8baf8..977cac2ef 100644
--- a/lib/mix/tasks/phx.gen.embedded.ex
+++ b/lib/mix/tasks/phx.gen.embedded.ex
@@ -62,11 +62,10 @@ defmodule Mix.Tasks.Phx.Gen.Embedded do
 
   @doc false
   def validate_args!([schema | _] = args) do
-    cond do
-      not Schema.valid?(schema) ->
-        raise_with_help "Expected the schema argument, #{inspect schema}, to be a valid module name"
-      true ->
-        args
+    if Schema.valid?(schema) do
+      args
+    else
+      raise_with_help "Expected the schema argument, #{inspect schema}, to be a valid module name"
     end
   end
   def validate_args!(_) do


Test patch:
diff --git a/test/mix/tasks/phx.gen.context_test.exs b/test/mix/tasks/phx.gen.context_test.exs
index 6424f3d54..f6595f68d 100644
--- a/test/mix/tasks/phx.gen.context_test.exs
+++ b/test/mix/tasks/phx.gen.context_test.exs
@@ -316,7 +316,7 @@ defmodule Mix.Tasks.Phx.Gen.ContextTest do
 
   test "when more than 50 attributes are given", config do
     in_tmp_project config.test, fn ->
-      long_attribute_list = 0..55 |> Enum.map(&("attribute#{&1}:string")) |> Enum.join(" ")
+      long_attribute_list = Enum.map_join(0..55, " ", &("attribute#{&1}:string"))
       Gen.Context.run(~w(Blog Post posts title #{long_attribute_list}))
 
       assert_file "test/phoenix/blog_test.exs", fn file ->
diff --git a/test/mix/tasks/phx.gen.html_test.exs b/test/mix/tasks/phx.gen.html_test.exs
index 71b3511f1..72e2b3b3f 100644
--- a/test/mix/tasks/phx.gen.html_test.exs
+++ b/test/mix/tasks/phx.gen.html_test.exs
@@ -353,7 +353,7 @@ defmodule Mix.Tasks.Phx.Gen.HtmlTest do
 
   test "when more than 50 arguments are given", config do
     in_tmp_project config.test, fn ->
-      long_attribute_list = 0..55 |> Enum.map(&("attribute#{&1}:string")) |> Enum.join(" ")
+      long_attribute_list = Enum.map_join(0..55, " ", &("attribute#{&1}:string"))
       Gen.Html.run(~w(Blog Post posts #{long_attribute_list}))
 
       assert_file "test/phoenix_web/controllers/post_controller_test.exs", fn file ->
diff --git a/test/mix/tasks/phx.gen.json_test.exs b/test/mix/tasks/phx.gen.json_test.exs
index 73028d4fd..b69297160 100644
--- a/test/mix/tasks/phx.gen.json_test.exs
+++ b/test/mix/tasks/phx.gen.json_test.exs
@@ -147,7 +147,7 @@ defmodule Mix.Tasks.Phx.Gen.JsonTest do
 
   test "when more than 50 arguments are given", config do
     in_tmp_project config.test, fn ->
-      long_attribute_list = 0..55 |> Enum.map(&("attribute#{&1}:string")) |> Enum.join(" ")
+      long_attribute_list = Enum.map_join(0..55, " ", &("attribute#{&1}:string"))
       Gen.Json.run(~w(Blog Post posts #{long_attribute_list}))
 
       assert_file "test/phoenix_web/controllers/post_controller_test.exs", fn file ->
diff --git a/test/mix/tasks/phx.gen.live_test.exs b/test/mix/tasks/phx.gen.live_test.exs
index 56859d71d..c1f272943 100644
--- a/test/mix/tasks/phx.gen.live_test.exs
+++ b/test/mix/tasks/phx.gen.live_test.exs
@@ -371,7 +371,7 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do
 
   test "when more than 50 attributes are given", config do
     in_tmp_live_project config.test, fn ->
-      long_attribute_list = 0..55 |> Enum.map(&("attribute#{&1}:string")) |> Enum.join(" ")
+      long_attribute_list = Enum.map_join(0..55, " ", &("attribute#{&1}:string"))
       Gen.Live.run(~w(Blog Post posts title #{long_attribute_list}))
 
       assert_file "test/phoenix/blog_test.exs", fn file ->