From 0807cdb7007b31c89336550e43b009934ce634ea Mon Sep 17 00:00:00 2001 From: Brett Hazen Date: Mon, 22 Feb 2021 09:11:35 -0700 Subject: [PATCH] What changed? ============= This adds a Dialyzer check to CI and cleans up existing warnings. --- .circleci/config.yml | 8 ++++++++ .gitignore | 2 ++ dialyzer.ignore-warnings.exs | 3 +++ lib/bamboo/api_error.ex | 2 ++ lib/bamboo/email.ex | 2 +- lib/bamboo/mailer.ex | 4 ++++ mix.exs | 11 +++++++++-- mix.lock | 2 ++ priv/plts/.gitkeep | 0 9 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 dialyzer.ignore-warnings.exs create mode 100644 priv/plts/.gitkeep diff --git a/.circleci/config.yml b/.circleci/config.yml index 024bbfa9..f911d5cc 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,6 +16,10 @@ jobs: keys: - mix-cache-{{ checksum "mix.lock" }} + - restore_cache: + keys: + - dialyzer-cache-21.2-1.8.1 + - run: mix do deps.get - save_cache: key: mix-cache-{{ checksum "mix.lock" }} @@ -23,4 +27,8 @@ jobs: - run: mix format --check-formatted - run: mix test + - run: mix dialyzer + - save_cache: + key: dialyzer-cache-21.2-1.8.1 + paths: "priv/plts" - run: MIX_ENV=prod mix compile diff --git a/.gitignore b/.gitignore index bb18dc22..3a4224bd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ /.elixir_ls erl_crash.dump *.ez +/priv/plts/*.plt +/priv/plts/*.plt.hash diff --git a/dialyzer.ignore-warnings.exs b/dialyzer.ignore-warnings.exs new file mode 100644 index 00000000..1155b549 --- /dev/null +++ b/dialyzer.ignore-warnings.exs @@ -0,0 +1,3 @@ +[ + {"lib/bamboo/formatter.ex", :callback_type_mismatch, 73} +] diff --git a/lib/bamboo/api_error.ex b/lib/bamboo/api_error.ex index 4c8528a9..bfe35fa6 100644 --- a/lib/bamboo/api_error.ex +++ b/lib/bamboo/api_error.ex @@ -39,8 +39,10 @@ defmodule Bamboo.ApiError do """ + @spec raise_api_error(any()) :: no_return() def raise_api_error(message), do: raise(__MODULE__, message: message) + @spec raise_api_error(String.t(), any(), Keyword.t()) :: no_return() def raise_api_error(service_name, response, params, extra_message \\ "") do message = """ There was a problem sending the email through the #{service_name} API. diff --git a/lib/bamboo/email.ex b/lib/bamboo/email.ex index d36b7a3c..3925e17c 100644 --- a/lib/bamboo/email.ex +++ b/lib/bamboo/email.ex @@ -71,7 +71,7 @@ defmodule Bamboo.Email do end """ - @type address :: {String.t(), String.t()} + @type address :: {String.t() | nil, String.t()} @type address_list :: nil | address | [address] | any @type t :: %__MODULE__{ diff --git a/lib/bamboo/mailer.ex b/lib/bamboo/mailer.ex index 2016a2d9..9e0803e7 100644 --- a/lib/bamboo/mailer.ex +++ b/lib/bamboo/mailer.ex @@ -142,6 +142,7 @@ defmodule Bamboo.Mailer do Email.welcome_email |> Mailer.deliver_now(config: %{username: "Emma", smtp_port: 2525}) """ + @spec deliver_now(any()) :: no_return() def deliver_now(_email, _opts \\ []) do raise @cannot_call_directly_error end @@ -156,6 +157,7 @@ defmodule Bamboo.Mailer do On failure, this function returns an error tuple: `{:error, error}`. """ + @spec deliver_now!(any()) :: no_return() def deliver_now!(_email, _opts \\ []) do raise @cannot_call_directly_error end @@ -174,6 +176,7 @@ defmodule Bamboo.Mailer do If the email is invalid, this function will return an `{:error, error}` tuple. """ + @spec deliver_later(any()) :: no_return() def deliver_later(_email, _opts \\ []) do raise @cannot_call_directly_error end @@ -188,6 +191,7 @@ defmodule Bamboo.Mailer do If the email is invalid, this function raises an error. """ + @spec deliver_later!(any()) :: no_return() def deliver_later!(_email, _opts \\ []) do raise @cannot_call_directly_error end diff --git a/mix.exs b/mix.exs index 3637e20f..0c395f12 100644 --- a/mix.exs +++ b/mix.exs @@ -21,7 +21,13 @@ defmodule Bamboo.Mixfile do package: package(), docs: docs(), deps: deps(), - xref: [exclude: [IEx]] + xref: [exclude: [IEx]], + dialyzer: [ + plt_add_deps: :app_tree, + ignore_warnings: "dialyzer.ignore-warnings.exs", + plt_add_apps: [:mix, :ex_unit, :iex], + plt_file: {:no_warn, "priv/plts/dialyzer.plt"} + ] ] end @@ -67,7 +73,8 @@ defmodule Bamboo.Mixfile do {:floki, "~> 0.29", only: :test}, {:ex_doc, "~> 0.23", only: :dev}, {:hackney, ">= 1.15.2"}, - {:jason, "~> 1.0", optional: true} + {:jason, "~> 1.0", optional: true}, + {:dialyxir, "~> 1.0", only: [:test, :dev], runtime: false} ] end end diff --git a/mix.lock b/mix.lock index 65dd2dc4..c35f5ed2 100644 --- a/mix.lock +++ b/mix.lock @@ -2,8 +2,10 @@ "certifi": {:hex, :certifi, "2.5.2", "b7cfeae9d2ed395695dd8201c57a2d019c0c43ecaf8b8bcb9320b40d6662f340", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "3b3b5f36493004ac3455966991eaf6e768ce9884693d9968055aeeeb1e575040"}, "cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "f4763bbe08233eceed6f24bc4fcc8d71c17cfeafa6439157c57349aa1bb4f17c"}, "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm", "db622da03aa039e6366ab953e31186cc8190d32905e33788a1acb22744e6abd2"}, + "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, "earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm", "e3be2bc3ae67781db529b80aa7e7c49904a988596e2dbff897425b48b3581161"}, "earmark_parser": {:hex, :earmark_parser, "1.4.10", "6603d7a603b9c18d3d20db69921527f82ef09990885ed7525003c7fe7dc86c56", [:mix], [], "hexpm", "8e2d5370b732385db2c9b22215c3f59c84ac7dda7ed7e544d7c459496ae519c0"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.23.0", "a069bc9b0bf8efe323ecde8c0d62afc13d308b1fa3d228b65bca5cf8703a529d", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f5e2c4702468b2fd11b10d39416ddadd2fcdd173ba2a0285ebd92c39827a5a16"}, "ex_machina": {:hex, :ex_machina, "2.4.0", "09a34c5d371bfb5f78399029194a8ff67aff340ebe8ba19040181af35315eabb", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "a20bc9ddc721b33ea913b93666c5d0bdca5cbad7a67540784ae277228832d72c"}, "excoveralls": {:hex, :excoveralls, "0.13.2", "5ca05099750c086f144fcf75842c363fc15d7d9c6faa7ad323d010294ced685e", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1e7ed75c158808a5a8f019d3ad63a5efe482994f2f8336c0a8c77d2f0ab152ce"}, diff --git a/priv/plts/.gitkeep b/priv/plts/.gitkeep new file mode 100644 index 00000000..e69de29b