{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeApplications #-}
module HaskellCI.Config.HLint where
import HaskellCI.Prelude
import Distribution.Version (withinVersion)
import qualified Distribution.Compat.CharParsing as C
import qualified Distribution.FieldGrammar as C
import qualified Distribution.Parsec as C
import qualified Distribution.Pretty as C
import qualified Text.PrettyPrint as PP
import HaskellCI.OptionsGrammar
data HLintConfig = HLintConfig
{ HLintConfig -> Bool
cfgHLintEnabled :: !Bool
, HLintConfig -> HLintJob
cfgHLintJob :: !HLintJob
, HLintConfig -> Maybe FilePath
cfgHLintYaml :: !(Maybe FilePath)
, HLintConfig -> [FilePath]
cfgHLintOptions :: [String]
, HLintConfig -> VersionRange
cfgHLintVersion :: !VersionRange
, HLintConfig -> Bool
cfgHLintDownload :: !Bool
}
deriving (Int -> HLintConfig -> ShowS
[HLintConfig] -> ShowS
HLintConfig -> FilePath
(Int -> HLintConfig -> ShowS)
-> (HLintConfig -> FilePath)
-> ([HLintConfig] -> ShowS)
-> Show HLintConfig
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HLintConfig -> ShowS
showsPrec :: Int -> HLintConfig -> ShowS
$cshow :: HLintConfig -> FilePath
show :: HLintConfig -> FilePath
$cshowList :: [HLintConfig] -> ShowS
showList :: [HLintConfig] -> ShowS
Show, (forall x. HLintConfig -> Rep HLintConfig x)
-> (forall x. Rep HLintConfig x -> HLintConfig)
-> Generic HLintConfig
forall x. Rep HLintConfig x -> HLintConfig
forall x. HLintConfig -> Rep HLintConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HLintConfig -> Rep HLintConfig x
from :: forall x. HLintConfig -> Rep HLintConfig x
$cto :: forall x. Rep HLintConfig x -> HLintConfig
to :: forall x. Rep HLintConfig x -> HLintConfig
Generic, Get HLintConfig
[HLintConfig] -> Put
HLintConfig -> Put
(HLintConfig -> Put)
-> Get HLintConfig -> ([HLintConfig] -> Put) -> Binary HLintConfig
forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
$cput :: HLintConfig -> Put
put :: HLintConfig -> Put
$cget :: Get HLintConfig
get :: Get HLintConfig
$cputList :: [HLintConfig] -> Put
putList :: [HLintConfig] -> Put
Binary)
defaultHLintVersion :: VersionRange
defaultHLintVersion :: VersionRange
defaultHLintVersion = Version -> VersionRange
withinVersion ([Int] -> Version
mkVersion [Int
3,Int
5])
data HLintJob
= HLintJobLatest
| HLintJob Version
deriving (HLintJob -> HLintJob -> Bool
(HLintJob -> HLintJob -> Bool)
-> (HLintJob -> HLintJob -> Bool) -> Eq HLintJob
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: HLintJob -> HLintJob -> Bool
== :: HLintJob -> HLintJob -> Bool
$c/= :: HLintJob -> HLintJob -> Bool
/= :: HLintJob -> HLintJob -> Bool
Eq, Int -> HLintJob -> ShowS
[HLintJob] -> ShowS
HLintJob -> FilePath
(Int -> HLintJob -> ShowS)
-> (HLintJob -> FilePath) -> ([HLintJob] -> ShowS) -> Show HLintJob
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> HLintJob -> ShowS
showsPrec :: Int -> HLintJob -> ShowS
$cshow :: HLintJob -> FilePath
show :: HLintJob -> FilePath
$cshowList :: [HLintJob] -> ShowS
showList :: [HLintJob] -> ShowS
Show, (forall x. HLintJob -> Rep HLintJob x)
-> (forall x. Rep HLintJob x -> HLintJob) -> Generic HLintJob
forall x. Rep HLintJob x -> HLintJob
forall x. HLintJob -> Rep HLintJob x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. HLintJob -> Rep HLintJob x
from :: forall x. HLintJob -> Rep HLintJob x
$cto :: forall x. Rep HLintJob x -> HLintJob
to :: forall x. Rep HLintJob x -> HLintJob
Generic, Get HLintJob
[HLintJob] -> Put
HLintJob -> Put
(HLintJob -> Put)
-> Get HLintJob -> ([HLintJob] -> Put) -> Binary HLintJob
forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
$cput :: HLintJob -> Put
put :: HLintJob -> Put
$cget :: Get HLintJob
get :: Get HLintJob
$cputList :: [HLintJob] -> Put
putList :: [HLintJob] -> Put
Binary)
instance C.Parsec HLintJob where
parsec :: forall (m :: * -> *). CabalParsing m => m HLintJob
parsec = HLintJob
HLintJobLatest HLintJob -> m FilePath -> m HLintJob
forall a b. a -> m b -> m a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ FilePath -> m FilePath
forall (m :: * -> *). CharParsing m => FilePath -> m FilePath
C.string FilePath
"latest"
m HLintJob -> m HLintJob -> m HLintJob
forall a. m a -> m a -> m a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Version -> HLintJob
HLintJob (Version -> HLintJob) -> m Version -> m HLintJob
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> m Version
forall a (m :: * -> *). (Parsec a, CabalParsing m) => m a
forall (m :: * -> *). CabalParsing m => m Version
C.parsec
instance C.Pretty HLintJob where
pretty :: HLintJob -> Doc
pretty HLintJob
HLintJobLatest = FilePath -> Doc
PP.text FilePath
"latest"
pretty (HLintJob Version
v) = Version -> Doc
forall a. Pretty a => a -> Doc
C.pretty Version
v
hlintConfigGrammar
:: (OptionsGrammar c g, Applicative (g HLintConfig), c (Identity HLintJob))
=> g HLintConfig HLintConfig
hlintConfigGrammar :: forall (c :: * -> Constraint) (g :: * -> * -> *).
(OptionsGrammar c g, Applicative (g HLintConfig),
c (Identity HLintJob)) =>
g HLintConfig HLintConfig
hlintConfigGrammar = Bool
-> HLintJob
-> Maybe FilePath
-> [FilePath]
-> VersionRange
-> Bool
-> HLintConfig
HLintConfig
(Bool
-> HLintJob
-> Maybe FilePath
-> [FilePath]
-> VersionRange
-> Bool
-> HLintConfig)
-> g HLintConfig Bool
-> g HLintConfig
(HLintJob
-> Maybe FilePath
-> [FilePath]
-> VersionRange
-> Bool
-> HLintConfig)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FieldName -> ALens' HLintConfig Bool -> Bool -> g HLintConfig Bool
forall s. FieldName -> ALens' s Bool -> Bool -> g s Bool
forall (c :: * -> Constraint) (g :: * -> * -> *) s.
FieldGrammar c g =>
FieldName -> ALens' s Bool -> Bool -> g s Bool
C.booleanFieldDef FieldName
"hlint" (forall (name :: Symbol) r a (f :: * -> *).
(HasField name r a, Functor f) =>
(a -> f a) -> r -> f r
field @"cfgHLintEnabled") Bool
False
g HLintConfig Bool
-> (g HLintConfig Bool -> g HLintConfig Bool) -> g HLintConfig Bool
forall a b. a -> (a -> b) -> b
^^^ FilePath -> g HLintConfig Bool -> g HLintConfig Bool
forall s a. FilePath -> g s a -> g s a
forall (c :: * -> Constraint) (p :: * -> * -> *) s a.
OptionsGrammar c p =>
FilePath -> p s a -> p s a
help FilePath
"Enable HLint job"
g HLintConfig
(HLintJob
-> Maybe FilePath
-> [FilePath]
-> VersionRange
-> Bool
-> HLintConfig)
-> g HLintConfig HLintJob
-> g HLintConfig
(Maybe FilePath
-> [FilePath] -> VersionRange -> Bool -> HLintConfig)
forall a b.
g HLintConfig (a -> b) -> g HLintConfig a -> g HLintConfig b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FieldName
-> ALens' HLintConfig HLintJob
-> HLintJob
-> g HLintConfig HLintJob
forall (c :: * -> Constraint) (g :: * -> * -> *) s a.
(FieldGrammar c g, Functor (g s), c (Identity a), Eq a) =>
FieldName -> ALens' s a -> a -> g s a
C.optionalFieldDef FieldName
"hlint-job" (forall (name :: Symbol) r a (f :: * -> *).
(HasField name r a, Functor f) =>
(a -> f a) -> r -> f r
field @"cfgHLintJob") HLintJob
HLintJobLatest
g HLintConfig HLintJob
-> (g HLintConfig HLintJob -> g HLintConfig HLintJob)
-> g HLintConfig HLintJob
forall a b. a -> (a -> b) -> b
^^^ FilePath
-> FilePath -> g HLintConfig HLintJob -> g HLintConfig HLintJob
forall s a. FilePath -> FilePath -> g s a -> g s a
forall (c :: * -> Constraint) (p :: * -> * -> *) s a.
OptionsGrammar c p =>
FilePath -> FilePath -> p s a -> p s a
metahelp FilePath
"JOB" FilePath
"Specify HLint job"
g HLintConfig
(Maybe FilePath
-> [FilePath] -> VersionRange -> Bool -> HLintConfig)
-> g HLintConfig (Maybe FilePath)
-> g HLintConfig
([FilePath] -> VersionRange -> Bool -> HLintConfig)
forall a b.
g HLintConfig (a -> b) -> g HLintConfig a -> g HLintConfig b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FieldName
-> (FilePath -> FilePathNT)
-> ALens' HLintConfig (Maybe FilePath)
-> g HLintConfig (Maybe FilePath)
forall b a s.
(c b, Newtype a b) =>
FieldName -> (a -> b) -> ALens' s (Maybe a) -> g s (Maybe a)
forall (c :: * -> Constraint) (g :: * -> * -> *) b a s.
(FieldGrammar c g, c b, Newtype a b) =>
FieldName -> (a -> b) -> ALens' s (Maybe a) -> g s (Maybe a)
C.optionalFieldAla FieldName
"hlint-yaml" FilePath -> FilePathNT
C.FilePathNT (forall (name :: Symbol) r a (f :: * -> *).
(HasField name r a, Functor f) =>
(a -> f a) -> r -> f r
field @"cfgHLintYaml")
g HLintConfig (Maybe FilePath)
-> (g HLintConfig (Maybe FilePath)
-> g HLintConfig (Maybe FilePath))
-> g HLintConfig (Maybe FilePath)
forall a b. a -> (a -> b) -> b
^^^ FilePath
-> FilePath
-> FilePath
-> g HLintConfig (Maybe FilePath)
-> g HLintConfig (Maybe FilePath)
forall (c :: * -> Constraint) (p :: * -> * -> *) s a.
OptionsGrammar c p =>
FilePath -> FilePath -> FilePath -> p s a -> p s a
metaActionHelp FilePath
"PATH" FilePath
"file" FilePath
"Use specific .hlint.yaml"
g HLintConfig ([FilePath] -> VersionRange -> Bool -> HLintConfig)
-> g HLintConfig [FilePath]
-> g HLintConfig (VersionRange -> Bool -> HLintConfig)
forall a b.
g HLintConfig (a -> b) -> g HLintConfig a -> g HLintConfig b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FieldName
-> ([FilePath] -> List NoCommaFSep Token' FilePath)
-> ALens' HLintConfig [FilePath]
-> g HLintConfig [FilePath]
forall b a s.
(c b, Monoid a, Newtype a b) =>
FieldName -> (a -> b) -> ALens' s a -> g s a
forall (c :: * -> Constraint) (g :: * -> * -> *) b a s.
(FieldGrammar c g, c b, Monoid a, Newtype a b) =>
FieldName -> (a -> b) -> ALens' s a -> g s a
C.monoidalFieldAla FieldName
"hlint-options" (NoCommaFSep
-> (FilePath -> Token')
-> [FilePath]
-> List NoCommaFSep Token' FilePath
forall sep a b. sep -> (a -> b) -> [a] -> List sep b a
C.alaList' NoCommaFSep
C.NoCommaFSep FilePath -> Token'
C.Token') (forall (name :: Symbol) r a (f :: * -> *).
(HasField name r a, Functor f) =>
(a -> f a) -> r -> f r
field @"cfgHLintOptions")
g HLintConfig [FilePath]
-> (g HLintConfig [FilePath] -> g HLintConfig [FilePath])
-> g HLintConfig [FilePath]
forall a b. a -> (a -> b) -> b
^^^ FilePath
-> FilePath -> g HLintConfig [FilePath] -> g HLintConfig [FilePath]
forall s a. FilePath -> FilePath -> g s a -> g s a
forall (c :: * -> Constraint) (p :: * -> * -> *) s a.
OptionsGrammar c p =>
FilePath -> FilePath -> p s a -> p s a
metahelp FilePath
"OPTS" FilePath
"Additional HLint options"
g HLintConfig (VersionRange -> Bool -> HLintConfig)
-> g HLintConfig VersionRange
-> g HLintConfig (Bool -> HLintConfig)
forall a b.
g HLintConfig (a -> b) -> g HLintConfig a -> g HLintConfig b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FieldName
-> ALens' HLintConfig VersionRange
-> VersionRange
-> g HLintConfig VersionRange
forall (c :: * -> Constraint) (g :: * -> * -> *) s a.
(FieldGrammar c g, Functor (g s), c (Identity a), Eq a) =>
FieldName -> ALens' s a -> a -> g s a
C.optionalFieldDef FieldName
"hlint-version" (forall (name :: Symbol) r a (f :: * -> *).
(HasField name r a, Functor f) =>
(a -> f a) -> r -> f r
field @"cfgHLintVersion") VersionRange
defaultHLintVersion
g HLintConfig VersionRange
-> (g HLintConfig VersionRange -> g HLintConfig VersionRange)
-> g HLintConfig VersionRange
forall a b. a -> (a -> b) -> b
^^^ FilePath
-> FilePath
-> g HLintConfig VersionRange
-> g HLintConfig VersionRange
forall s a. FilePath -> FilePath -> g s a -> g s a
forall (c :: * -> Constraint) (p :: * -> * -> *) s a.
OptionsGrammar c p =>
FilePath -> FilePath -> p s a -> p s a
metahelp FilePath
"RANGE" FilePath
"HLint version"
g HLintConfig (Bool -> HLintConfig)
-> g HLintConfig Bool -> g HLintConfig HLintConfig
forall a b.
g HLintConfig (a -> b) -> g HLintConfig a -> g HLintConfig b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> FieldName -> ALens' HLintConfig Bool -> Bool -> g HLintConfig Bool
forall s. FieldName -> ALens' s Bool -> Bool -> g s Bool
forall (c :: * -> Constraint) (g :: * -> * -> *) s.
FieldGrammar c g =>
FieldName -> ALens' s Bool -> Bool -> g s Bool
C.booleanFieldDef FieldName
"hlint-download-binary" (forall (name :: Symbol) r a (f :: * -> *).
(HasField name r a, Functor f) =>
(a -> f a) -> r -> f r
field @"cfgHLintDownload") Bool
True
g HLintConfig Bool
-> (g HLintConfig Bool -> g HLintConfig Bool) -> g HLintConfig Bool
forall a b. a -> (a -> b) -> b
^^^ FilePath -> g HLintConfig Bool -> g HLintConfig Bool
forall s a. FilePath -> g s a -> g s a
forall (c :: * -> Constraint) (p :: * -> * -> *) s a.
OptionsGrammar c p =>
FilePath -> p s a -> p s a
help FilePath
"Download HLint binary release"