dfithian / prune-juice

Prune unused Haskell dependencies.
MIT License
48 stars 4 forks source link

Fix sublib parser #23

Closed dbalseiro closed 2 years ago

dbalseiro commented 2 years ago

Hey @dfithian thanks for this tool :smile: I use it quite often.

I had trouble working with projects using sub libraries. I think I fixed the issue and thought about sending the fix upstream.

I made this repo to replicate the issue.

The error I got is the following:

$ prune-juice
Failed to parse cabal sections for ./prune-juice-fixture.cabal l due to ParseErrorBundle {bundleErrors = TrivialError 854 (Just (...

and a long error message. I first added a more legible error message using megaparsec pretty print, so now you have this:

$ prune-juice
Failed to parse cabal sections for ./prune-juice-fixture.cabal due to 39:9:
   |
39 | library prune-juice-fixture-common
   |         ^^
unexpected "pr"
expecting end of line or white space

Some unused base dependencies for package prune-juice-fixture
  prune-juice-fixture-common

That line is valid, but the parser didn't identify a sublibrary correctly. Basically, it tried to parse the main library instead a sub-library. So I fixed the parser. Now it can parse sublibraries in the cabal file

Also, as you can see, the dependencies parser incorrectly marked the sub-lib as unused, even though it is being used. This happened because it was giving the same name (package name) to both the main library and the sub library. So I fixed that too.

This PR should also fix issue #22

If you have any comments, please let me know. Thanks!

dfithian commented 2 years ago

Awesome! Thanks for making this change!