Skip to content
Permalink
Browse files

Merge pull request #697 from ityonemo/fix_issue_696

fix: fixes issue #696
  • Loading branch information...
rrrene committed Sep 1, 2019
2 parents d757fdb + ce64cb3 commit 56ebbef6b4105371702ccabbb758a0d0efdf53e0
@@ -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
@@ -29,6 +29,11 @@ defmodule Credo.Check.Readability.ModuleAttributeNames do
Credo.Code.prewalk(source_file, &traverse(&1, &2, issue_meta))
end

# ignore non-alphanumeric @ ASTs, for when you're redefining the @ macro.
defp traverse({:@, _meta, [{:{}, _, _}]} = ast, issues, _) do
{ast, issues}
end

defp traverse(
{:@, _meta, [{name, meta, _arguments}]} = ast,
issues,
@@ -67,6 +67,21 @@ defmodule Credo.Check.Readability.FunctionNamesTest do
|> refute_issues(@described_check)
end

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
#
@@ -31,6 +31,20 @@ defmodule Credo.Check.Readability.ModuleAttributeNamesTest do
|> refute_issues(@described_check)
end

test "it should NOT fail when redefining the @ operator" do
"""
defmodule CredoSampleModule do
defmacro @{_, _, _} do
quote do
# some_code_here
end
end
end
"""
|> to_source_file
|> refute_issues(@described_check)
end

#
# cases raising issues
#

0 comments on commit 56ebbef

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