Skip to content

Commit

Permalink
Merge pull request #1140 from leobessa/fix/ignore-private-sigil-defin…
Browse files Browse the repository at this point in the history
…itions-function-names

Ignore FunctionNames when sigil is private
  • Loading branch information
rrrene authored Aug 9, 2024
2 parents 9f00f6b + 91a95e6 commit 1deaa53
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/credo/check/readability/function_names.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule Credo.Check.Readability.FunctionNames do
_issue_meta,
_allow_acronyms?
)
when op in [:def, :defmacro, :defmacrop] do
when op in [:def, :defp, :defmacro, :defmacrop] do
{ast, issues}
end

Expand All @@ -77,7 +77,7 @@ defmodule Credo.Check.Readability.FunctionNames do
_issue_meta,
_allow_acronyms?
)
when op in [:def, :defmacro, :defmacrop] do
when op in [:def, :defp, :defmacro, :defmacrop] do
{ast, issues}
end
end
Expand Down
42 changes: 41 additions & 1 deletion test/credo/check/readability/function_names_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,7 +80,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
# ...
Expand All @@ -94,6 +117,23 @@ defmodule Credo.Check.Readability.FunctionNamesTest do
|> refute_issues()
end

test "it should NOT report expected code for private multi letter sigils" 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
Expand Down

0 comments on commit 1deaa53

Please sign in to comment.