diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a09010..baf4e2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Elixir 1.16 to CI - OTP 26.2 to CI +### Fixed + +- Credo warnings about [predicate function + names](https://hexdocs.pm/credo/Credo.Check.Readability.PredicateFunctionNames.html) + ## [0.1.2] - 2023-11-04 ### Added diff --git a/lib/sqids.ex b/lib/sqids.ex index e19c7f4..9a5d66d 100644 --- a/lib/sqids.ex +++ b/lib/sqids.ex @@ -206,7 +206,7 @@ defmodule Sqids do end defp validate_numbers(numbers) do - Enum.find(numbers, &(not is_valid_number(&1))) + Enum.find(numbers, &(not valid_number?(&1))) catch :error, %Protocol.UndefinedError{value: ^numbers} -> {:error, {:numbers_not_enumerable, numbers}} @@ -219,7 +219,7 @@ defmodule Sqids do {:error, {:number_is_not_a_non_negative_integer, invalid_number}} end - defp is_valid_number(number), do: is_integer(number) and number >= 0 + defp valid_number?(number), do: is_integer(number) and number >= 0 # if no numbers passed, return an empty string @spec encode_numbers(t(), [non_neg_integer]) :: {:ok, String.t()} | {:error, term} @@ -267,7 +267,7 @@ defmodule Sqids do id = handle_min_length_requirement(id_iodata, alphabet, sqids.min_length) - if Blocklist.is_blocked_id(sqids.blocklist, id) do + if Blocklist.blocked_id?(sqids.blocklist, id) do # ID has a blocked word, restart with a +1 attempt_index attempt_to_encode_numbers(sqids, list, attempt_index + 1) else @@ -391,7 +391,7 @@ defmodule Sqids do end defp are_all_chars_in_id_known(id, alphabet) do - id |> String.graphemes() |> Enum.all?(&Alphabet.is_known_symbol(alphabet, &1)) + id |> String.graphemes() |> Enum.all?(&Alphabet.known_symbol?(alphabet, &1)) end @spec decode(t(), String.t()) :: {:ok, [non_neg_integer]} diff --git a/lib/sqids/alphabet.ex b/lib/sqids/alphabet.ex index 56739ff..0ce5667 100644 --- a/lib/sqids/alphabet.ex +++ b/lib/sqids/alphabet.ex @@ -94,12 +94,12 @@ defmodule Sqids.Alphabet do Enum.reduce((size - 1)..0, _acc = [], fn index, acc -> [char_at!(alphabet, index) | acc] end) end - @spec is_known_symbol(t(), String.t()) :: boolean - def is_known_symbol(%{} = alphabet, <>) do + @spec known_symbol?(t(), String.t()) :: boolean + def known_symbol?(%{} = alphabet, <>) do Enum.any?(alphabet, fn {_index, char} -> arg_char === char end) end - def is_known_symbol(%{} = _alphabet, multibyte) when byte_size(multibyte) > 1 do + def known_symbol?(%{} = _alphabet, multibyte) when byte_size(multibyte) > 1 do false end diff --git a/lib/sqids/blocklist.ex b/lib/sqids/blocklist.ex index 3f3f769..2d75ecf 100644 --- a/lib/sqids/blocklist.ex +++ b/lib/sqids/blocklist.ex @@ -32,8 +32,8 @@ defmodule Sqids.Blocklist do end end - @spec is_blocked_id(t(), String.t()) :: boolean() - def is_blocked_id(%__MODULE__{} = blocklist, id) do + @spec blocked_id?(t(), String.t()) :: boolean() + def blocked_id?(%__MODULE__{} = blocklist, id) do downcased_id = String.downcase(id) downcased_size = byte_size(downcased_id) diff --git a/test/sqids_test.exs b/test/sqids_test.exs index 9ac2972..8203d8e 100644 --- a/test/sqids_test.exs +++ b/test/sqids_test.exs @@ -584,7 +584,7 @@ defmodule SqidsTest do test "Blocklist: short words are not blocked" do alphabet_str = "abc" {:ok, blocklist} = Sqids.Blocklist.new(["abc"], _min_word_length = 4, alphabet_str) - refute Sqids.Blocklist.is_blocked_id(blocklist, "abc") + refute Sqids.Blocklist.blocked_id?(blocklist, "abc") end test "Stopped agent" do