zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

map_update.ex (1138B)


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