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

Need modules attributes in moduledoc :( #43

Closed
adkron opened this issue May 20, 2023 · 3 comments
Closed

Need modules attributes in moduledoc :( #43

adkron opened this issue May 20, 2023 · 3 comments
Labels
wontfix This will not be worked on

Comments

@adkron
Copy link

adkron commented May 20, 2023

I use nimble options to build documentation, and mix help uses moduledoc as the output. I need to use the module attribute to create my documentation.

Elixir / OTP Version

Erlang/OTP 25 [erts-13.1.4] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

Elixir 1.14.3 (compiled with Erlang/OTP 25)

Example Input

defmodule Mix.Tasks.DenoEx.Install do
  use Mix.Task

  @shortdoc "Installs Deno"

  @options_schema [
    path: [
      type: :string,
      default: DenoEx.executable_location(),
      doc: "The path to install deno."
    ],
    chmod: [
      type: :string,
      default: "770",
      doc: "The permissions that will be set on the deno binary. In octal format."
    ]
  ]

  @moduledoc """
  A mix task that installs Deno into your project.

  # Usage

    > mix deno.install

  # Options

    #{NimbleOptions.docs(@options_schema)}
  """

  @impl true
  def run(args) do
    {:ok, options} =
      args
      |> OptionParser.parse(aliases: [p: :path], strict: [path: :string, chmod: :string])
      |> elem(0)
      |> NimbleOptions.validate(@options_schema)

    Mix.shell().info("Installing Deno to #{options[:path]} and setting permissions to #{options[:chmod]}")

    {chmod, _} = Integer.parse(options[:chmod], 8)
    DenoEx.DenoDownloader.install(options[:path], chmod)
  end
end

Current behaviour / Stacktrace

== Compilation error in file lib/tasks/install.ex ==
** (FunctionClauseError) no function clause matching in NimbleOptions.docs/2    
    
    The following arguments were given to NimbleOptions.docs/2:
    
        # 1
        nil
    
        # 2
        []
    
    Attempted function clauses (showing 2 out of 2):
    
        def docs(schema, options) when is_list(schema) and is_list(options)
        def docs(%NimbleOptions{schema: schema}, options) when is_list(options)
    
    (nimble_options 1.0.2) lib/nimble_options.ex:403: NimbleOptions.docs/2
    lib/tasks/install.ex:13: (module)

Expected Output

defmodule Mix.Tasks.DenoEx.Install do
  @shortdoc "Installs Deno"

  @options_schema [
    path: [
      type: :string,
      default: DenoEx.executable_location(),
      doc: "The path to install deno."
    ],
    chmod: [
      type: :string,
      default: "770",
      doc: "The permissions that will be set on the deno binary. In octal format."
    ]
  ]

  @moduledoc """
  A mix task that installs Deno into your project.

  # Usage

    > mix deno.install

  # Options

    #{NimbleOptions.docs(@options_schema)}
  """

  use Mix.Task

  @impl true
  def run(args) do
    {:ok, options} =
      args
      |> OptionParser.parse(aliases: [p: :path], strict: [path: :string, chmod: :string])
      |> elem(0)
      |> NimbleOptions.validate(@options_schema)

    Mix.shell().info("Installing Deno to #{options[:path]} and setting permissions to #{options[:chmod]}")

    {chmod, _} = Integer.parse(options[:chmod], 8)
    DenoEx.DenoDownloader.install(options[:path], chmod)
  end
end
@novaugust novaugust added the wontfix This will not be worked on label May 20, 2023
@novaugust
Copy link
Contributor

novaugust commented May 20, 2023

hey amos, thanks for the issue!

directive ordering breaking things is documented (albeit poorly) on the readme, but here's a fix for you that isnt documented there

you can move your options outside of the module into a naked variable and reference it in the module.

options_schema = [ ... ]

defmodule Mix.Tasks.DenoEx.Install do
  @moduledoc """
   ... #{NimbleOptions.docs(options_schema)}
  """
  
  ...

  @options_schema options_schema
end

Hope that helps.

Gonna leave this open for a bit to help others find it as well 🤙

@novaugust
Copy link
Contributor

Updated the readme with more explicit first-run advice like this, fingers crossed people see it ;)

@adkron
Copy link
Author

adkron commented May 20, 2023

🤖 ❤️

novaugust added a commit that referenced this issue May 20, 2024
Fixes the longstanding compilation-breaking bug that occurs when module attributes are moved below directives that reference them.

Closes #156, Ref #65 and #43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants