diff --git a/.hlint.yaml b/.hlint.yaml index f43afb0b0..9a6f01e09 100644 --- a/.hlint.yaml +++ b/.hlint.yaml @@ -17,7 +17,7 @@ - name: [PackageImports] - name: [ConstraintKinds, RankNTypes, TypeFamilies] - name: [TemplateHaskell] - - {name: CPP, within: [HsColour]} # so it can be disabled to avoid GPL code + - {name: CPP, within: [HsColour, Config.Yaml, Test.Annotations]} # so it can be disabled to avoid GPL code - flags: - default: false diff --git a/.weeder.yaml b/.weeder.yaml index 4d0c8aa6c..eb797e50e 100644 --- a/.weeder.yaml +++ b/.weeder.yaml @@ -4,4 +4,4 @@ - message: - name: Redundant build-depends entry - - depends: [ghc-lib-parser, ghc, ghc-boot-th, ghc-boot] # Only some subset is required + - depends: [ghc-lib-parser, ghc, ghc-boot-th, ghc-boot, HsYAML, HsYAML-aeson, yaml] # Only some subset is required diff --git a/hlint.cabal b/hlint.cabal index 245e9552e..650df5059 100644 --- a/hlint.cabal +++ b/hlint.cabal @@ -48,6 +48,11 @@ flag ghc-lib manual: True description: Force dependency on ghc-lib-parser even if GHC API in the ghc package is supported +flag hsyaml + default: False + manual: True + description: Use HsYAML instead of yaml + library default-language: Haskell2010 build-depends: @@ -59,7 +64,6 @@ library data-default >= 0.3, cpphs >= 1.20.1, cmdargs >= 0.10, - yaml >= 0.5.0, uniplate >= 1.5, ansi-terminal >= 0.6.2, extra >= 1.7.3, @@ -83,6 +87,14 @@ library else cpp-options: -DGPL_SCARES_ME + if flag(hsyaml) + build-depends: + HsYAML >= 0.2, + HsYAML-aeson >= 0.2 + cpp-options: -DHS_YAML + else + build-depends: yaml >= 0.5.0 + hs-source-dirs: src exposed-modules: Language.Haskell.HLint diff --git a/src/Config/Yaml.hs b/src/Config/Yaml.hs index 6f79d343d..e39a6225c 100644 --- a/src/Config/Yaml.hs +++ b/src/Config/Yaml.hs @@ -1,5 +1,6 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE OverloadedStrings, ViewPatterns, RecordWildCards, GeneralizedNewtypeDeriving, TupleSections #-} +{-# LANGUAGE CPP #-} module Config.Yaml( ConfigYaml, @@ -8,13 +9,11 @@ module Config.Yaml( ) where import Config.Type -import Data.Yaml import Data.Either import Data.Maybe import Data.List.Extra import Data.Tuple.Extra import Control.Monad.Extra -import Control.Exception.Extra import qualified Data.Text as T import qualified Data.Vector as V import qualified Data.ByteString.Char8 as BS @@ -42,6 +41,33 @@ import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances import Language.Haskell.GhclibParserEx.GHC.Types.Name.Reader import Data.Char +#ifdef HS_YAML + +import Data.YAML (Pos) +import Data.YAML.Aeson (encode1Strict, decode1Strict) +import Data.Aeson hiding (encode) +import Data.Aeson.Types (Parser) +import qualified Data.ByteString as BSS + +decodeFileEither :: FilePath -> IO (Either (Pos, String) ConfigYaml) +decodeFileEither path = decode1Strict <$> BSS.readFile path + +decodeEither' :: BSS.ByteString -> Either (Pos, String) ConfigYaml +decodeEither' = decode1Strict + +displayException :: (Pos, String) -> String +displayException = show + +encode :: Value -> BSS.ByteString +encode = encode1Strict + +#else + +import Data.Yaml +import Control.Exception.Extra + +#endif + -- | Read a config file in YAML format. Takes a filename, and optionally the contents. -- Fails if the YAML doesn't parse or isn't valid HLint YAML diff --git a/src/Test/Annotations.hs b/src/Test/Annotations.hs index 659bb8d7f..a0758c98c 100644 --- a/src/Test/Annotations.hs +++ b/src/Test/Annotations.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE PatternGuards, RecordWildCards, ViewPatterns #-} +{-# LANGUAGE CPP, PatternGuards, RecordWildCards, ViewPatterns #-} -- | Check the annotations within source and hint files. module Test.Annotations(testAnnotations) where @@ -13,7 +13,6 @@ import Data.Functor import Data.List.Extra import Data.Maybe import Data.Tuple.Extra -import Data.Yaml import System.Exit import System.FilePath import System.IO.Extra @@ -34,6 +33,21 @@ import GHC.Util import SrcLoc import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable +#ifdef HS_YAML + +import Data.YAML.Aeson (decode1Strict) +import Data.YAML (Pos) +import Data.ByteString (ByteString) + +decodeEither' :: ByteString -> Either (Pos, String) ConfigYaml +decodeEither' = decode1Strict + +#else + +import Data.Yaml + +#endif + -- Input, Output -- Output = Nothing, should not match -- Output = Just xs, should match xs