mirego / credo_naming

🏷 A suite of Credo checks to enforce naming best practices in an Elixir project
https://open.mirego.com
BSD 3-Clause "New" or "Revised" License
89 stars 9 forks source link

Issue when dynamically defining methods #14

Closed sitch closed 4 years ago

sitch commented 4 years ago

module has code:


  @layer_noop_actions [
    :layer_ok
  ]

  for action <- @layer_noop_actions do
    def unquote(action)(%Context{} = context, layer, result) do
      handle_action(context, layer, unquote(action), result)
    end
  end

and I get the error:

** (config) Error while running Elixir.CredoContrib.Check.FunctionNameUnderscorePrefix on lib/scorecard_ex/context_actions.ex

00:44:29.658 [error] Task #PID<0.94.0> started from #PID<0.4298.0> terminating
** (ArgumentError) argument error
    :erlang.atom_to_binary({:unquote, [line: 63, column: 9], [{:action, [line: 63, column: 17], nil}]}, :utf8)
    lib/check/function_name_underscore_prefix.ex:19: CredoContrib.Check.FunctionNameUnderscorePrefix.traverse/3
    (elixir 1.10.3) lib/macro.ex:410: Macro.do_traverse/4
    (elixir 1.10.3) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (elixir 1.10.3) lib/macro.ex:416: Macro.do_traverse/4
    (elixir 1.10.3) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (elixir 1.10.3) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (elixir 1.10.3) lib/macro.ex:396: Macro.do_traverse/4
Function: #Function<9.9572610/0 in Credo.Check.Runner.run/2>
    Args: []
** (EXIT from #PID<0.94.0>) an exception was raised:
    ** (ArgumentError) argument error
        :erlang.atom_to_binary({:unquote, [line: 63, column: 9], [{:action, [line: 63, column: 17], nil}]}, :utf8)
        lib/check/function_name_underscore_prefix.ex:19: CredoContrib.Check.FunctionNameUnderscorePrefix.traverse/3
        (elixir 1.10.3) lib/macro.ex:410: Macro.do_traverse/4
        (elixir 1.10.3) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (elixir 1.10.3) lib/macro.ex:416: Macro.do_traverse/4
        (elixir 1.10.3) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (elixir 1.10.3) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (elixir 1.10.3) lib/macro.ex:396: Macro.do_traverse/4

Seems its not expanding defs before analyzing

sitch commented 4 years ago

Oops sorry! this is for CredoContrib not CredoNaming! my bad!

:pray:

remi commented 4 years ago

No worries 😄