From 10bf18971db8d9c325a0ca089a49034885bdcd45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Wojtasik?= Date: Wed, 9 Mar 2022 14:30:37 +0100 Subject: [PATCH] Filter out generated functions/specs following __name__ pattern --- lib/gradient/elixir_checker.ex | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/gradient/elixir_checker.ex b/lib/gradient/elixir_checker.ex index 19aae0da..564afdad 100644 --- a/lib/gradient/elixir_checker.ex +++ b/lib/gradient/elixir_checker.ex @@ -52,7 +52,7 @@ defmodule Gradient.ElixirChecker do |> Stream.filter(&is_fun_or_spec?/1) |> Stream.map(&simplify_form/1) |> Stream.concat() - |> Stream.filter(&has_line/1) + |> Stream.filter(&is_not_generated?/1) |> Enum.sort(&(elem(&1, 2) < elem(&2, 2))) |> Enum.reduce({nil, []}, fn {:fun, fna, _} = fun, {{:spec, {n, a} = sna, anno}, errors} when fna != sna -> @@ -70,8 +70,11 @@ defmodule Gradient.ElixirChecker do |> Enum.map(&{file, &1}) end - # Filter out __info__ generated function - def has_line(form), do: :erl_anno.line(elem(form, 2)) > 1 + # Filter out __info__ and other generated functions with the same name pattern + def is_not_generated?({_, {name, _}, _}) do + name_str = Atom.to_string(name) + not (String.starts_with?(name_str, "__") and String.ends_with?(name_str, "__")) + end def is_fun_or_spec?({:attribute, _, :spec, _}), do: true def is_fun_or_spec?({:function, _, _, _, _}), do: true