Credo warning fast fixes (disable module docs)

This commit is contained in:
Danil Negrienko 2024-03-07 18:39:33 -05:00
parent 1a9d6758fd
commit 390036bafb
9 changed files with 36 additions and 17 deletions

View File

@ -1,4 +1,6 @@
defmodule IbanEx.Commons do defmodule IbanEx.Commons do
@moduledoc false
@spec normalize(binary()) :: binary() @spec normalize(binary()) :: binary()
def normalize(string) do def normalize(string) do
string string

View File

@ -1,4 +1,6 @@
defmodule IbanEx.Country do defmodule IbanEx.Country do
@moduledoc false
import IbanEx.Commons, only: [normalize: 1] import IbanEx.Commons, only: [normalize: 1]
@type country_code() :: <<_::16>> | atom() @type country_code() :: <<_::16>> | atom()

View File

@ -7,8 +7,8 @@ end
defimpl IbanEx.Deserialize, for: [BitString, String] do defimpl IbanEx.Deserialize, for: [BitString, String] do
alias IbanEx.{Parser, Error} alias IbanEx.{Parser, Error}
@type iban_or_error() :: IbanEx.Iban.t() | {:error, atom()} @type iban_or_error() :: IbanEx.Iban.t() | {:error, atom()}
@spec to_iban(binary()) :: iban_or_error()
@spec to_iban(String.t()) :: iban_or_error() @spec to_iban(String.t()) :: iban_or_error()
@spec to_iban(binary()) :: IbanEx.Iban.t()
def to_iban(string) do def to_iban(string) do
case Parser.parse(string) do case Parser.parse(string) do
{:ok, iban} -> iban {:ok, iban} -> iban

View File

@ -1,7 +1,5 @@
defmodule IbanEx.Error do defmodule IbanEx.Error do
@moduledoc """ @moduledoc false
"""
@type error() :: @type error() ::
:unsupported_country_code :unsupported_country_code

View File

@ -1,4 +1,6 @@
defmodule IbanEx.Formatter do defmodule IbanEx.Formatter do
@moduledoc false
alias IbanEx.Country alias IbanEx.Country
import IbanEx.Commons, only: [normalize: 1] import IbanEx.Commons, only: [normalize: 1]
@ -28,7 +30,7 @@ defmodule IbanEx.Formatter do
def format(iban, :pretty) do def format(iban, :pretty) do
country_module = Country.country_module(iban.country_code) country_module = Country.country_module(iban.country_code)
country_module.to_s(iban) country_module.to_string(iban)
end end
def format(iban, :splitted) do def format(iban, :splitted) do

View File

@ -1,4 +1,6 @@
defmodule IbanEx.Iban do defmodule IbanEx.Iban do
@moduledoc false
alias IbanEx.Formatter alias IbanEx.Formatter
alias IbanEx.{Serialize} alias IbanEx.{Serialize}

View File

@ -1,4 +1,6 @@
defmodule IbanEx.Parser do defmodule IbanEx.Parser do
@moduledoc false
alias IbanEx.{Country, Iban, Validator} alias IbanEx.{Country, Iban, Validator}
import IbanEx.Commons, only: [normalize_and_slice: 2] import IbanEx.Commons, only: [normalize_and_slice: 2]
@ -9,20 +11,27 @@ defmodule IbanEx.Parser do
@spec parse({:ok, String.t()} | String.t()) :: iban_or_error() @spec parse({:ok, String.t()} | String.t()) :: iban_or_error()
def parse({:ok, iban_string}), do: parse(iban_string) def parse({:ok, iban_string}), do: parse(iban_string)
def parse(iban_string) do def parse(iban_string) do
with {:ok, valid_iban} <- Validator.validate(iban_string) do case Validator.validate(iban_string) do
iban_map = %{ {:ok, valid_iban} ->
country_code: country_code(valid_iban), iban_map = %{
check_digits: check_digits(valid_iban), country_code: country_code(valid_iban),
} check_digits: check_digits(valid_iban)
}
regex = Country.country_module(iban_map.country_code).rule() regex = Country.country_module(iban_map.country_code).rule()
bban = bban(iban_string) bban = bban(iban_string)
bban_map = for {key, val} <- Regex.named_captures(regex, bban), into: %{}, do: {String.to_atom(key), val}
{:ok, struct(Iban, Map.merge(iban_map, bban_map))} bban_map =
else for {key, val} <- Regex.named_captures(regex, bban),
{:error, error_type} -> {:error, error_type} into: %{},
do: {String.to_atom(key), val}
{:ok, struct(Iban, Map.merge(iban_map, bban_map))}
{:error, error_type} ->
{:error, error_type}
end end
end end

View File

@ -1,4 +1,6 @@
defmodule IbanEx.Serialize do defmodule IbanEx.Serialize do
@moduledoc false
alias IbanEx.{Iban, Formatter} alias IbanEx.{Iban, Formatter}
@spec to_string(Iban.t()) :: String.t() @spec to_string(Iban.t()) :: String.t()

View File

@ -1,9 +1,11 @@
defmodule IbanEx.Validator do defmodule IbanEx.Validator do
@moduledoc false
alias IbanEx.{Country, Parser} alias IbanEx.{Country, Parser}
alias IbanEx.Validator.Replacements alias IbanEx.Validator.Replacements
import IbanEx.Commons, only: [normalize: 1] import IbanEx.Commons, only: [normalize: 1]
@spec validate(String.t()) :: {:ok, String.t()} | {:error} @spec validate(String.t()) :: {:ok, String.t()} | {:error, Atom.t()}
def validate(iban) do def validate(iban) do
cond do cond do
iban_violates_format?(iban) -> iban_violates_format?(iban) ->