mirror of
https://github.com/ocharles/weeder.git
synced 2024-11-29 10:15:33 +03:00
Compare commits
2 Commits
01c900f742
...
11ab798d46
Author | SHA1 | Date | |
---|---|---|---|
|
11ab798d46 | ||
|
e0ed4661b4 |
6
.github/workflows/nix-build.yml
vendored
6
.github/workflows/nix-build.yml
vendored
@ -4,18 +4,18 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2.3.4
|
||||
- uses: actions/checkout@v3.5.3
|
||||
with:
|
||||
persist-credentials: false
|
||||
submodules: true
|
||||
|
||||
- uses: cachix/install-nix-action@v14.1
|
||||
- uses: cachix/install-nix-action@v22
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
extra_nix_config: |
|
||||
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
|
||||
substituters = https://cache.nixos.org/ https://cache.iog.io
|
||||
- uses: cachix/cachix-action@v10
|
||||
- uses: cachix/cachix-action@v12
|
||||
with:
|
||||
name: weeder
|
||||
authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}'
|
||||
|
16
README.md
16
README.md
@ -55,13 +55,8 @@ stack build
|
||||
|
||||
## Calling Weeder
|
||||
|
||||
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:
|
||||
|
||||
``` dhall
|
||||
{ roots : List Text, type-class-roots : Bool }
|
||||
```
|
||||
To call Weeder, you first need to provide a configuration file, `weeder.toml`. Weeder uses
|
||||
[TOML](https://toml.io/en/) as its configuration format.
|
||||
|
||||
`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
|
||||
@ -74,8 +69,9 @@ a type class instance as a root. Weeder is currently unable to add dependency
|
||||
edges into type class instances, and without this flag may produce false
|
||||
positives. It's recommended to initially set this to `True`:
|
||||
|
||||
``` dhall
|
||||
{ roots = [ "^Main.main$" ], type-class-roots = True }
|
||||
``` toml
|
||||
roots = [ "^Main.main$" ]
|
||||
type-class-roots = true
|
||||
```
|
||||
|
||||
Now invoke the `weeder` executable, and - if your project has weeds - you will
|
||||
@ -93,7 +89,7 @@ in the Dhall project).
|
||||
|
||||
# Tips
|
||||
|
||||
- You may want to add `^Paths_.*` to the roots in `weeder.dhall` to ignore the
|
||||
- You may want to add `^Paths_.*` to the roots in `weeder.toml` to ignore the
|
||||
`Paths_packageName` module automatically generated by Cabal.
|
||||
|
||||
# Limitations
|
||||
|
@ -1,10 +1,2 @@
|
||||
packages:
|
||||
weeder.cabal
|
||||
|
||||
-- https://github.com/well-typed/cborg/pull/304
|
||||
source-repository-package
|
||||
type: git
|
||||
location: https://github.com/scarf-sh/cborg
|
||||
tag: 8dae0d21e6f17e30785f35bb3ef5eb611863a904
|
||||
subdir: cborg
|
||||
--sha256: sha256-SAHFIlN5QKQKJFhHliXvXOQhrqvsE/TLvY2rkftXkHM=
|
||||
|
@ -3,14 +3,13 @@
|
||||
{-# language OverloadedStrings #-}
|
||||
{-# language RecordWildCards #-}
|
||||
|
||||
module Weeder.Config ( Config(..), config ) where
|
||||
module Weeder.Config ( Config(..) ) where
|
||||
|
||||
-- containers
|
||||
import Data.Set ( Set )
|
||||
import qualified Data.Set as Set
|
||||
|
||||
-- dhall
|
||||
import qualified Dhall
|
||||
-- toml-reader
|
||||
import qualified TOML
|
||||
|
||||
|
||||
-- | Configuration for Weeder analysis.
|
||||
@ -24,14 +23,9 @@ data Config = Config
|
||||
-- instance is used - enabling this option can prevent false positives.
|
||||
}
|
||||
|
||||
|
||||
-- | A Dhall expression decoder for 'Config'.
|
||||
--
|
||||
-- This parses Dhall expressions of the type @{ roots : List Text, type-class-roots : Bool }@.
|
||||
config :: Dhall.Decoder Config
|
||||
config =
|
||||
Dhall.record do
|
||||
rootPatterns <- Set.fromList <$> Dhall.field "roots" ( Dhall.list Dhall.string )
|
||||
typeClassRoots <- Dhall.field "type-class-roots" Dhall.bool
|
||||
instance TOML.DecodeTOML Config where
|
||||
tomlDecoder = do
|
||||
rootPatterns <- TOML.getField "roots"
|
||||
typeClassRoots <- TOML.getField "type-class-roots"
|
||||
|
||||
return Config{..}
|
||||
|
@ -9,6 +9,7 @@
|
||||
module Weeder.Main ( main, mainWithConfig ) where
|
||||
|
||||
-- base
|
||||
import Control.Exception ( throwIO )
|
||||
import Control.Monad ( guard, unless, when )
|
||||
import Control.Monad.IO.Class ( liftIO )
|
||||
import Data.Bool
|
||||
@ -24,8 +25,8 @@ import qualified Data.Set as Set
|
||||
-- text
|
||||
import qualified Data.Text as T
|
||||
|
||||
-- dhall
|
||||
import qualified Dhall
|
||||
-- toml-reader
|
||||
import qualified TOML
|
||||
|
||||
-- directory
|
||||
import System.Directory ( canonicalizePath, doesDirectoryExist, doesFileExist, doesPathExist, listDirectory, withCurrentDirectory )
|
||||
@ -63,15 +64,16 @@ main = do
|
||||
execParser $
|
||||
info (optsP <**> helper <**> versionP) mempty
|
||||
|
||||
Dhall.input config configExpr
|
||||
TOML.decodeFile (T.unpack configExpr)
|
||||
>>= either throwIO pure
|
||||
>>= mainWithConfig hieExt hieDirectories requireHsFiles
|
||||
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>"
|
||||
<> help "A file path for Weeder's configuration."
|
||||
<> value "./weeder.toml"
|
||||
<> metavar "<weeder.toml>"
|
||||
<> showDefaultWith T.unpack
|
||||
)
|
||||
<*> strOption
|
||||
|
@ -22,7 +22,6 @@ library
|
||||
, base ^>= 4.17.0.0
|
||||
, bytestring ^>= 0.10.9.0 || ^>= 0.11.0.0
|
||||
, containers ^>= 0.6.2.1
|
||||
, dhall ^>= 1.30.0 || ^>= 1.31.0 || ^>= 1.32.0 || ^>= 1.33.0 || ^>= 1.34.0 || ^>= 1.35.0 || ^>= 1.36.0 || ^>= 1.37.0 || ^>= 1.40.0 || ^>= 1.41
|
||||
, directory ^>= 1.3.3.2
|
||||
, filepath ^>= 1.4.2.1
|
||||
, generic-lens ^>= 2.2.0.0
|
||||
@ -32,6 +31,7 @@ library
|
||||
, optparse-applicative ^>= 0.14.3.0 || ^>= 0.15.1.0 || ^>= 0.16.0.0 || ^>= 0.17
|
||||
, regex-tdfa ^>= 1.2.0.0 || ^>= 1.3.1.0
|
||||
, text ^>= 2.0.1
|
||||
, toml-reader ^>= 0.2.0.0
|
||||
, transformers ^>= 0.5.6.2 || ^>= 0.6
|
||||
hs-source-dirs: src
|
||||
exposed-modules:
|
||||
|
@ -1,3 +0,0 @@
|
||||
{ roots = [ "Main.main", "^Paths_weeder\\..*" ]
|
||||
, type-class-roots = True
|
||||
}
|
2
weeder.toml
Normal file
2
weeder.toml
Normal file
@ -0,0 +1,2 @@
|
||||
roots = [ "Main.main", "^Paths_weeder\\..*" ]
|
||||
type-class-roots = true
|
Loading…
Reference in New Issue
Block a user