From 491f8d5a460c9983cd6fcb3c567e57dadb7e645e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20F=C3=B6hring?= Date: Tue, 2 Jan 2024 18:31:39 +0100 Subject: [PATCH] Fix false positive on Credo.Check.Readability.PredicateFunctionNames Refs #1100 --- .../check/readability/predicate_function_names.ex | 4 ++-- .../readability/predicate_function_names_test.exs | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/credo/check/readability/predicate_function_names.ex b/lib/credo/check/readability/predicate_function_names.ex index 0156b3dfb..671e585cb 100644 --- a/lib/credo/check/readability/predicate_function_names.ex +++ b/lib/credo/check/readability/predicate_function_names.ex @@ -93,7 +93,7 @@ defmodule Credo.Check.Readability.PredicateFunctionNames do issues end - defp issues_for_name(_op, name, meta, issues, issue_meta) do + defp issues_for_name(op, name, meta, issues, issue_meta) do name = to_string(name) cond do @@ -103,7 +103,7 @@ defmodule Credo.Check.Readability.PredicateFunctionNames do | issues ] - String.starts_with?(name, "is_") -> + String.starts_with?(name, "is_") && op != :defmacro -> [issue_for(issue_meta, meta[:line], name, :only_predicate) | issues] true -> diff --git a/test/credo/check/readability/predicate_function_names_test.exs b/test/credo/check/readability/predicate_function_names_test.exs index 900dfd2ab..a3afe4482 100644 --- a/test/credo/check/readability/predicate_function_names_test.exs +++ b/test/credo/check/readability/predicate_function_names_test.exs @@ -31,6 +31,16 @@ defmodule Credo.Check.Readability.PredicateFunctionNamesTest do |> refute_issues() end + test "it should NOT report a violation with defmacro" do + """ + defmacro is_user(cookie) do + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report a violation with quote" do ~S''' defmodule ElixirScript.FFI do