From e7ee8ae258adc63a93147261c2dba41eecdb3f1e Mon Sep 17 00:00:00 2001 From: Kip Cole Date: Sat, 17 Aug 2024 01:08:27 +1000 Subject: [PATCH] Update specs for a broad range of dialyzer flags --- CHANGELOG.md | 10 ++++++++++ lib/cldr/unit.ex | 15 +++++++++------ lib/cldr/unit/backend.ex | 8 +++++--- lib/cldr/unit_range.ex | 2 +- mix.exs | 13 ++++++++++--- mix.lock | 8 ++++---- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2b751c..b050033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +**Note that `ex_cldr_units` version 3.17.2 and later are supported on Elixir 1.12 and later only.** + +## Cldr_Units v3.17.2 + +This is the changelog for Cldr_units v3.17.2 released on August 16th, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_units/tags) + +### Bug Fixes + +* Fix specs to suport dialyzer flags `:error_handling, :unknown, :underspecs, :extra_return, :missing_return` + ## Cldr_Units v3.17.1 This is the changelog for Cldr_units v3.17.1 released on July 30th, 2024. For older changelogs please consult the release tag on [GitHub](https://github.com/elixir-cldr/cldr_units/tags) diff --git a/lib/cldr/unit.ex b/lib/cldr/unit.ex index d873e0a..3e9237d 100644 --- a/lib/cldr/unit.ex +++ b/lib/cldr/unit.ex @@ -122,7 +122,7 @@ defmodule Cldr.Unit do # Converts a list of atoms into a typespec type = &Enum.reduce(&1, fn x, acc -> {:|, [], [x, acc]} end) - @type translatable_unit :: atom() | list(atom()) + @type translatable_unit :: atom() @type unit :: translatable_unit | String.t() @type category :: atom() @type usage :: atom() @@ -177,6 +177,8 @@ defmodule Cldr.Unit do } """ + @dialyzer {:nowarn_function, known_units_by_category: 0} + @units_by_category @unit_tree |> Map.delete(:compound) |> Map.delete(:coordinate) @@ -238,7 +240,7 @@ defmodule Cldr.Unit do """ @unit_categories Map.keys(@units_by_category) |> Enum.sort() - @spec known_unit_categories :: list(category()) + @spec known_unit_categories :: [category(), ...] def known_unit_categories do @unit_categories end @@ -1490,7 +1492,7 @@ defmodule Cldr.Unit do details. """ - @spec localize(t()) :: [t(), ...] + @spec localize(t()) :: [t(), ...] | {:error, {module(), String.t()}} def localize(%Unit{} = unit) do locale = Cldr.get_locale() backend = locale.backend @@ -1542,7 +1544,7 @@ defmodule Cldr.Unit do ] """ - @spec localize(t(), Cldr.backend(), Keyword.t()) :: [t(), ...] + @spec localize(t(), Cldr.backend(), Keyword.t()) :: [t(), ...] | {:error, {module(), String.t()}} def localize(unit, backend, options \\ []) def localize(%Unit{} = unit, options, []) when is_list(options) do @@ -1879,7 +1881,7 @@ defmodule Cldr.Unit do [:astronomical, :jpsystem, :metric, :metric_adjacent, :person_age, :prefixable, :si, :si_acceptable, :uksystem, :ussystem] """ - @spec known_measurement_systems() :: list(measurement_system()) + @spec known_measurement_systems() :: [measurement_system(), ...] def known_measurement_systems do @system_names end @@ -2101,7 +2103,7 @@ defmodule Cldr.Unit do |> Enum.map(fn {k, v} -> {Kernel.to_string(v), k} end) |> Map.new() - @spec base_unit_category_map :: map() + @spec base_unit_category_map :: %{String.t() => category( )} def base_unit_category_map do @base_unit_category_map end @@ -2262,6 +2264,7 @@ defmodule Cldr.Unit do :long """ + @dialyzer {:nowarn_function, default_style: 0} @spec default_style :: style() def default_style do @default_style diff --git a/lib/cldr/unit/backend.ex b/lib/cldr/unit/backend.ex index ac4d344..11056a5 100644 --- a/lib/cldr/unit/backend.ex +++ b/lib/cldr/unit/backend.ex @@ -432,7 +432,7 @@ defmodule Cldr.Unit.Backend do details. """ - @spec localize(Cldr.Unit.t()) :: [Cldr.Unit.t(), ...] + @spec localize(Cldr.Unit.t()) :: [Cldr.Unit.t(), ...] | {:error, {module, String.t()}} def localize(%Cldr.Unit{} = unit) do Cldr.Unit.localize(unit) end @@ -479,7 +479,9 @@ defmodule Cldr.Unit.Backend do ] """ - @spec localize(Cldr.Unit.t(), Keyword.t()) :: [Cldr.Unit.t(), ...] + @spec localize(Cldr.Unit.t(), Keyword.t()) :: + [Cldr.Unit.t(), ...] | {:error, {module, String.t()}} + def localize(unit, options \\ []) do Cldr.Unit.localize(unit, unquote(backend), options) end @@ -829,7 +831,7 @@ defmodule Cldr.Unit.Backend do """ @spec preferred_units(Cldr.Unit.t(), Keyword.t()) :: - {:ok, String.t()} | {:error, {module, binary}} + {:ok, [atom(), ...], Keyword.t()} | {:error, {module, binary}} def preferred_units(unit, options \\ []) do Cldr.Unit.Preference.preferred_units(unit, unquote(backend), options) diff --git a/lib/cldr/unit_range.ex b/lib/cldr/unit_range.ex index c5ce6e2..fc9f6a8 100644 --- a/lib/cldr/unit_range.ex +++ b/lib/cldr/unit_range.ex @@ -22,7 +22,7 @@ defmodule Cldr.Unit.Range do as the first unit. """ - @type t :: %{first: Cldr.Unit.t(), last: Cldr.Unit.t()} + @type t :: %__MODULE__{first: Cldr.Unit.t(), last: Cldr.Unit.t()} @doc """ Returns a new Cldr.Unit.Range. diff --git a/mix.exs b/mix.exs index ea6161b..64a3a50 100644 --- a/mix.exs +++ b/mix.exs @@ -1,13 +1,13 @@ defmodule Cldr.Units.Mixfile do use Mix.Project - @version "3.17.1" + @version "3.17.2" def project do [ app: :ex_cldr_units, version: @version, - elixir: "~> 1.11", + elixir: "~> 1.12", name: "Cldr Units", source_url: "https://github.com/elixir-cldr/cldr_units", description: description(), @@ -19,7 +19,14 @@ defmodule Cldr.Units.Mixfile do elixirc_paths: elixirc_paths(Mix.env()), dialyzer: [ ignore_warnings: ".dialyzer_ignore_warnings", - plt_add_apps: ~w(inets jason mix)a + plt_add_apps: ~w(inets jason mix)a, + flags: [ + :error_handling, + :unknown, + :underspecs, + :extra_return, + :missing_return + ] ] ] end diff --git a/mix.lock b/mix.lock index a146365..dbbef99 100644 --- a/mix.lock +++ b/mix.lock @@ -1,16 +1,16 @@ %{ "benchee": {:hex, :benchee, "1.3.1", "c786e6a76321121a44229dde3988fc772bca73ea75170a73fd5f4ddf1af95ccf", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}, {:statistex, "~> 1.0", [hex: :statistex, repo: "hexpm", optional: false]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "76224c58ea1d0391c8309a8ecbfe27d71062878f59bd41a390266bf4ac1cc56d"}, - "cldr_utils": {:hex, :cldr_utils, "2.28.0", "ce309d11b79fc13e1f22f808b5e3c1647102b01b11734ca8cb0296ca6d406fe4", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "e7ac4bcea0fdbc11b5295ef30dd7b18d0922512399361af06a97198e57d23742"}, + "cldr_utils": {:hex, :cldr_utils, "2.28.1", "3d85c835e1d0b7bceb9feed1647025ff7df59180246f13b582422f12b1afd52c", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: true]}, {:decimal, "~> 1.9 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "79a5f645481d09b1372962384aa275d67d69273e73e3b38a9fee363eb57c2b79"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, "digital_token": {:hex, :digital_token, "0.6.0", "13e6de581f0b1f6c686f7c7d12ab11a84a7b22fa79adeb4b50eec1a2d278d258", [:mix], [{:cldr_utils, "~> 2.17", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "2455d626e7c61a128b02a4a8caddb092548c3eb613ac6f6a85e4cbb6caddc4d1"}, "earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"}, "erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"}, - "ex_cldr": {:hex, :ex_cldr, "2.40.0", "624717778dbf0a8cd307f1576eabbd44470c16190172abf293fed24150440a5a", [:mix], [{:cldr_utils, "~> 2.28", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}], "hexpm", "113394b6dd23aaf7912da583aab103d9cf082b9821bc4a6e287543a895af7cb4"}, + "ex_cldr": {:hex, :ex_cldr, "2.40.1", "c1fcb0cd9d2a70d28f4540a99f32127e7f1813e0db109d65ab29dea5337ae266", [:mix], [{:cldr_utils, "~> 2.28", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}], "hexpm", "509810702e8e81991851d9426ffe6b34b48b7b9baa12922e7b3fb8f6368606f3"}, "ex_cldr_currencies": {:hex, :ex_cldr_currencies, "2.16.2", "670d96cc4fb18cfebd82488ed687742683be2d0725d66ec051578d4b13539aa8", [:mix], [{:ex_cldr, "~> 2.38", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "2ccfac2838f4df8c8e5424dbc68eb2f3ac9eeb45e10365050901f7ac7a914ce1"}, - "ex_cldr_lists": {:hex, :ex_cldr_lists, "2.11.0", "1d39e75f0e493ccc95adfc85c55b4ca34f0771626350ce326d9ab8813d91444e", [:mix], [{:ex_cldr_numbers, "~> 2.25", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:ex_doc, "~> 0.18", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "8132b30a5506ae8a09e5c9a21c23fd60c8837ce6c3a1de9966d813eb78951695"}, - "ex_cldr_numbers": {:hex, :ex_cldr_numbers, "2.33.2", "c5587a8d84214d9cc42e7827e4c3bed2aa9e52505a55b10540020725954ded2c", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:digital_token, "~> 0.3 or ~> 1.0", [hex: :digital_token, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 2.38", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_currencies, "~> 2.16", [hex: :ex_cldr_currencies, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "49f1dbaddc1ad6e3f496a97fa425d25b3ae89e8178ce0416d9909deaf2e5ad80"}, + "ex_cldr_lists": {:hex, :ex_cldr_lists, "2.11.1", "ad18f861d7c5ca82aac6d173469c6a2339645c96790172ab0aa255b64fb7303b", [:mix], [{:ex_cldr_numbers, "~> 2.25", [hex: :ex_cldr_numbers, repo: "hexpm", optional: false]}, {:ex_doc, "~> 0.18", [hex: :ex_doc, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "00161c04510ccb3f18b19a6b8562e50c21f1e9c15b8ff4c934bea5aad0b4ade2"}, + "ex_cldr_numbers": {:hex, :ex_cldr_numbers, "2.33.3", "9fedcf279a17d19abdf8872738472326e82378d90ec2dd9756a0c84558c86b36", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:digital_token, "~> 0.3 or ~> 1.0", [hex: :digital_token, repo: "hexpm", optional: false]}, {:ex_cldr, "~> 2.38", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:ex_cldr_currencies, "~> 2.16", [hex: :ex_cldr_currencies, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "4a0d90d06710c1499528d5f536c539379a73a68d4679c55375198a798d138442"}, "ex_doc": {:hex, :ex_doc, "0.34.2", "13eedf3844ccdce25cfd837b99bea9ad92c4e511233199440488d217c92571e8", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "5ce5f16b41208a50106afed3de6a2ed34f4acfd65715b82a0b84b49d995f95c1"}, "jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"}, "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"},