From c0b82e4c8a1b37dca109f962014fe6ee64e76ec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Thu, 11 Apr 2024 17:00:41 +0200 Subject: [PATCH] Fix false positive for Specs Refs #1123 --- lib/credo/check/readability/specs.ex | 4 ++++ test/credo/check/readability/specs_test.exs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/credo/check/readability/specs.ex b/lib/credo/check/readability/specs.ex index 42ecb2672..82cd262ec 100644 --- a/lib/credo/check/readability/specs.ex +++ b/lib/credo/check/readability/specs.ex @@ -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, diff --git a/test/credo/check/readability/specs_test.exs b/test/credo/check/readability/specs_test.exs index 18636f728..f60c12d49 100644 --- a/test/credo/check/readability/specs_test.exs +++ b/test/credo/check/readability/specs_test.exs @@ -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 #