unused-code / unused

A tool to identify potentially unused code.
https://unused.codes
MIT License
283 stars 11 forks source link

unused_rs should filter results based on current directory #14

Open milmazz opened 4 years ago

milmazz commented 4 years ago

I just tried to emulate a monorepo structure with two Phoenix applications and I was expecting the following behaviors:

Here is the way I did it in case you want to replicate the issue:

$ mkdir /tmp/demo 
$ cd /tmp/demo/
$ mix phx.new app1 --no-ecto
$ cd app1
$ mix phx.server # just to check that the app works
$ cd ..
$ mix phx.new app2 --no-html --no-webpack
$ cd app2
$ mix ecto.create
$ mix phx.server # just to check that the app works
$ cd ..
$ git init
$ git add .
$ git commit -m "initial structure"
$ git ctags
$ ls .git/tags
.git/tags

Then, here are the results:

$ pwd
/tmp/demo
$ ~/Dev/rust/unused_rs/target/debug/unused-rs -l high --format compact
LayoutView            app1/lib/app1_web/views/layout_view.ex                     Only one occurrence exists
LayoutViewTest        app1/test/app1_web/views/layout_view_test.exs              Only one occurrence exists
PageControllerTest    app1/test/app1_web/controllers/page_controller_test.exs    Only one occurrence exists
PageView              app1/lib/app1_web/views/page_view.ex                       Only one occurrence exists
PageViewTest          app1/test/app1_web/views/page_view_test.exs                Only one occurrence exists
error_tag             app1/lib/app1_web/views/error_helpers.ex                   Only one occurrence exists

In the previous command, I just see the results for app1, it should have included the results for app2 too.

$ cd app1/
$ ~/Dev/rust/unused_rs/target/debug/unused-rs -l high --format compact
ErrorViewTest         app2/test/app2_web/views/error_view_test.exs               Only one occurrence exists
LayoutView            app1/lib/app1_web/views/layout_view.ex                     Only one occurrence exists
LayoutViewTest        app1/test/app1_web/views/layout_view_test.exs              Only one occurrence exists
MixProject            app2/mix.exs                                               Only one occurrence exists
PageControllerTest    app1/test/app1_web/controllers/page_controller_test.exs    Only one occurrence exists
PageView              app1/lib/app1_web/views/page_view.ex                       Only one occurrence exists
PageViewTest          app1/test/app1_web/views/page_view_test.exs                Only one occurrence exists
Repo                  app2/lib/app2/repo.ex                                      Only one occurrence exists
__using__             app1/lib/app1_web.ex                                       Only one occurrence exists
error_tag             app1/lib/app1_web/views/error_helpers.ex                   Only one occurrence exists
template_not_found    app2/lib/app2_web/views/error_view.ex                      Only one occurrence exists

In the previous output, I was expecting only results for the app1, but, as you can see, results for app2 are included.

$ cd ../app2/
$ ~/Dev/rust/unused_rs/target/debug/unused-rs -l high --format compact
ErrorViewTest         app2/test/app2_web/views/error_view_test.exs    Only one occurrence exists
MixProject            app1/mix.exs                                    Only one occurrence exists
__using__             app1/lib/app1_web.ex                            Only one occurrence exists
template_not_found    app1/lib/app1_web/views/error_view.ex           Only one occurrence exists
translate_error       app2/lib/app2_web/views/error_helpers.ex        Only one occurrence exists

In the previous output, I was expecting only results for the app2, but, as you can see, results for app1 are included.

The unused_rs that I'm using was built using cargo build and using the commit 8b4f82220037710bb73c8165efb2444bb15b617a