Could cabal warn about unused package in dependencies?

For given cabal project how could unused dependencies packages be retrieved?

Is there a way to get something like warning during cabal install process if there is a package mentioned in project dependency and there is no any usage of it, so it could be removed from dependencies?

Upvotes: 24

Views: 2048

Answers (4)

Ignat Insarov
Ignat Insarov

Reputation: 4832

There are some options:

  • For GHC 8.6 and earlier, Weeder version 1 by Neil Mitchell can find unused dependencies.
  • For GHC 8.10 and later, there is a warning GHC may emit (with the GHC option -Wunused-packages) when it sees unnecessary packages in the package database. Since Cabal prepares the package database, any unnecessary package is an unused dependency.

Unfortunately, GHC 8.8 is left out.

P. S.   There was recently released a program called prune-juice that should work for GHC 8.8 too.

Upvotes: 8

nponeccop
nponeccop

Reputation: 13677

There is yet another tool:

https://github.com/ndmitchell/weeder https://hackage.haskell.org/package/weeder

It's not yet on Stackage though

Upvotes: 1

LambdaStaal
LambdaStaal

Reputation: 557

I think the program packunused is what you are looking for.

Upvotes: 8

Gabriel Riba
Gabriel Riba

Reputation: 6738

cabal-progdeps lists dependencies once the cabal project has been built.

You can check if thay are all used by adding an unused one to your project.

It requires the same Cabal library version used in cabal-install, otherwise it gives errors parsing dist/setup-config.

Upvotes: 2

Related Questions