Skip to content

Commit

Permalink
Fix Spec for unquote in def name
Browse files Browse the repository at this point in the history
Refs #1114
  • Loading branch information
rrrene committed Feb 9, 2024
1 parent 733c954 commit 2dd4fb3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/credo/check/readability/specs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
18 changes: 18 additions & 0 deletions test/credo/check/readability/specs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ defmodule Credo.Check.Readability.SpecsTest do
|> refute_issues()
end


#
# cases raising issues
#
Expand Down Expand Up @@ -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

0 comments on commit 2dd4fb3

Please sign in to comment.