This is just the plugin I was looking for, and I have been giving it a whirl.
I used ghc 8.8.3 (by adjusting the cabal bounds).
- build-depends: base ^>= 4.12
+ build-depends: base ^>= 4.13
ghc-options: -Wall
-Wincomplete-uni-patterns
-Wincomplete-record-updates
@@ -62,8 +62,8 @@ library
build-depends: bytestring ^>= 0.10
, containers >= 0.5 && < 0.7
, filepath ^>= 1.4
- , ghc ^>= 8.6.0
- , ghc-exactprint ^>= 0.6
+ , ghc ^>= 8.8.3
+ , ghc-exactprint ^>= 0.6.2
, unordered-containers ^>= 0.2.7
This doesn't compile, so I also have to
diff --git a/src/Smuggler/Loc.hs b/src/Smuggler/Loc.hs
index 6580578..b2ae1f2 100644
--- a/src/Smuggler/Loc.hs
+++ b/src/Smuggler/Loc.hs
@@ -4,8 +4,7 @@ module Smuggler.Loc
, unL
) where
-import SrcLoc (GenLocated (L), Located, SrcSpan (RealSrcSpan), srcSpanStartCol, srcSpanStartLine,
- unLoc)
+import SrcLoc (GenLocated (L), Located, SrcSpan (RealSrcSpan), srcSpanStartCol, srcSpanStartLine)
-- | Returns location in the way of @line:col@.
showLoc :: SrcSpan -> String
@@ -18,4 +17,4 @@ showL name showA (L l nm) = "(" ++ showLoc l ++ name ++ showA nm ++ ")"
-- | Shorter synonim for 'unLoc'.
unL :: GenLocated l e -> e
-unL = unLoc
+unL (L _ e) = e
Perhaps the answer is to use ghc-lib
.
The tests now don't pass
Linking /Users/xxx/Documents/Haskell/smuggler/dist-newstyle/build/x86_64-osx/ghc-8.8.3/smuggler-0.2.0.0/t/smuggler-test/build/smuggler-test/smuggler-test ...
Running 1 test suites...
Test suite smuggler-test: RUNNING...
Test test/Test/BoolPartlyUsedLast failed:
Expected:
- import Data.Bool ( not)
But got:
Test test/Test/TypeConstructorUsed failed:
Expected:
- import Data.Bool (Bool (True))
But got:
Test test/Test/TypeUsed failed:
Expected:
- import Data.Bool (Bool)
But got:
Test test/Test/WildcardUsed failed:
Expected:
- import Data.Bool (Bool (..))
But got:
Test test/Test/TypeConstructorUnused failed:
Expected:
- import Data.Bool (Bool ( True))
But got:
Test test/Test/TypeConstructorUnusedComma failed:
Expected:
- import Data.Bool (Bool (False))
But got:
Test test/Test/WildcardUnused failed:
Expected:
- import Data.Bool ( not)
But got:
Test test/Test/ConstructorsUnused failed:
Expected:
- import Data.Bool ( not)
But got:
Test test/Test/TypeUnused failed:
Expected:
- import Data.Bool ( not)
But got:
Cleaning tests
Some tests failed
Test suite smuggler-test: FAIL
I tried running the plugin on a large project with a lot of redundant imports, https://github.com/agda/agda
. There were several issues:
- because
smuggler
reads files using ByteString
it mangles Unicode characters in the code. Eg:
--- | Get the next version of the concrete name. For instance, @nextName "x" = "x₁"@.
+-- | Get the next version of the concrete name. For instance, @nextName "x" = "xâ<U+0082><U+0081>"@.
- a good number of redundant imports get zapped, but there is a fair bit of mangling (where two adjacent imports get joined into a single line, with the second
import
keyword missing). I am not sure how close the result is to the minimal imports that GHC sees with -ddump-minimal-imports
- some imports are redundant, but needed for backward compatibility (eg, around
Monad.Fail
and Data.Monoid
and Data.Semigroup
.
To make this app even more useful, it would be helpful to have it generate a minimal exports list (based on what is used elsewhere in the project)!
Thanks for all the hard work that has clearly gone into all this.