Skip to content

Commit a9021b1

Browse files
authored
Fix trailing whitespace in files generated by "mix new" (#15710)
1 parent 25bba6c commit a9021b1

2 files changed

Lines changed: 26 additions & 12 deletions

File tree

lib/mix/lib/mix/tasks/new.ex

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ defmodule Mix.Tasks.New do
269269
embed_template(:readme, """
270270
# <%= @mod %>
271271
272-
**TODO: Add description**
273-
<%= if @app do %>
272+
**TODO: Add description**<%= if @app do %>
273+
274274
## Installation
275275
276276
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
@@ -286,8 +286,7 @@ defmodule Mix.Tasks.New do
286286
287287
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
288288
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
289-
be found at <https://<%= String.replace(@app, "_", "-") %>.hexdocs.pm>.
290-
<% end %>
289+
be found at <https://<%= String.replace(@app, "_", "-") %>.hexdocs.pm>.<% end %>
291290
""")
292291

293292
embed_template(:formatter, """
@@ -325,11 +324,10 @@ defmodule Mix.Tasks.New do
325324
erl_crash.dump
326325
327326
# Also ignore archive artifacts (built via "mix archive.build").
328-
*.ez
329-
<%= if @app do %>
327+
*.ez<%= if @app do %>
328+
330329
# Ignore package tarball (built via "mix hex.build").
331-
<%= @app %>-*.tar
332-
<% end %>
330+
<%= @app %>-*.tar<% end %>
333331
""")
334332

335333
embed_template(:mix_exs, """

lib/mix/test/mix/tasks/new_test.exs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,16 @@ defmodule Mix.Tasks.NewTest do
1616
assert file =~ "version: \"0.1.0\""
1717
end)
1818

19-
assert_file("hello_world/README.md", ~r/# HelloWorld\n/)
20-
assert_file("hello_world/.gitignore")
19+
assert_file("hello_world/README.md", fn file ->
20+
assert file =~ "# HelloWorld\n"
21+
assert String.ends_with?(file, "\n")
22+
refute String.ends_with?(file, "\n\n")
23+
end)
24+
25+
assert_file("hello_world/.gitignore", fn file ->
26+
assert String.ends_with?(file, "\n")
27+
refute String.ends_with?(file, "\n\n")
28+
end)
2129

2230
assert_file("hello_world/lib/hello_world.ex", ~r/defmodule HelloWorld do/)
2331
assert_file("hello_world/test/test_helper.exs", ~r/ExUnit.start()/)
@@ -118,8 +126,16 @@ defmodule Mix.Tasks.NewTest do
118126
assert file =~ "apps_path: \"apps\""
119127
end)
120128

121-
assert_file("hello_world/README.md", ~r/# HelloWorld\n/)
122-
assert_file("hello_world/.gitignore")
129+
assert_file("hello_world/README.md", fn file ->
130+
assert file =~ "# HelloWorld\n"
131+
assert String.ends_with?(file, "\n")
132+
refute String.ends_with?(file, "\n\n")
133+
end)
134+
135+
assert_file("hello_world/.gitignore", fn file ->
136+
assert String.ends_with?(file, "\n")
137+
refute String.ends_with?(file, "\n\n")
138+
end)
123139

124140
assert_received {:mix_shell, :info, ["* creating mix.exs"]}
125141

0 commit comments

Comments
 (0)