hrzndhrn/recode

Feature request: list all public functions not used in other modules

Opened this issue · 6 comments

mayel commented

Thinking about deep vs shallow modules (see https://twitter.com/mechanical_monk/status/1581978963399757824) it would be handy to see a list of def that can be changed to defp (probably manually rather than automatically in most cases)

mayel commented

FYI I opened a similar issue in another project where it might be more relevant: https://gitlab.com/bunsan1/archeometer/-/issues/103

Hello @mayel . Great idea. I will give it a try when I have time.

Hi, @NickNeck , If you don't mind, I can try implementing this feature. When I used to work on a very large project, I had the same trouble as mayel.

I'm very interesting in implementing a stable and useful references. I think this feature's logic is very related to the references, we at least need two traversal steps:

  1. to fetch all of references of the whole project and build the mapping between the file and references
  2. traverse the whole project again, check current file's definitions exists in the mapping or not(maybe exclude the *test.exs files). If not, then modify or record that issue in zipper.

Hi, @scottming , a PR is welcome.

Currently recode does not compile the mix project. But for this task it could be useful because we could get all public functions of a module with __info__(:functions). It is always a little bit hard to get all references because we have to take in account that this can come with an alias, alias * as: Foo, use or import. But you can also start with out compiling because you has to traverse the code anyway.

Maybe Recode.Context could be helpful here but I am not sure.

The Rewrite.Source struct has a private field and Rewrite.source.put_private/3 that is the place to store infos on the run. We could add for this feature something like Recode.Task.after_run to have a place to analyse the collected data.

Happy coding.

@mayel have you seen https://hex.pm/packages/mix_unused? I think it does what you're looking for.

mayel commented

Oh thank you @axelson! I think I came across it before but assumed it was about finding unused dependencies. I'll give it a whirl :)