rrrene / credo

A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
http://credo-ci.org/
MIT License
4.91k stars 414 forks source link

missing spec on unquoted function raise error #1114

Closed aleagnelli closed 6 months ago

aleagnelli commented 6 months ago

Environment

What were you trying to do?

defmodule SpecIssue do
  function_name = :do_something

  def unquote(function_name)() do
    :ok
  end
end

Expected outcome

correctly reporting missing spec

Actual outcome

Checking 22 source files ...
Error while running Elixir.Credo.Check.Readability.Specs on lib/spec_issue.ex

10:12:12.077 [error] Task #PID<0.221.0> started from #PID<0.204.0> terminating
** (Protocol.UndefinedError) protocol String.Chars not implemented for {:unquote, [line: 4, column: 7], [{:function_name, [line: 4, column: 15], nil}]} of type Tuple
    (elixir 1.16.0) lib/string/chars.ex:3: String.Chars.impl_for!/1
    (elixir 1.16.0) lib/string/chars.ex:22: String.Chars.to_string/1
    (credo 1.7.4) lib/credo/check.ex:722: Credo.Check.format_issue/5
    (credo 1.7.4) lib/credo/check/readability/specs.ex:104: Credo.Check.Readability.Specs.traverse/4
    (elixir 1.16.0) lib/macro.ex:637: anonymous fn/4 in Macro.do_traverse_args/4
    (stdlib 5.2) lists.erl:1706: :lists.mapfoldl_1/3
    (stdlib 5.2) lists.erl:1707: :lists.mapfoldl_1/3
    (elixir 1.16.0) lib/macro.ex:602: Macro.do_traverse/4
Function: &:erlang.apply/2
    Args: [#Function<0.66951469/1 in Credo.Check.Readability.Specs.do_run_on_all_source_files/3>, [%SourceFile<lib/spec_issue.ex>]]
** (EXIT from #PID<0.99.0>) an exception was raised:
    ** (Protocol.UndefinedError) protocol String.Chars not implemented for {:unquote, [line: 4, column: 7], [{:function_name, [line: 4, column: 15], nil}]} of type Tuple
        (elixir 1.16.0) lib/string/chars.ex:3: String.Chars.impl_for!/1
        (elixir 1.16.0) lib/string/chars.ex:22: String.Chars.to_string/1
        (credo 1.7.4) lib/credo/check.ex:722: Credo.Check.format_issue/5
        (credo 1.7.4) lib/credo/check/readability/specs.ex:104: Credo.Check.Readability.Specs.traverse/4
        (elixir 1.16.0) lib/macro.ex:637: anonymous fn/4 in Macro.do_traverse_args/4
        (stdlib 5.2) lists.erl:1706: :lists.mapfoldl_1/3
        (stdlib 5.2) lists.erl:1707: :lists.mapfoldl_1/3
        (elixir 1.16.0) lib/macro.ex:602: Macro.do_traverse/4
rrrene commented 6 months ago

Thanks for reporting this πŸ˜€ It is now fixed on master.

You can try this by setting the Credo dep to

{:credo, github: "rrrene/credo"}

Please report back if your issue is solved! πŸ‘

aleagnelli commented 6 months ago

Thanks for reporting this πŸ˜€ It is now fixed on master.

You can try this by setting the Credo dep to

{:credo, github: "rrrene/credo"}

Please report back if your issue is solved! πŸ‘

I tried right now, the fix is working. Thank you! :smile:

rrrene commented 6 months ago

This is live in v1.7.5.