Skip to content

Commit 1deaa53

Browse files
authored
Merge pull request #1140 from leobessa/fix/ignore-private-sigil-definitions-function-names
Ignore FunctionNames when sigil is private
2 parents 9f00f6b + 91a95e6 commit 1deaa53

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

lib/credo/check/readability/function_names.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ defmodule Credo.Check.Readability.FunctionNames do
6666
_issue_meta,
6767
_allow_acronyms?
6868
)
69-
when op in [:def, :defmacro, :defmacrop] do
69+
when op in [:def, :defp, :defmacro, :defmacrop] do
7070
{ast, issues}
7171
end
7272

@@ -77,7 +77,7 @@ defmodule Credo.Check.Readability.FunctionNames do
7777
_issue_meta,
7878
_allow_acronyms?
7979
)
80-
when op in [:def, :defmacro, :defmacrop] do
80+
when op in [:def, :defp, :defmacro, :defmacrop] do
8181
{ast, issues}
8282
end
8383
end

test/credo/check/readability/function_names_test.exs

+41-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ defmodule Credo.Check.Readability.FunctionNamesTest do
6363
def sigil_O(input, args) do
6464
# ...
6565
end
66+
def sigil_o(input, args) do
67+
# ...
68+
end
6669
defmacro sigil_U({:<<>>, _, [string]}, []) do
6770
# ...
6871
end
@@ -77,7 +80,27 @@ defmodule Credo.Check.Readability.FunctionNamesTest do
7780
|> refute_issues()
7881
end
7982

80-
test "it should NOT report expected code for multi letter sigils /5" do
83+
test "it should NOT report expected code /6" do
84+
"""
85+
defp sigil_O(input, args) do
86+
# ...
87+
end
88+
defp sigil_p(input, args) do
89+
# ...
90+
end
91+
defmacrop sigil_U({:<<>>, _, [string]}, []) do
92+
# ...
93+
end
94+
defmacrop sigil_U({:<<>>, _, [string]}, []) when is_binary(string) do
95+
# ...
96+
end
97+
"""
98+
|> to_source_file
99+
|> run_check(@described_check)
100+
|> refute_issues()
101+
end
102+
103+
test "it should NOT report expected code for multi letter sigils" do
81104
"""
82105
def sigil_ZZO(input, args) do
83106
# ...
@@ -94,6 +117,23 @@ defmodule Credo.Check.Readability.FunctionNamesTest do
94117
|> refute_issues()
95118
end
96119

120+
test "it should NOT report expected code for private multi letter sigils" do
121+
"""
122+
defp sigil_ZZO(input, args) do
123+
# ...
124+
end
125+
defmacrop sigil_ZZU({:<<>>, _, [string]}, []) do
126+
# ...
127+
end
128+
defmacrop sigil_ZZU({:<<>>, _, [string]}, []) when is_binary(string) do
129+
# ...
130+
end
131+
"""
132+
|> to_source_file
133+
|> run_check(@described_check)
134+
|> refute_issues()
135+
end
136+
97137
test "it should NOT report expected code (for operators) /6" do
98138
"""
99139
defmacro @expr2

0 commit comments

Comments
 (0)