Skip to content

Commit

Permalink
Fix bug in Scope
Browse files Browse the repository at this point in the history
  • Loading branch information
René Föhring committed Jan 12, 2020
1 parent 895f4aa commit d77eab6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/credo/code/module.ex
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,23 @@ defmodule Credo.Code.Module do
{ast, modules}
end

@doc "Returns the name of a module's given ast node."
@doc """
Returns the name of a module's given ast node.
"""
def name(ast)

def name({:defmodule, _, [{:__aliases__, _, name_list}, _]}) do
Enum.join(name_list, ".")
name_list
|> Enum.map(&name/1)
|> Enum.join(".")
end

def name({:__MODULE__, _meta, nil}), do: "__MODULE__"

def name(atom) when is_atom(atom), do: atom

def name(string) when is_binary(string), do: string

def name(_), do: "<Unknown Module Name>"

# TODO: write unit test
Expand Down
2 changes: 2 additions & 0 deletions test/credo/code/module_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Credo.Code.ModuleTest do

alias Credo.Code.Module

doctest Credo.Code.Module

#
# attribute
#
Expand Down

0 comments on commit d77eab6

Please sign in to comment.