-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
map_update.ex
52 lines (42 loc) · 1.11 KB
/
map_update.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
defmodule Dialyxir.Warnings.MapUpdate do
@moduledoc """
Elixir can only use the map update syntax to update a key that is in
the map.
## Example
defmodule Example do
@spec error() :: map
def error() do
map = %{exists: :exists}
%{map | does_not_exist: :fail}
end
end
"""
@behaviour Dialyxir.Warning
@impl Dialyxir.Warning
@spec warning() :: :map_update
def warning(), do: :map_update
@impl Dialyxir.Warning
@spec format_short([String.t()]) :: String.t()
def format_short([_map, key]) do
pretty_key = Erlex.pretty_print(key)
"Attempted to update key #{pretty_key} in a map that does not have that key."
end
@impl Dialyxir.Warning
@spec format_long([String.t()]) :: String.t()
def format_long([map, key]) do
pretty_key = Erlex.pretty_print(key)
pretty_map = Erlex.pretty_print(map)
"""
Attempted to update a key in a map that does not have that key.
Key:
#{pretty_key}
Map:
#{pretty_map}
"""
end
@impl Dialyxir.Warning
@spec explain() :: String.t()
def explain() do
@moduledoc
end
end