Mix compiler tracer for detecting unused public functions.
def deps do
[
{:mix_unused, "~> 0.3.0"}
]
end
The docs can be found at https://hexdocs.pm/mix_unused.
After installation you need to add :unused
as a compiler to the list of Mix
compilers:
defmodule MySystem.MixProject do
use Mix.Project
def project do
[
compilers: [:unused] ++ Mix.compilers(),
# In case of Phoenix projects you need to add it to the list
# compilers: [:unused, :phoenix, :gettext] ++ Mix.compilers()
# ...
#
# If you want to only run it in the dev environment you could do
# it by using `compilers: compilers(Mix.env()) ++ Mix.compilers()`
# instead and then returning the right compilers per environment.
]
end
# ...
end
Then you just need to run mix compile
or mix compile --force
as usual
and unused hints will be added to the end of the output.
This isn't perfect solution and this will not find dynamic calls in form of:
apply(mod, func, args)
So this mean that, for example, if you have custom child_spec/1
definition
then mix unused
can return such function as unused even when you are using
that indirectly in your supervisor.
You can define used functions by adding mfa
in unused: [ignored: [⋯]]
in your project configuration:
def project do
[
# ⋯
unused: [
ignore: [
{MyApp.Foo, :child_spec, 1}
]
],
# ⋯
]
end
Copyright © 2021 by Łukasz Niemier
This work is free. You can redistribute it and/or modify it under the terms of the MIT License. See the LICENSE file for more details.