• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nshkrdotcom / ElixirScope / 5cec2b5f3d6eeb9cd1b58af4e46a4f2515dd5de6

29 May 2025 07:57PM UTC coverage: 58.426% (-0.03%) from 58.453%
5cec2b5f3d6eeb9cd1b58af4e46a4f2515dd5de6

push

github

NSHkr
refactor module_data

144 of 188 new or added lines in 6 files covered. (76.6%)

2 existing lines in 2 files now uncovered.

6081 of 10408 relevant lines covered (58.43%)

3205.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.0
/lib/elixir_scope/ast_repository/module_data/attribute_extractor.ex
1
# ==============================================================================
2
# Attribute Extraction Component
3
# ==============================================================================
4

5
defmodule ElixirScope.ASTRepository.ModuleData.AttributeExtractor do
6
  @moduledoc """
7
  Extracts module attributes from AST structures.
8
  """
9

10
  @doc """
11
  Extracts all module attributes from the AST.
12
  """
13
  @spec extract_attributes(term()) :: [map()]
14
  def extract_attributes(ast) do
15
    case ast do
25✔
16
      {:defmodule, _, [_name, [do: body]]} ->
17
        extract_attribute_statements(body)
24✔
18
      _ ->
1✔
19
        []
20
    end
21
  end
22

23
  # Private implementation
24
  defp extract_attribute_statements({:__block__, _, statements}) do
25
    statements
26
    |> Enum.filter(&is_attribute_statement?/1)
27
    |> Enum.map(&extract_attribute_info/1)
28
    |> Enum.reject(&is_nil/1)
14✔
29
  end
30

31
  defp extract_attribute_statements(statement) do
32
    if is_attribute_statement?(statement) do
10✔
NEW
33
      case extract_attribute_info(statement) do
×
NEW
34
        nil -> []
×
NEW
35
        attribute -> [attribute]
×
36
      end
37
    else
38
      []
39
    end
40
  end
41

42
  defp is_attribute_statement?({:@, _, [{name, _, _}]}) when is_atom(name) do
7✔
43
    true
44
  end
45

46
  defp is_attribute_statement?(_), do: false
54✔
47

48
  defp extract_attribute_info({:@, _, [{name, _, [value]}]}) do
49
    %{
7✔
50
      name: name,
51
      value: value,
52
      type: determine_attribute_type(name)
53
    }
54
  end
55

56
  defp extract_attribute_info({:@, _, [{name, _, _}]}) do
NEW
57
    %{
×
58
      name: name,
59
      value: nil,
60
      type: determine_attribute_type(name)
61
    }
62
  end
63

NEW
64
  defp extract_attribute_info(_), do: nil
×
65

66
  defp determine_attribute_type(name) do
67
    case name do
7✔
68
      :moduledoc -> :documentation
2✔
NEW
69
      :doc -> :documentation
×
70
      :behaviour -> :behaviour
2✔
NEW
71
      :behavior -> :behaviour
×
NEW
72
      :impl -> :implementation
×
NEW
73
      :spec -> :typespec
×
NEW
74
      :type -> :typespec
×
NEW
75
      :typep -> :typespec
×
NEW
76
      :opaque -> :typespec
×
NEW
77
      :callback -> :callback
×
NEW
78
      :macrocallback -> :callback
×
NEW
79
      :optional_callbacks -> :callback
×
NEW
80
      :derive -> :protocol
×
NEW
81
      :protocol -> :protocol
×
NEW
82
      :fallback_to_any -> :protocol
×
83
      _ -> :custom
3✔
84
    end
85
  end
86
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc