From 5c304fa5928ab4846a912d205a5f35050a5edf35 Mon Sep 17 00:00:00 2001 From: Doc Ritezel Date: Thu, 25 Jan 2018 19:17:45 -0800 Subject: [PATCH] Add dialyzer --- .dialyzer-ignore | 2 ++ circle.yml | 2 ++ lib/explorer/fetcher.ex | 4 +++- lib/explorer/latest_block.ex | 1 + lib/explorer/repo.ex | 1 + lib/explorer/scheduler.ex | 2 +- lib/explorer/transaction.ex | 2 +- lib/explorer_web/gettext.ex | 6 ++++++ lib/explorer_web/views/page_view.ex | 1 + lib/mix/tasks/scrape.ex | 3 ++- mix.exs | 10 ++++++++-- mix.lock | 1 + test/support/conn_case.ex | 3 +-- test/support/factory.ex | 1 + 14 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 .dialyzer-ignore diff --git a/.dialyzer-ignore b/.dialyzer-ignore new file mode 100644 index 0000000000..78c9daf302 --- /dev/null +++ b/.dialyzer-ignore @@ -0,0 +1,2 @@ +:0: Unknown function 'Elixir.ExUnit.Callbacks':'__merge__'/3 +:0: Unknown function 'Elixir.ExUnit.CaseTemplate':'__proxy__'/2 diff --git a/circle.yml b/circle.yml index 195144c355..099e6ee1b3 100644 --- a/circle.yml +++ b/circle.yml @@ -33,6 +33,7 @@ dependencies: timeout: 3600 override: - yes | mix do deps.get, local.rebar, deps.compile, compile + - mix dialyzer --plt - cd assets && npm install && cd .. cache_directories: - ~/.asdf @@ -44,6 +45,7 @@ test: pre: - mix credo - mix sobelow --private --compact --exit Low + - mix dialyzer --halt-exit-status - cd assets && npm run eslint -- --format=junit --output-file="$CIRCLE_TEST_REPORTS/eslint/junit.xml" && cd .. override: - mix test diff --git a/lib/explorer/fetcher.ex b/lib/explorer/fetcher.ex index 5c9a724479..246eee2810 100644 --- a/lib/explorer/fetcher.ex +++ b/lib/explorer/fetcher.ex @@ -5,14 +5,16 @@ defmodule Explorer.Fetcher do @moduledoc false + @dialyzer {:nowarn_function, fetch: 1} def fetch(block_number) do block_number |> download_block |> extract_block |> validate_block - |> Repo.insert + |> Repo.insert! end + @dialyzer {:nowarn_function, download_block: 1} def download_block(block_number) do {:ok, block} = eth_get_block_by_number(block_number, true) block diff --git a/lib/explorer/latest_block.ex b/lib/explorer/latest_block.ex index 254c3556d5..6add7487fd 100644 --- a/lib/explorer/latest_block.ex +++ b/lib/explorer/latest_block.ex @@ -4,6 +4,7 @@ defmodule Explorer.LatestBlock do @moduledoc false + @dialyzer {:nowarn_function, fetch: 0} def fetch do get_latest_block() |> Fetcher.fetch end diff --git a/lib/explorer/repo.ex b/lib/explorer/repo.ex index 3949599e13..e3939f0548 100644 --- a/lib/explorer/repo.ex +++ b/lib/explorer/repo.ex @@ -1,5 +1,6 @@ defmodule Explorer.Repo do use Ecto.Repo, otp_app: :explorer + @dialyzer {:nowarn_function, rollback: 1} @doc """ Dynamically loads the repository url from the diff --git a/lib/explorer/scheduler.ex b/lib/explorer/scheduler.ex index e5b533bdb4..4fec9f20bb 100644 --- a/lib/explorer/scheduler.ex +++ b/lib/explorer/scheduler.ex @@ -1,4 +1,4 @@ defmodule Explorer.Scheduler do - use Quantum.Scheduler, otp_app: :explorer @moduledoc false + use Quantum.Scheduler, otp_app: :explorer end diff --git a/lib/explorer/transaction.ex b/lib/explorer/transaction.ex index 526839cad9..b296f8415b 100644 --- a/lib/explorer/transaction.ex +++ b/lib/explorer/transaction.ex @@ -20,7 +20,7 @@ defmodule Explorer.Transaction do @optional_attrs ~w()a @doc false - def changeset(%Transaction{} = transaction, attrs \\ :empty) do + def changeset(%Transaction{} = transaction, attrs \\ %{}) do transaction |> cast(attrs, [:block_id | @required_attrs], @optional_attrs) |> validate_required(@required_attrs) diff --git a/lib/explorer_web/gettext.ex b/lib/explorer_web/gettext.ex index 567d1e2f66..e5a078693d 100644 --- a/lib/explorer_web/gettext.ex +++ b/lib/explorer_web/gettext.ex @@ -21,4 +21,10 @@ defmodule ExplorerWeb.Gettext do See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. """ use Gettext, otp_app: :explorer + + @dialyzer [{:nowarn_function, 'MACRO-dgettext': 3}, + {:nowarn_function, 'MACRO-dgettext': 4}, + {:nowarn_function, 'MACRO-dngettext': 5}, + {:nowarn_function, 'MACRO-dngettext': 6}, + ] end diff --git a/lib/explorer_web/views/page_view.ex b/lib/explorer_web/views/page_view.ex index 99e00fe6e6..cd74de9269 100644 --- a/lib/explorer_web/views/page_view.ex +++ b/lib/explorer_web/views/page_view.ex @@ -1,3 +1,4 @@ defmodule ExplorerWeb.PageView do use ExplorerWeb, :view + @dialyzer :no_match end diff --git a/lib/mix/tasks/scrape.ex b/lib/mix/tasks/scrape.ex index bbd7f6b746..09223f1354 100644 --- a/lib/mix/tasks/scrape.ex +++ b/lib/mix/tasks/scrape.ex @@ -5,8 +5,9 @@ defmodule Mix.Tasks.Scrape do @shortdoc "Scrape the blockchain." @moduledoc false + @dialyzer {:nowarn_function, run: 1} def run(_) do - Mix.Task.run "app.start" + Mix.Task.run("app.start") LatestBlock.fetch() end end diff --git a/mix.exs b/mix.exs index b1a7fdb58f..b53f0acdf2 100644 --- a/mix.exs +++ b/mix.exs @@ -7,10 +7,15 @@ defmodule Explorer.Mixfile do version: "0.0.1", elixir: "~> 1.4", elixirc_paths: elixirc_paths(Mix.env), - compilers: [:phoenix, :gettext] ++ Mix.compilers, + compilers: [:phoenix, :gettext | Mix.compilers], start_permanent: Mix.env == :prod, aliases: aliases(), - deps: deps() + deps: deps(), + dialyzer: [ + plt_add_deps: :transitive, + plt_add_apps: [:mix], + ignore_warnings: ".dialyzer-ignore" + ] ] end @@ -41,6 +46,7 @@ defmodule Explorer.Mixfile do [ {:cowboy, "~> 1.0"}, {:credo, "~> 0.8", only: [:dev, :test], runtime: false}, + {:dialyxir, "~> 0.5", only: [:dev, :test], runtime: false}, {:ethereumex, github: "exthereum/ethereumex", commit: "262f1d81ae163ffb46e127283658249dac1c8318"}, # Waiting for this version to be pushed to Hex. {:ex_machina, "~> 2.1", only: [:test]}, {:exvcr, "~> 0.8", only: :test}, diff --git a/mix.lock b/mix.lock index 294f42ab6f..4562c34ddf 100644 --- a/mix.lock +++ b/mix.lock @@ -8,6 +8,7 @@ "crontab": {:hex, :crontab, "1.1.2", "4784a50987b4a19af07a908f98e8a308b00f9c93efc5a7892155dc10cd8fc7d9", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 2.1", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"}, "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, "decimal": {:hex, :decimal, "1.4.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], [], "hexpm"}, + "dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"}, "ecto": {:hex, :ecto, "2.2.8", "a4463c0928b970f2cee722cd29aaac154e866a15882c5737e0038bbfcf03ec2c", [:mix], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"}, "ethereumex": {:git, "https://github.com/exthereum/ethereumex.git", "262f1d81ae163ffb46e127283658249dac1c8318", []}, "ex_machina": {:hex, :ex_machina, "2.1.0", "4874dc9c78e7cf2d429f24dc3c4005674d4e4da6a08be961ffccc08fb528e28b", [:mix], [{:ecto, "~> 2.1", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"}, diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex index 0b01988ae6..7e104e2f54 100644 --- a/test/support/conn_case.ex +++ b/test/support/conn_case.ex @@ -28,7 +28,7 @@ defmodule ExplorerWeb.ConnCase do end end - + @dialyzer {:nowarn_function, __ex_unit_setup_0: 1} setup tags do :ok = Ecto.Adapters.SQL.Sandbox.checkout(Explorer.Repo) unless tags[:async] do @@ -36,5 +36,4 @@ defmodule ExplorerWeb.ConnCase do end {:ok, conn: Phoenix.ConnTest.build_conn()} end - end diff --git a/test/support/factory.ex b/test/support/factory.ex index 6b1b6d0bb9..610288a424 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -1,4 +1,5 @@ defmodule Explorer.Factory do + @dialyzer {:nowarn_function, fields_for: 1} use ExMachina.Ecto, repo: Explorer.Repo use Explorer.BlockFactory use Explorer.TransactionFactory