diff --git a/lib/credo/check/readability/specs.ex b/lib/credo/check/readability/specs.ex index 043f32e98..9843e9cd1 100644 --- a/lib/credo/check/readability/specs.ex +++ b/lib/credo/check/readability/specs.ex @@ -110,6 +110,12 @@ defmodule Credo.Check.Readability.Specs do end defp issue_for(issue_meta, line_no, trigger) do + trigger = if is_tuple(trigger) do + Macro.to_string(trigger) + else + trigger + end + format_issue( issue_meta, message: "Functions should have a @spec type specification.", diff --git a/test/credo/check/readability/specs_test.exs b/test/credo/check/readability/specs_test.exs index f36a526f3..3d21d330f 100644 --- a/test/credo/check/readability/specs_test.exs +++ b/test/credo/check/readability/specs_test.exs @@ -125,6 +125,7 @@ defmodule Credo.Check.Readability.SpecsTest do |> refute_issues() end + # # cases raising issues # @@ -195,4 +196,21 @@ defmodule Credo.Check.Readability.SpecsTest do assert issue.trigger == "foo" end) end + + test "it should report/not crash for unquote/1 calls in the function name" do + ~S""" + defmodule SpecIssue do + function_name = :do_something + + def unquote(function_name)() do + :ok + end + end + """ + |> to_source_file() + |> run_check(@described_check) + |> assert_issue(fn issue -> + assert issue.trigger == "unquote(function_name)" + end) + end end