-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
ft: add an alternative analyzer to detect unused code #42
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Thomas Alderighi <[email protected]>
No feedback received, so long and thanks for all the fish! |
Hey @hauleth! 👋 I've taken over maintaining our (Prima.it) fork and I was wondering if this PR could still be useful to merge |
I will take a look today and will see. |
Hello! Any news? |
I will look at it today. I was highly occupied with my |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to view it as a 2 separate PRs - one that adds option for more configuration options, and separate with the unreachable
analyser.
When I was creating mix_unused
the idea behind MixUnused.Analyze
was that it would support externally implemented analysers. So this Unreachable
analyser could be library like mix_unused_unreachable
. I would need to think whether this particular analyser is useful outside of projects like Phoenix to make it part of the core.
Don't understand me wrong, it looks useful, it is just that additional code will push maintenance burden to me, and as you may have noticed, I often have other stuff that I need to maintain and I would want to avoid having such issues stalled again.
I completely understand and thanks for looking into this 😄 I will open separate PRs and once we actually have the one on the unreachable analyzer we can see if it's actually useful to integrate it in the core or may extract it in a library, does that make sense? |
Yes, that would be awesome. |
Hello @hauleth, we at Prima.it are using mix_unused in our Elixir services.
This is a simplified PR that excludes all the discovery modules included in the previous one.
We found some issues with the current implementation, which marked as unused lots of code, depending on the application's design.
We explored a different approach which could make the results more reliable when used properly.
Although the PR is a bit fat, most of the changes are additive and the rest is of course backward compatible.
Summary
MixUnused.Analyzers.Unreachable
analyzer, alternative to theUnused
one;paths
configuration option to report only functions defined in such paths (i.e. to hide code made only for tests purposes);limit
configuration option to report only a limited number of functions;checks
options overridable, so that the user can enable the "unreachable" analyzer;MIX_UNUSED_DEBUG
env var is set totrue
.The "unreachable" analyzer
It just analyses the calls graph finding all the functions that are reachable from a specific set of well-known used functions. This makes the analysis simple and deterministic.
The analyzer requires the user to specify the set of usages, or "usages-discovery" (modules that try to discover dynamically-called functions - for instance by reading the application config or by analyze the source code).
Unreachable
has some differences fromUnused
:Please look at the
README.md
andguides/unreachable-analyzer.md
for further details.