Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miskeeping a end keyword in the context module while expanding it with mix phx.gen.context #5697

Open
GuillaumeMilan opened this issue Jan 17, 2024 · 1 comment

Comments

@GuillaumeMilan
Copy link

Environment

  • Erlang version: Erlang/OTP 26

  • Elixir version (elixir -v): Elixir 1.15.7 (compiled with Erlang/OTP 24)

  • Operating system: Mac OS Sonoma 14.2.1

  • Phoenix version in mix.exs

      {:phoenix, "~> 1.7"},
      {:phoenix_ecto, "~> 4.1"},
  • Phoenix version in the mix.lock
"phoenix": {:hex, :phoenix, "1.7.10", "02189140a61b2ce85bb633a9b6fd02dff705a5f1596869547aeb2b2b95edd729", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "cf784932e010fd736d656d7fead6a584a4498efefe5b8227e9f383bf15bb79d0"},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.4.2", "b21bd01fdeffcfe2fab49e4942aa938b6d3e89e93a480d4aee58085560a0bc0d", [:mix], [{:ecto, "~> 3.5", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "70242edd4601d50b69273b057ecf7b684644c19ee750989fd555625ae4ce8f5d"},
  "phoenix_html": {:hex, :phoenix_html, "3.3.3", "380b8fb45912b5638d2f1d925a3771b4516b9a78587249cabe394e0a5d579dc9", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "923ebe6fec6e2e3b3e569dfbdc6560de932cd54b000ada0208b5f45024bdd76c"},

Actual behavior

Let’s say my context module is already existing as follow before running any mix command in my project:

defmodule MyApp.MySuperContext do

  def already_present_fun, do: "hello world!"
end

After running the following context generation command:

mix phx.gen.context MySuperContext Datum data

The generated context consider the end of the module is belonging to the function and so it starts generating the context after it

defmodule MyApp.MySuperContext do

  def already_present_fun, do: "hello world!"
end # <- this end is staying during the generation

  alias MyApp.MySuperContext.Datum

  ....

  
end

Expected behavior

The end keyword should be correctly considered as the end of the module and be removed during the generation of the context's functions

Here I was expecting something like this

defmodule MyApp.MySuperContext do

  def already_present_fun, do: "hello world!"

  alias MyApp.MySuperContext.Datum

  ....

  
end
@agonzalezro
Copy link
Contributor

agonzalezro commented Feb 6, 2024

Hi @GuillaumeMilan,

I tried to reproduce this issue with Elixir 1.7.11 and I couldn't.

cat lib/foo/my_test_context.ex
defmodule Foo.MyTestContext do
  
  def already_present_fun, do: "hello world!"
endmix phx.gen.context MyTestContext Datum data 
You are generating into an existing context.
...
Would you like to proceed? [Yn] y
...head lib/foo/my_test_context.ex              
defmodule Foo.MyTestContext do
  
  def already_present_fun, do: "hello world!"

  alias Foo.MyTestContext.Datum

  @doc """
  Returns the list of data.

  ## Examples

Did you try with any other version? Maybe it's already fixed or maybe I am testing it wrong, please let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants