Skip to content

Commit

Permalink
also fix using operators in function defines
Browse files Browse the repository at this point in the history
  • Loading branch information
ityonemo committed Aug 31, 2019
1 parent f7076dd commit 0410278
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/credo/check/readability/function_names.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ defmodule Credo.Check.Readability.FunctionNames do
@all_sigil_chars ~w(a A b B c C d D e E f F g G h H i I j J k K l L m M n N o O p P q Q r R s S t T u U v V w W x X y Y z Z)
@all_sigil_atoms Enum.map(@all_sigil_chars, &:"sigil_#{&1}")

#all non-special-form operators
@all_nonspecial_operators ~W(! && ++ -- .. <> =~ @ |> || != !== * + - / <= == === > >= ||| &&& <<< >>> <<~ ~>> <~ ~> <~> <|> ^^^ ~~~)a

use Credo.Check, base_priority: :high

alias Credo.Code.Name
Expand Down Expand Up @@ -64,6 +67,12 @@ defmodule Credo.Check.Readability.FunctionNames do
{ast, issues}
end

# ignore non-special-form (overridable) operators
defp traverse({unquote(op), _meta, [{operator, _at_meta, _args} | _tail]} = ast, issues, _issue_meta)
when operator in @all_nonspecial_operators do
{ast, issues}
end

defp traverse({unquote(op), _meta, arguments} = ast, issues, issue_meta) do
{ast, issues_for_definition(arguments, issues, issue_meta)}
end
Expand Down
16 changes: 16 additions & 0 deletions test/credo/check/readability/function_names_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ defmodule Credo.Check.Readability.FunctionNamesTest do
|> refute_issues(@described_check)
end

@tag :one
test "it should NOT report expected code (for operators) /6" do
"""
defmacro @expr2
defmacro @expr do
# ...
end
def left ++ right do
# ++ code
end
"""
|> to_source_file
|> refute_issues(@described_check)
end

#
# cases raising issues
#
Expand Down

0 comments on commit 0410278

Please sign in to comment.