Skip to content
Permalink
Browse files

also fix using operators in function defines

  • Loading branch information...
ityonemo committed Aug 31, 2019
1 parent f7076dd commit 0410278b9f498e5ba0310dc1f5f97e280a943436
@@ -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
@@ -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
@@ -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
#

0 comments on commit 0410278

Please sign in to comment.
You can’t perform that action at this time.