Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore FunctionNames when sigil is private #1140

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading