packages feed

weeder 2.0.1 → 2.1.0

raw patch · 5 files changed

+310/−52 lines, 5 filesdep +textdep ~basedep ~dhalldep ~generic-lens

Dependencies added: text

Dependency ranges changed: base, dhall, generic-lens, ghc, lens, regex-tdfa

Files

CHANGELOG.md view
@@ -1,10 +1,200 @@-# 2.0.1.0+## Changelog for Weeder +### [`2.1.0`][v2.1.0] - *2020-06-30*++- Support regex-tdfa ^>= 1.2 (#13)+- Handle mismatched hie file version explicitly (fixes #8). (#16)+- Implement --help and --version (#36)+- Make search directory configurable (#37)+- Support GHC 8.10++### [`2.0.1`][v2.0.1] - *2020-03-15*+ - PR #7: Support optparse-applicative-0.15.1.0 and algebraic-graphs-0.5. Thanks   to @robx for contribuiting this fix! -# 2.0.0.0 -Weeder 2.0 is a ground up rewrite of Weeder using `.hie` files. It is now+### [`2.0.0`][v2.0.0] - *2020-03-15*++- Weeder 2.0 is a ground up rewrite of Weeder using `.hie` files. It is now maintained by Ollie Charles (@ocharles on GitHub). +- **Note:**++  Issue numbers *before* this version reference to the original repository here:++    - https://github.com/ndmitchell/weeder++  Issue numbers *after*  this version reference to the new repository here:++    - https://github.com/ocharles/weeder+++### [`1.0.8`][v1.0.8] - *2018-08-26*++- #42, make paths case-insensitive on MacOS+++### [`1.0.7`][v1.0.7] - *2018-08-23*++- Don't warn on base as it is used by Paths_ modules++- #42, make --verbose print out the version number++- #41, make the --help output clear you can pass a stack.yaml+++### [`1.0.6`][v1.0.6] - *2018-06-16*++- Don't fail with an error if stack setup is necessary++- If you fail to find stack.yaml give a better error message+++### [`1.0.5`][v1.0.5] - *2018-05-05*++- #39, provide weeder as a library+++### [`1.0.4`][v1.0.4] - *2018-05-02*++- #38, make sure you parse bracketed version ranges properly+++### [`1.0.3`][v1.0.3] - *2018-03-04*++- #35, support ^>= operator in Cabal+++### [`1.0.2`][v1.0.2] - *2018-03-01*++- Add lower bounds for Yaml and Aeson+++### [`1.0.1`][v1.0.1] - *2018-02-23*++- #34, support -any for version numbers+++### [`1.0`][v1.0] - *2018-01-22*++- #30, bump the version number to 1.0+++### [`0.1.13`][v0.1.13] - *2018-01-17*++- #32, find .hi files in more places++- #32, always disable color when running stack+++### [`0.1.12`][v0.1.12] - *2018-01-16*++- Make available on Mac+++### [`0.1.11`][v0.1.11] - *2017-12-29++- #29, deal with case-insensitive FilePath on Windows+++### [`0.1.10`][v0.1.10] - *2017-12-28*++- Make --verbose print out the directory when running commands++- Don't report semigroups as unused on any platforms+++### [`0.1.9`][v0.1.9] - *2017-12-07*++- Don't report Win32/unix as unused on the alternate platform+++### [`0.1.8`][v0.1.8] - *2017-12-06*++- Follow both branches for if/else containing dependencies/modules+++### [`0.1.7`][v0.1.7] - *2017-08-09*++- #21, detect dependencies that are only required transitively++- #13, respect the STACK_YAML environment variable++- #20, add verbosity messages in a lot of places++- #15, tone down unused import if exporting a cross-package type++- #11, optimise execution speed (~3x faster)+++### [`0.1.6`][v0.1.6] - *2017-06-18*++- #10, find files generated by alex/happy+++### [`0.1.5`][v0.1.5] - *2017-06-02*++- If --yaml and no hints give no output+++### [`0.1.4`][v0.1.4] - *2017-05-27*++- #9, allow --dist-dir to set the stack dist-dir++- Deal with operators including | in them++- Allow arrays of arrays of strings in the .weeder.yaml+++### [`0.1.3`][v0.1.3] - *2017-05-08*++- #5, document how to install weeder++- #8, detect unused imports, even import Foo()++- #7, don't say modules with only instances are always redundant++- #6, don't give partial pattern matches when reading .weeder.yaml+++### [`0.1.2`][v0.1.2] - *2017-04-29*++- #3, deal with space-separated hs-source-dirs+++### [`0.1.1`][v0.1.1] - *2017-04-29*++- #2, use "stack query" rather than parsing stack.yaml+++### [`0.1`][v0.1] - *2017-04-28*++- Initial version+++[v2.0.1 ]: https://github.com/ocharles/weeder/tree/v2.0.1+[v2.0.0 ]: https://github.com/ocharles/weeder/tree/v2.0.0+[v1.0.8 ]: https://github.com/ndmitchell/weeder/tree/v1.0.8+[v1.0.7 ]: https://github.com/ndmitchell/weeder/tree/v1.0.7+[v1.0.6 ]: https://github.com/ndmitchell/weeder/tree/v1.0.6+[v1.0.5 ]: https://github.com/ndmitchell/weeder/tree/v1.0.5+[v1.0.4 ]: https://github.com/ndmitchell/weeder/tree/v1.0.4+[v1.0.3 ]: https://github.com/ndmitchell/weeder/tree/v1.0.3+[v1.0.2 ]: https://github.com/ndmitchell/weeder/tree/v1.0.2+[v1.0.1 ]: https://github.com/ndmitchell/weeder/tree/v1.0.1+[v1.0   ]: https://github.com/ndmitchell/weeder/tree/v1.0+[v0.1.13]: https://github.com/ndmitchell/weeder/tree/v0.1.13+[v0.1.12]: https://github.com/ndmitchell/weeder/tree/v0.1.12+[v0.1.11]: https://github.com/ndmitchell/weeder/tree/v0.1.11+[v0.1.10]: https://github.com/ndmitchell/weeder/tree/v0.1.10+[v0.1.9 ]: https://github.com/ndmitchell/weeder/tree/v0.1.9+[v0.1.8 ]: https://github.com/ndmitchell/weeder/tree/v0.1.8+[v0.1.7 ]: https://github.com/ndmitchell/weeder/tree/v0.1.7+[v0.1.6 ]: https://github.com/ndmitchell/weeder/tree/v0.1.6+[v0.1.5 ]: https://github.com/ndmitchell/weeder/tree/v0.1.5+[v0.1.4 ]: https://github.com/ndmitchell/weeder/tree/v0.1.4+[v0.1.3 ]: https://github.com/ndmitchell/weeder/tree/v0.1.3+[v0.1.2 ]: https://github.com/ndmitchell/weeder/tree/v0.1.2+[v0.1.1 ]: https://github.com/ndmitchell/weeder/tree/v0.1.1+[v0.1   ]: https://github.com/ndmitchell/weeder/tree/v0.1
README.md view
@@ -18,8 +18,11 @@  ## Preparing Your Code for Weeder -To use Weeder, you will need to generate `.hie` files from your source code. If-you use Cabal, this is easily done by adding one line to your+To use Weeder, you will need to generate `.hie` files from your source code. ++### Cabal ++If you use Cabal, this is easily done by adding one line to your `cabal.project.local` file:  ``` cabal@@ -34,9 +37,25 @@ cabal build all ``` +### Stack++If you use `stack`, add the following to your `stack.yaml`:++``` yaml+ghc-options:+  "$locals": -fwrite-ide-info+```++and rebuild:++``` shell+stack clean+stack build+```+ ## Calling Weeder -To call Weeder, you first need to provide a configuration file. Weeder uses+To call Weeder, you first need to provide a configuration file, `weeder.dhall`. Weeder uses [Dhall](https://dhall-lang.org) as its configuration format, and configuration files have the type: @@ -46,7 +65,9 @@  `roots` is a list of regular expressions of symbols that are considered as alive. If you're building an executable, the pattern `^Main.main$` is a-good starting point - specifying that `main` is a root.+good starting point - specifying that `main` is a root. Weeder currently doesn't+add all exported functions a roots automatically but in many cases `main` from a+test suite could be a good workaround for that  `type-class-roots` configures whether or not Weeder should consider anything in a type class instance as a root. Weeder is currently unable to add dependency@@ -87,6 +108,11 @@  (Please note these warnings are just for demonstration and not necessarily weeds in the Dhall project).++# Tips++- You may want to add `^Paths_.*` to the roots in `weeder.dhall` to ignore the+  `Paths_packageName` module automatically generated by Cabal.  # Limitations 
src/Weeder.hs view
@@ -204,6 +204,7 @@    where +    addExport :: MonadState Analysis m => Declaration -> m ()     addExport d = #exports %= Map.insertWith (<>) m ( Set.singleton d )  
src/Weeder/Main.hs view
@@ -14,6 +14,7 @@ import Control.Monad.IO.Class ( liftIO ) import Data.Bool import Data.Foldable+import Data.Version ( showVersion ) import Text.Printf ( printf ) import System.Exit ( exitFailure ) @@ -24,6 +25,9 @@ import qualified Data.Map.Strict as Map import qualified Data.Set as Set +-- text+import qualified Data.Text as T+ -- dhall import qualified Dhall @@ -34,10 +38,10 @@ import System.FilePath ( isExtensionOf )  -- ghc-import HieBin ( HieFileResult( HieFileResult, hie_file_result ) )-import HieBin ( readHieFile )+import HieBin ( HieFileResult( HieFileResult, hie_file_result ), readHieFileWithVersion )+import HieTypes ( HieFile, hieVersion ) import Module ( moduleName, moduleNameString )-import NameCache ( initNameCache )+import NameCache ( initNameCache, NameCache ) import OccName ( occNameString ) import SrcLoc ( realSrcSpanStart, srcLocCol, srcLocLine ) import UniqSupply ( mkSplitUniqSupply )@@ -54,33 +58,50 @@ -- weeder import Weeder import Weeder.Config+import Paths_weeder (version)   -- | Parse command line arguments and into a 'Config' and run 'mainWithConfig'. main :: IO () main = do-  configExpr <-+  (configExpr, hieDirectories) <-     execParser $-      info-        ( strOption-            (    long "config"-              <> help "A Dhall expression for Weeder's configuration. Can either be a file path (a Dhall import) or a literal Dhall expression."-              <> value "./weeder.dhall"+      info (optsP <**> helper <**> versionP) mempty++  Dhall.input config configExpr >>= mainWithConfig hieDirectories+  where+    optsP = (,)+        <$> strOption+            ( long "config"+                <> help "A Dhall expression for Weeder's configuration. Can either be a file path (a Dhall import) or a literal Dhall expression."+                <> value "./weeder.dhall"+                <> metavar "<weeder.dhall>"+                <> showDefaultWith T.unpack             )-        )-        mempty+        <*> many (+            strOption+                ( long "hie-directory"+                    <> help "A directory to look for .hie files in. Maybe specified multiple times. Default ./."+                )+            ) -  Dhall.input config configExpr >>= mainWithConfig+    versionP = infoOption (showVersion version)+        ( long "version" <> help "Show version" )   -- | Run Weeder in the current working directory with a given 'Config'. -- -- This will recursively find all @.hie@ files in the current directory, perform -- analysis, and report all unused definitions according to the 'Config'.-mainWithConfig :: Config -> IO ()-mainWithConfig Config{ rootPatterns, typeClassRoots } = do+mainWithConfig :: [FilePath] -> Config -> IO ()+mainWithConfig hieDirectories Config{ rootPatterns, typeClassRoots } = do   hieFilePaths <--    getHieFilesIn "./."+    concat <$>+      traverse getHieFilesIn+        ( if null hieDirectories+          then ["./."]+          else hieDirectories+        )    nameCache <- do     uniqSupply <- mkSplitUniqSupply 'z'@@ -89,10 +110,8 @@   analysis <-     flip execStateT emptyAnalysis do       for_ hieFilePaths \hieFilePath -> do-        ( HieFileResult{ hie_file_result }, _ ) <--          liftIO ( readHieFile nameCache hieFilePath )--        analyseHieFile hie_file_result+        hieFileResult <- liftIO ( readCompatibleHieFileOrExit nameCache hieFilePath )+        analyseHieFile hieFileResult    let     roots =@@ -203,3 +222,18 @@      else       return []+++-- | Read a .hie file, exiting if it's an incompatible version.+readCompatibleHieFileOrExit :: NameCache -> FilePath -> IO HieFile+readCompatibleHieFileOrExit nameCache path = do+  res <- readHieFileWithVersion (\ (v, _) -> v == hieVersion) nameCache path+  case res of+    Right ( HieFileResult{ hie_file_result }, _ ) ->+      return hie_file_result+    Left ( v, _ghcVersion ) -> do+      putStrLn $ "incompatible hie file: " <> path+      putStrLn $ "    expected .hie file version " <> show hieVersion <> " but got " <> show v+      putStrLn $ "    weeder must be built with the same GHC version"+               <> " as the project it is used on"+      exitFailure
weeder.cabal view
@@ -1,55 +1,62 @@-cabal-version: 2.0-license:       BSD3+cabal-version: 3.0+license:       BSD-3-Clause license-file:  LICENSE name:          weeder author:        Ollie Charles <ollie@ocharles.org.uk>+maintainer:    Ollie Charles <ollie@ocharles.org.uk> build-type:    Simple-version:       2.0.1+version:       2.1.0 copyright:     Neil Mitchell 2017-2020, Oliver Charles 2020 synopsis:      Detect dead code description:   Find declarations. homepage:      https://github.com/ocharles/weeder#readme bug-reports:   https://github.com/ocharles/weeder/issues+category:      Development extra-doc-files:     README.md     CHANGELOG.md  library   build-depends:-    algebraic-graphs     ^>= 0.4 || ^>= 0.5           ,-    base                 ^>= 4.13.0.0                 ,-    bytestring           ^>= 0.10.9.0                 ,-    containers           ^>= 0.6.2.1                  ,-    dhall                ^>= 1.30.0                   ,-    directory            ^>= 1.3.3.2                  ,-    filepath             ^>= 1.4.2.1                  ,-    generic-lens         ^>= 1.1.0.0 || ^>= 2.0.0.0   ,-    ghc                  ^>= 8.8.1                    ,-    lens                 ^>= 4.18.1                   ,-    mtl                  ^>= 2.2.2                    ,-    optparse-applicative ^>= 0.14.3.0 || ^>= 0.15.1.0 ,-    regex-tdfa           ^>= 1.3.1.0                  ,-    transformers         ^>= 0.5.6.2+    , algebraic-graphs     ^>= 0.4 || ^>= 0.5+    , base                 ^>= 4.13.0.0 || ^>= 4.14.0.0+    , bytestring           ^>= 0.10.9.0+    , containers           ^>= 0.6.2.1+    , dhall                ^>= 1.30.0 || ^>= 1.31.0 || ^>= 1.32.0 || ^>= 1.33.0+    , directory            ^>= 1.3.3.2+    , filepath             ^>= 1.4.2.1+    , generic-lens         ^>= 1.1.0.0 || ^>= 1.2.0.0 || ^>= 2.0.0.0+    , ghc                  ^>= 8.8.1 || ^>= 8.10+    , lens                 ^>= 4.18.1 || ^>= 4.19+    , mtl                  ^>= 2.2.2+    , optparse-applicative ^>= 0.14.3.0 || ^>= 0.15.1.0+    , regex-tdfa           ^>= 1.2.0.0 || ^>= 1.3.1.0+    , text                 ^>= 1.2.3.0+    , transformers         ^>= 0.5.6.2   hs-source-dirs: src   exposed-modules:     Weeder     Weeder.Config     Weeder.Main+  autogen-modules:+    Paths_weeder+  other-modules:+    Paths_weeder   ghc-options: -Wall -fwarn-incomplete-uni-patterns   default-language: Haskell2010   executable weeder   build-depends:-    base                 ^>= 4.13.0.0                 ,-    bytestring           ^>= 0.10.9.0                 ,-    containers           ^>= 0.6.2.1                  ,-    directory            ^>= 1.3.3.2                  ,-    filepath             ^>= 1.4.2.1                  ,-    ghc                  ^>= 8.8.1                    ,-    optparse-applicative ^>= 0.14.3.0 || ^>= 0.15.1.0 ,-    transformers         ^>= 0.5.6.2                  ,-    weeder+    , base                 ^>= 4.13.0.0 || ^>= 4.14+    , bytestring           ^>= 0.10.9.0+    , containers           ^>= 0.6.2.1+    , directory            ^>= 1.3.3.2+    , filepath             ^>= 1.4.2.1+    , ghc                  ^>= 8.8.1 || ^>= 8.10+    , optparse-applicative ^>= 0.14.3.0 || ^>= 0.15.1.0+    , transformers         ^>= 0.5.6.2+    , weeder   main-is: Main.hs   hs-source-dirs: exe-weeder   ghc-options: -Wall -fwarn-incomplete-uni-patterns