From 956ca4eea1a426215ddafa4bf27e9b672de8db98 Mon Sep 17 00:00:00 2001 From: leobessa Date: Thu, 13 Jun 2024 12:01:11 -0300 Subject: [PATCH 1/2] Ignore FunctionNames when sigil is private --- lib/credo/check/readability/function_names.ex | 4 +- .../check/readability/function_names_test.exs | 42 ++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/lib/credo/check/readability/function_names.ex b/lib/credo/check/readability/function_names.ex index 5c91c44a7..f0e59474f 100644 --- a/lib/credo/check/readability/function_names.ex +++ b/lib/credo/check/readability/function_names.ex @@ -66,7 +66,7 @@ defmodule Credo.Check.Readability.FunctionNames do _issue_meta, _allow_acronyms? ) - when op in [:def, :defmacro] do + when op in [:def, :defp, :defmacro, :defmacrop] do {ast, issues} end @@ -77,7 +77,7 @@ defmodule Credo.Check.Readability.FunctionNames do _issue_meta, _allow_acronyms? ) - when op in [:def, :defmacro] do + when op in [:def, :defp, :defmacro, :defmacrop] do {ast, issues} end end diff --git a/test/credo/check/readability/function_names_test.exs b/test/credo/check/readability/function_names_test.exs index 99144b224..7363c0a54 100644 --- a/test/credo/check/readability/function_names_test.exs +++ b/test/credo/check/readability/function_names_test.exs @@ -63,6 +63,9 @@ defmodule Credo.Check.Readability.FunctionNamesTest do def sigil_O(input, args) do # ... end + def sigil_o(input, args) do + # ... + end defmacro sigil_U({:<<>>, _, [string]}, []) do # ... end @@ -75,7 +78,27 @@ defmodule Credo.Check.Readability.FunctionNamesTest do |> refute_issues() end - test "it should NOT report expected code for multi letter sigils /5" do + test "it should NOT report expected code /6" do + """ + defp sigil_O(input, args) do + # ... + end + defp sigil_p(input, args) do + # ... + end + defmacrop sigil_U({:<<>>, _, [string]}, []) do + # ... + end + defmacrop sigil_U({:<<>>, _, [string]}, []) when is_binary(string) do + # ... + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + + test "it should NOT report expected code for multi letter sigils" do """ def sigil_ZZO(input, args) do # ... @@ -92,6 +115,23 @@ defmodule Credo.Check.Readability.FunctionNamesTest do |> refute_issues() end + test "it should NOT report expected code for private multi letter sigils /2" do + """ + defp sigil_ZZO(input, args) do + # ... + end + defmacrop sigil_ZZU({:<<>>, _, [string]}, []) do + # ... + end + defmacrop sigil_ZZU({:<<>>, _, [string]}, []) when is_binary(string) do + # ... + end + """ + |> to_source_file + |> run_check(@described_check) + |> refute_issues() + end + test "it should NOT report expected code (for operators) /6" do """ defmacro @expr2 From 880062a2ce678c3c2c68407ccb4b2011d5733a1f Mon Sep 17 00:00:00 2001 From: leobessa Date: Thu, 13 Jun 2024 12:03:37 -0300 Subject: [PATCH 2/2] Refactor test case for private multi letter sigils in FunctionNames check --- test/credo/check/readability/function_names_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/credo/check/readability/function_names_test.exs b/test/credo/check/readability/function_names_test.exs index 7363c0a54..ada16f349 100644 --- a/test/credo/check/readability/function_names_test.exs +++ b/test/credo/check/readability/function_names_test.exs @@ -115,7 +115,7 @@ defmodule Credo.Check.Readability.FunctionNamesTest do |> refute_issues() end - test "it should NOT report expected code for private multi letter sigils /2" do + test "it should NOT report expected code for private multi letter sigils" do """ defp sigil_ZZO(input, args) do # ...