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
@moduledoc false
@spec normalize(binary()) :: binary()
def normalize(string) do
string

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,4 +1,6 @@
defmodule IbanEx.Parser do
@moduledoc false
alias IbanEx.{Country, Iban, Validator}
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()
def parse({:ok, iban_string}), do: parse(iban_string)
def parse(iban_string) do
with {:ok, valid_iban} <- Validator.validate(iban_string) do
iban_map = %{
country_code: country_code(valid_iban),
check_digits: check_digits(valid_iban),
}
case Validator.validate(iban_string) do
{:ok, valid_iban} ->
iban_map = %{
country_code: country_code(valid_iban),
check_digits: check_digits(valid_iban)
}
regex = Country.country_module(iban_map.country_code).rule()
bban = bban(iban_string)
bban_map = for {key, val} <- Regex.named_captures(regex, bban), into: %{}, do: {String.to_atom(key), val}
regex = Country.country_module(iban_map.country_code).rule()
bban = bban(iban_string)
{:ok, struct(Iban, Map.merge(iban_map, bban_map))}
else
{:error, error_type} -> {:error, error_type}
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))}
{:error, error_type} ->
{:error, error_type}
end
end

View File

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

View File

@ -1,9 +1,11 @@
defmodule IbanEx.Validator do
@moduledoc false
alias IbanEx.{Country, Parser}
alias IbanEx.Validator.Replacements
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
cond do
iban_violates_format?(iban) ->