Skip to content

Commit

Permalink
Try dialyzer on travis
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmuskala committed Dec 21, 2017
1 parent ec206f7 commit ec2aeb6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -8,7 +8,7 @@ cache:

elixir:
- 1.4
- 1.5.0-rc.1
- 1.5

otp_release:
- 18.3
Expand All @@ -21,3 +21,4 @@ install:

script:
- mix test
- mix dialyzer --halt-exit-status
5 changes: 5 additions & 0 deletions dialyzer.ignore
@@ -0,0 +1,5 @@
Unknown function 'Elixir.Jason.Encoder.Function':'__impl__'/1
Unknown function 'Elixir.Jason.Encoder.PID':'__impl__'/1
Unknown function 'Elixir.Jason.Encoder.Port':'__impl__'/1
Unknown function 'Elixir.Jason.Encoder.Reference':'__impl__'/1
Unknown function 'Elixir.Jason.Encoder.Tuple':'__impl__'/1
6 changes: 3 additions & 3 deletions lib/decoder.ex
Expand Up @@ -606,8 +606,8 @@ defmodule Jason.Decoder do
token_error(token, skip)
end

defp error(<<_rest::bits>>, original, skip, _stack, _key_decode, _string_decode) do
error(original, skip - 1)
defp error(<<_rest::bits>>, _original, skip, _stack, _key_decode, _string_decode) do
throw {:position, skip - 1}
end

defp empty_error(_original, skip) do
Expand All @@ -624,7 +624,7 @@ defmodule Jason.Decoder do
end

defp token_error(token, position, len) do
token_error(binary_part(token, position, len), position)
throw {:token, binary_part(token, position, len), position}
end

@compile {:inline, continue: 7}
Expand Down
3 changes: 3 additions & 0 deletions lib/encode.ex
@@ -1,6 +1,8 @@
defmodule Jason.EncodeError do
defexception [:message]

@type t :: %__MODULE__{message: String.t}

def exception(message) when is_binary(message) do
%__MODULE__{message: message}
end
Expand Down Expand Up @@ -28,6 +30,7 @@ defmodule Jason.Encode do
# @compile :native

@doc false
@spec encode(any, map) :: {:ok, iodata} | {:error, EncodeError.t}
def encode(value, opts) do
escape = escape_function(opts)
encode_map = encode_map_function(opts)
Expand Down
6 changes: 3 additions & 3 deletions lib/jason.ex
Expand Up @@ -12,7 +12,7 @@ defmodule Jason do

@type decode_opt :: {:keys, keys}

alias Jason.{Encode, Decoder, ParseError, EncodeError}
alias Jason.{Encode, Decoder, DecodeError, EncodeError}

@doc """
Parses a JSON value from `input` iodata.
Expand Down Expand Up @@ -40,7 +40,7 @@ defmodule Jason do
Since the atoms are not garbage collected, this can pose a DoS attack vector when used
on user-controlled data.
"""
@spec decode(iodata, [decode_opt]) :: {:ok, term} | {:error, ParseError.t()}
@spec decode(iodata, [decode_opt]) :: {:ok, term} | {:error, DecodeError.t()}
def decode(input, opts \\ []) do
input = IO.iodata_to_binary(input)
Decoder.parse(input, format_decode_opts(opts))
Expand Down Expand Up @@ -117,7 +117,7 @@ defmodule Jason do
writes and avoid allocating a continuous buffer for the whole
resulting string, lowering memory use and increasing performance.
"""
@spec encode_to_iodata(term, [encode_opt]) :: {:ok, iodata} | {:error, Jason.EncodeError.t()}
@spec encode_to_iodata(term, [encode_opt]) :: {:ok, iodata} | {:error, EncodeError.t()}
def encode_to_iodata(input, opts \\ []) do
Encode.encode(input, format_encode_opts(opts))
end
Expand Down
15 changes: 12 additions & 3 deletions mix.exs
Expand Up @@ -9,7 +9,8 @@ defmodule Jason.Mixfile do
start_permanent: Mix.env() == :prod,
consolidate_protocols: Mix.env != :test,
deps: deps(),
aliases: aliases()
aliases: aliases(),
dialyzer: dialyzer()
]
end

Expand All @@ -22,15 +23,16 @@ defmodule Jason.Mixfile do
defp deps do
[
{:decimal, "~> 1.0", optional: true},
{:stream_data, "~> 0.4", obly: :test},
{:stream_data, "~> 0.4", only: :test},
{:benchee, "~> 0.8", only: :dev},
{:benchee_html, "~> 0.1", only: :dev},
{:poison, "~> 3.0", only: :dev},
{:exjsx, "~> 4.0", only: :dev},
{:tiny, "~> 1.0", only: :dev},
{:jsone, "~> 1.4", only: :dev},
{:jiffy, "~> 0.14", only: :dev},
{:json, "~> 1.0", only: :dev}
{:json, "~> 1.0", only: :dev},
{:dialyxir, "~> 0.5", only: :dev, runtime: false}
]
end

Expand All @@ -40,4 +42,11 @@ defmodule Jason.Mixfile do
"bench.decode": ["run bench/decode.exs"]
]
end

defp dialyzer() do
[
plt_apps: [:kernel, :stdlib, :elixir, :decimal],
ignore_warnings: "dialyzer.ignore"
]
end
end
1 change: 1 addition & 0 deletions mix.lock
Expand Up @@ -4,6 +4,7 @@
"benchee_json": {:hex, :benchee_json, "0.4.0", "59d3277829bd1dca8373cdb20b916cb435c2647be235d09963fc0959db908c36", [:mix], [{:benchee, "~> 0.10", [hex: :benchee, repo: "hexpm", optional: false]}, {:poison, ">= 1.4.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
"decimal": {:hex, :decimal, "1.4.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], [], "hexpm"},
"deep_merge": {:hex, :deep_merge, "0.1.1", "c27866a7524a337b6a039eeb8dd4f17d458fd40fbbcb8c54661b71a22fffe846", [:mix], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [], [], "hexpm"},
"elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [:mix], [], "hexpm"},
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
"jiffy": {:hex, :jiffy, "0.14.11", "919a87d491c5a6b5e3bbc27fafedc3a0761ca0b4c405394f121f582fd4e3f0e5", [:rebar3], [], "hexpm"},
Expand Down

0 comments on commit ec2aeb6

Please sign in to comment.