Packwerk: Unused Dependencies Detected?

This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.

Does Packwerk detect unused dependencies?
• A depends on B
• I remove all references to B from A
• A’s package.yml still references B in the dependencies section
Is this reported as an error somewhere?

No it doesn’t. This is because to detect unused dependencies, we need:

all_declared_dependencies - all_used_dependencies

While the former is easy to get, the latter is not easy to get with packwerk’s current design.

Packwerk checkers do not, by default, collect any state about what dependencies are used. If it detects a dependency is used but it is not a violation, it throws away that data.

We’d need some way for checkers to collect the dependencies used.

I had spiked on this in the past and it actually kind of works: https://github.com/rubyatscale/packwerk-extensions/pull/30

It works by having a checker which keeps state in a tmp file, and then validate reads that file to fail if there are unused dependencies.

I didn’t end up shipping it because it ended up feeling like it had really awkward ergonomics, but if you or anyone wants to take it over the line and publish it as experimental I’d be down.

It could be useful for us I think. I’ll run it by the team, thanks Alex!

FYI –

I just added a command list-unnecessary-dependencies to packs!

oh wow that’s great! thank you!