Current section
6 Versions
Jump to
Current section
6 Versions
Compare versions
3
files changed
+34
additions
-12
deletions
| @@ -1,14 +1,14 @@ | |
| 1 | - {<<"app">>,<<"loppers">>}. |
| 2 | - {<<"build_tools">>,[<<"mix">>]}. |
| 1 | + {<<"links">>,[{<<"GitHub">>,<<"https://github.com/narrowtux/loppers">>}]}. |
| 2 | + {<<"name">>,<<"loppers">>}. |
| 3 | + {<<"version">>,<<"1.1.0">>}. |
| 3 4 | {<<"description">>, |
| 4 5 | <<"Validate quoted Elixir AST against a function whitelist">>}. |
| 5 | - {<<"elixir">>,<<"~> 1.4">>}. |
| 6 | + {<<"elixir">>,<<"~> 1.14">>}. |
| 7 | + {<<"app">>,<<"loppers">>}. |
| 8 | + {<<"licenses">>,[<<"MIT">>]}. |
| 9 | + {<<"requirements">>,[]}. |
| 6 10 | {<<"files">>, |
| 7 11 | [<<"lib">>,<<"lib/walk.ex">>,<<"lib/match.ex">>,<<"lib/list.ex">>, |
| 8 12 | <<"lib/validate.ex">>,<<"lib/loppers.ex">>,<<"mix.exs">>,<<"README.md">>, |
| 9 13 | <<"LICENSE">>]}. |
| 10 | - {<<"licenses">>,[<<"MIT">>]}. |
| 11 | - {<<"links">>,[{<<"GitHub">>,<<"https://github.com/narrowtux/loppers">>}]}. |
| 12 | - {<<"name">>,<<"loppers">>}. |
| 13 | - {<<"requirements">>,[]}. |
| 14 | - {<<"version">>,<<"1.0.0">>}. |
| 14 | + {<<"build_tools">>,[<<"mix">>]}. |
| @@ -52,9 +52,31 @@ defmodule Loppers.Match do | |
| 52 52 | # {:map, [context: Elixir, import: Enum], [:a, :b]} |
| 53 53 | |
| 54 54 | def matches?({called_fn, context, _arguments}, {mod, list_fn}) do |
| 55 | - called_module = Keyword.get(context, :import) |
| 55 | + module_candidates = |
| 56 | + cond do |
| 57 | + Keyword.has_key?(context, :import) -> |
| 58 | + [Keyword.get(context, :import)] |
| 59 | + |
| 60 | + Keyword.has_key?(context, :imports) -> |
| 61 | + context |
| 62 | + |> Keyword.get(:imports, []) |
| 63 | + |> Enum.map(&elem(&1, 1)) |
| 64 | + |> Enum.uniq() |
| 65 | + |
| 66 | + true -> |
| 67 | + [] |
| 68 | + end |
| 69 | + |
| 70 | + called_module = List.first(module_candidates) |
| 71 | + |
| 72 | + cond do |
| 73 | + length(module_candidates) > 1 -> false |
| 74 | + length(module_candidates) == 0 -> false |
| 75 | + true -> |
| 76 | + mod == called_module && (list_fn == called_fn || list_fn == :__all__) |
| 77 | + end |
| 78 | + |
| 56 79 | |
| 57 | - mod == called_module && (list_fn == called_fn || list_fn == :__all__) |
| 58 80 | end |
| 59 81 | |
| 60 82 | def matches?(_, _) do |
| @@ -3,8 +3,8 @@ defmodule Loppers.Mixfile do | |
| 3 3 | |
| 4 4 | def project do |
| 5 5 | [app: :loppers, |
| 6 | - version: "1.0.0", |
| 7 | - elixir: "~> 1.4", |
| 6 | + version: "1.1.0", |
| 7 | + elixir: "~> 1.14", |
| 8 8 | build_embedded: Mix.env == :prod, |
| 9 9 | start_permanent: Mix.env == :prod, |
| 10 10 | deps: deps(), |