Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable rules does not exist #5

Open
pmontrasio opened this issue Apr 6, 2021 · 2 comments
Open

Variable rules does not exist #5

pmontrasio opened this issue Apr 6, 2021 · 2 comments

Comments

@pmontrasio
Copy link
Contributor

pmontrasio commented Apr 6, 2021

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
Copy link
Contributor Author

I opened PR #6 to fix the issue and two deprecation warnings.

@kkempin
Copy link
Owner

kkempin commented Apr 6, 2021

Thanks @pmontrasio! I'll take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants