Skip to content

Commit

Permalink
Heed new warnings from credo 1.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
g-andrade committed Jan 1, 2024
1 parent a50a9e5 commit d5aeb85
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/sqids.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]}
Expand Down
6 changes: 3 additions & 3 deletions lib/sqids/alphabet.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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, <<arg_char>>) do
@spec known_symbol?(t(), String.t()) :: boolean
def known_symbol?(%{} = alphabet, <<arg_char>>) 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

Expand Down
4 changes: 2 additions & 2 deletions lib/sqids/blocklist.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion test/sqids_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d5aeb85

Please sign in to comment.