Fix dialyzer

This commit is contained in:
Marcel Otto 2022-04-21 03:01:09 +02:00
parent 851a1b0c19
commit 01974543a0
6 changed files with 13 additions and 19 deletions

View File

@ -5,7 +5,10 @@ defmodule JSON.LD.Compaction do
alias JSON.LD.{Context, Options}
@spec compact(map | [map], map | nil, Options.convertible()) :: map
# TODO: Why is dialyzer ignoring the spec of context as a potential binary and
# complains about the is_binary(context) in the final cond to never match?
@dialyzer {:nowarn_function, compact: 3}
@spec compact(map | [map], map | binary | nil, Options.convertible()) :: map
def compact(input, context, options \\ %Options{}) do
options = Options.new(options)
active_context = JSON.LD.context(context, options)

View File

@ -52,7 +52,7 @@ defmodule JSON.LD.Encoder do
@rdf_list to_string(RDF.uri(RDF.NS.RDF.List))
@impl RDF.Serialization.Encoder
@spec encode(RDF.Data.t(), Options.t() | Enum.t()) :: {:ok, String.t()} | {:error, any}
@spec encode(RDF.Data.t(), keyword) :: {:ok, String.t()} | {:error, any}
def encode(data, opts \\ []) do
with {:ok, json_ld_object} <- from_rdf(data, opts),
{:ok, json_ld_object} <- maybe_compact(json_ld_object, opts) do
@ -62,7 +62,7 @@ defmodule JSON.LD.Encoder do
# TODO: unless we find a way to allow more optimized encode! versions, remove this since it's never used (see the respective warning)
@impl RDF.Serialization.Encoder
@spec encode!(RDF.Data.t(), Options.t() | Enum.t()) :: String.t()
@spec encode!(RDF.Data.t(), Options.convertible()) :: String.t()
@dialyzer {:nowarn_function, encode!: 1}
def encode!(data, opts \\ []) do
case encode(data, opts) do

View File

@ -6,7 +6,7 @@ defmodule JSON.LD.Expansion do
alias JSON.LD.{Context, Options}
alias JSON.LD.Context.TermDefinition
@spec expand(map, Options.t() | Enum.t()) :: [map]
@spec expand(map | [map], Options.convertible()) :: [map]
def expand(input, options \\ %Options{}) do
options = Options.new(options)
active_context = Context.new(options)

View File

@ -5,8 +5,7 @@ defmodule JSON.LD.Flattening do
alias JSON.LD.{NodeIdentifierMap, Options}
@dialyzer {:nowarn_function, flatten: 3}
@spec flatten(map | [map], map | nil, Options.t() | Enum.t()) :: [map]
@spec flatten(map | [map], map | nil, Options.convertible()) :: [map]
def flatten(input, context \\ nil, options \\ %Options{}) do
options = Options.new(options)
expanded = JSON.LD.expand(input, options)

View File

@ -16,7 +16,7 @@ defmodule JSON.LD.Options do
processing_mode: String.t()
}
@type convertible :: t | Enum.t()
@type convertible :: t | keyword | Enum.t()
defstruct base: nil,
compact_arrays: true,

View File

@ -57,9 +57,7 @@ defmodule JSON.LD do
Details at <http://json-ld.org/spec/latest/json-ld-api/#expansion-algorithm>
"""
@spec expand(map, Options.t() | Enum.t()) :: [map]
defdelegate expand(input, options \\ %Options{}),
to: Expansion
defdelegate expand(input, options \\ %Options{}), to: Expansion
@doc """
Compacts the given input according to the steps in the JSON-LD Compaction Algorithm.
@ -74,9 +72,7 @@ defmodule JSON.LD do
Details at <https://www.w3.org/TR/json-ld-api/#compaction-algorithms>
"""
@spec compact(map | [map], map | nil, Options.t() | Enum.t()) :: map
defdelegate compact(input, context, options \\ %Options{}),
to: Compaction
defdelegate compact(input, context, options \\ %Options{}), to: Compaction
@doc """
Flattens the given input according to the steps in the JSON-LD Flattening Algorithm.
@ -90,9 +86,7 @@ defmodule JSON.LD do
Details at <https://www.w3.org/TR/json-ld-api/#flattening-algorithms>
"""
@spec flatten(map | [map], map | nil, Options.t() | Enum.t()) :: [map]
defdelegate flatten(input, context \\ nil, options \\ %Options{}),
to: Flattening
defdelegate flatten(input, context \\ nil, options \\ %Options{}), to: Flattening
@doc """
Generator function for `JSON.LD.Context`s.
@ -112,7 +106,5 @@ defmodule JSON.LD do
@doc """
Generator function for JSON-LD node maps.
"""
@spec node_map([map], pid | nil) :: map
defdelegate node_map(input, node_id_map \\ nil),
to: Flattening
defdelegate node_map(input, node_id_map \\ nil), to: Flattening
end