Skip to content

Commit

Permalink
Fix false positive for Specs
Browse files Browse the repository at this point in the history
Refs #1123
  • Loading branch information
rrrene committed Apr 11, 2024
1 parent f6d31e1 commit c0b82e4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/credo/check/readability/specs.ex
Expand Up @@ -79,6 +79,10 @@ defmodule Credo.Check.Readability.Specs do
{ast, issues}
end

defp traverse({:quote, _, _}, issues, _specs, _issue_meta) do
{nil, issues}
end

defp traverse(
{keyword, meta, [{:when, _, def_ast} | _]},
issues,
Expand Down
16 changes: 16 additions & 0 deletions test/credo/check/readability/specs_test.exs
Expand Up @@ -125,6 +125,22 @@ defmodule Credo.Check.Readability.SpecsTest do
|> refute_issues()
end

test "it should NOT report functions inside `quote`" do
"""
@spec to_def(t(), atom()) :: Macro.t()
def to_def(%__MODULE__{vars: vars, code: code}, name) do
quote generated: true do
def unquote(name)(unquote_splicing(vars)) do
unquote(code)
end
end
end
"""
|> to_source_file()
|> run_check(@described_check)
|> refute_issues()
end

#
# cases raising issues
#
Expand Down

0 comments on commit c0b82e4

Please sign in to comment.