kkempin / exiban

Elixir library for validation and manipulating IBAN bank account numbers.
MIT License
10 stars 11 forks source link

Variable rules does not exist #5

Open pmontrasio opened 3 years ago

pmontrasio commented 3 years ago

With both Erlang 21.2.6 / Elixir 1.7.4-otp-21 and Erlang 23.2 / Elixir 1.11.4:

warning: variable "rules" does not exist and is being expanded to "rules()", please use parentheses to remove the ambiguity or change the variable name
  lib/exiban/validators.ex:56: ExIban.Validators.check_country_code/1

warning: variable "rules" does not exist and is being expanded to "rules()", please use parentheses to remove the ambiguity or change the variable name
  lib/exiban/validators.ex:65: ExIban.Validators.check_length/1

warning: variable "rules" does not exist and is being expanded to "rules()", please use parentheses to remove the ambiguity or change the variable name
  lib/exiban/validators.ex:73: ExIban.Validators.check_format/1

That rules should probably be ExIban.Rules.rules/0 .

For some reasons the import ExiIban.Rules at the top of the file doesn't work. This patch fixes the problem:

diff --git a/lib/exiban/validators.ex b/lib/exiban/validators.ex
index 78cc154..66d3299 100644
--- a/lib/exiban/validators.ex
+++ b/lib/exiban/validators.ex
@@ -3,7 +3,6 @@ defmodule ExIban.Validators do
   Set of validation rules to perform on checking IBAN account number.
   """

-  import ExIban.Rules
   import ExIban.Parser

   @doc """
@@ -53,7 +52,7 @@ defp check_chars({_, _, _, _, iban} = parsed_iban) do

   defp check_country_code({errors, {country_code, _, _, _, _} = parsed_iban}) do
     cond do
-      rules |> Map.get(country_code) |> is_nil ->
+      ExIban.Rules.rules |> Map.get(country_code) |> is_nil ->
         {errors ++ [:unknown_country_code], parsed_iban}
       true -> {errors, parsed_iban}
     end
@@ -62,7 +61,7 @@ defp check_country_code({errors, {country_code, _, _, _, _} = parsed_iban}) do
   defp check_length({errors,
     {country_code, _, _, iban_length, _} = parsed_iban}) do
     cond do
-      rules |> Map.get(country_code, %{}) |> Map.get("length") != iban_length ->
+      ExIban.Rules.rules |> Map.get(country_code, %{}) |> Map.get("length") != iban_length ->
         {errors ++ [:bad_length], parsed_iban}
       true -> {errors, parsed_iban}
     end
@@ -70,7 +69,7 @@ defp check_length({errors,

   defp check_format({errors,
     {country_code, _, bban, _, _} = parsed_iban}) do
-    {:ok, reg} = rules
+    {:ok, reg} = ExIban.Rules.rules
                   |> Map.get(country_code, %{})
                   |> Map.get("bban_pattern", "")
                   |> Regex.compile

I didn't try the code with older versions of Erlang and Elixir.

All tests pass both with and without the fix. That's strange.

pmontrasio commented 3 years ago

I opened PR https://github.com/kkempin/exiban/pull/6 to fix the issue and two deprecation warnings.

kkempin commented 3 years ago

Thanks @pmontrasio! I'll take a look!