Skip to content

Instantly share code, notes, and snippets.

@trbngr
Last active March 24, 2022 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trbngr/13c03554eb2d56078c7e42bc6ee7d18d to your computer and use it in GitHub Desktop.
Save trbngr/13c03554eb2d56078c7e42bc6ee7d18d to your computer and use it in GitHub Desktop.
defmodule ShutUpDialyzer do
defmacro __using__(_opts) do
quote do
@on_definition unquote(__MODULE__)
@before_compile unquote(__MODULE__)
Module.register_attribute(__MODULE__, :funs, accumulate: true)
end
end
def __on_definition__(%{module: module}, :def, name, args, _guards, _body) do
fun = Keyword.new([{name, length(args)}])
Module.put_attribute(module, :funs, fun)
end
defmacro __before_compile__(%{module: module}) do
funs = Module.delete_attribute(module, :funs) |> List.flatten()
Module.put_attribute(module, :dialyzer, {:nowarn_function, funs})
end
end
defmodule SomeModule do
use ShutUpDialyzer
def do_something do
nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment