Skip to content

Commit 02056d1

Browse files
josevalimJosé Valim
authored andcommitted
Merge pull request #2891 from chrismccord/master
Fix command_to_module_name not converting snakecased names properly Signed-off-by: José Valim <[email protected]>
1 parent 14a3686 commit 02056d1

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

lib/mix/lib/mix/utils.ex

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ defmodule Mix.Utils do
267267

268268
def module_name_to_command(module, nesting) do
269269
t = Regex.split(~r/\./, to_string(module))
270-
t |> Enum.drop(nesting) |> Enum.map(&first_to_lower(&1)) |> Enum.join(".")
270+
t |> Enum.drop(nesting) |> Enum.map(&underscore(&1)) |> Enum.join(".")
271271
end
272272

273273
@doc """
@@ -281,16 +281,10 @@ defmodule Mix.Utils do
281281
"""
282282
def command_to_module_name(s) do
283283
Regex.split(~r/\./, to_string(s)) |>
284-
Enum.map(&first_to_upper(&1)) |>
284+
Enum.map(&camelize(&1)) |>
285285
Enum.join(".")
286286
end
287287

288-
defp first_to_upper(<<s, t :: binary>>), do: <<to_upper_char(s)>> <> t
289-
defp first_to_upper(<<>>), do: <<>>
290-
291-
defp first_to_lower(<<s, t :: binary>>), do: <<to_lower_char(s)>> <> t
292-
defp first_to_lower(<<>>), do: <<>>
293-
294288
defp to_upper_char(char) when char in ?a..?z, do: char - 32
295289
defp to_upper_char(char), do: char
296290

lib/mix/test/mix/utils_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ defmodule Mix.UtilsTest do
1616
assert Mix.Utils.module_name_to_command(Mix.Tasks.Foo, 2) == "foo"
1717
assert Mix.Utils.module_name_to_command("Mix.Tasks.Foo", 2) == "foo"
1818
assert Mix.Utils.module_name_to_command("Mix.Tasks.Foo.Bar", 2) == "foo.bar"
19+
assert Mix.Utils.module_name_to_command("Mix.Tasks.FooBar.Bing", 2) == "foo_bar.bing"
20+
assert Mix.Utils.module_name_to_command("Mix.Tasks.FooBar.BingBang", 2) == "foo_bar.bing_bang"
1921
end
2022

2123
test :command_to_module_name do
2224
assert Mix.Utils.command_to_module_name("foo") == "Foo"
2325
assert Mix.Utils.command_to_module_name("foo.bar") == "Foo.Bar"
26+
assert Mix.Utils.command_to_module_name("foo_bar.baz") == "FooBar.Baz"
27+
assert Mix.Utils.command_to_module_name("foo_bar.baz_bing") == "FooBar.BazBing"
2428
end
2529

2630
test :underscore do

0 commit comments

Comments
 (0)