Select Git revision
Types.hs 4.13 KiB
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
-- | basic types for the linter to eat and produce
-- The dark magic making thse useful is in LintWriter
module Types where
import Control.Monad.Trans.Maybe ()
import Data.Aeson (FromJSON, ToJSON (toJSON),
ToJSONKey, (.=))
import Data.Text (Text)
import GHC.Generics (Generic)
import Badges (Badge)
import qualified Data.Aeson as A
import Data.Maybe (mapMaybe)
import Paths (RelPath)
import Util (PrettyPrint (..), showText)
import WithCli (Argument, Proxy (..),
atomicArgumentsParser)
import WithCli.Pure (Argument (argumentType, parseArgument),
HasArguments (argumentsParser))
-- | Levels of errors and warnings, collectively called
-- "Hints" until I can think of some better name
data Level = Info | Suggestion | Warning | Forbidden | Error | Fatal
deriving (Show, Generic, Ord, Eq, ToJSON, FromJSON)
instance Argument Level where
argumentType Proxy = "Lint Level"
parseArgument arg = case arg of
"info" -> Just Info
"suggestion" -> Just Suggestion
"warning" -> Just Warning
"forbidden" -> Just Forbidden
"error" -> Just Error
"fatal" -> Just Fatal
_ -> Nothing
instance HasArguments Level where
argumentsParser = atomicArgumentsParser
-- | a hint comes with an explanation (and a level), or is a dependency
-- (in which case it'll be otherwise treated as an info hint)
data Lint = Depends Dep | Offers Text | Lint Hint | Badge Badge
deriving (Ord, Eq, Generic, ToJSONKey)
data Dep = Local RelPath | Link Text | MapLink Text | LocalMap RelPath
deriving (Generic, Ord, Eq)
data Hint = Hint
{ hintLevel :: Level
, hintMsg :: Text
} deriving (Generic, Ord, Eq)
-- | shorter constructor (called hint because (a) older name and
-- (b) lint also exists and is monadic)
hint :: Level -> Text -> Lint
hint level msg = Lint Hint { hintLevel = level, hintMsg = msg }
-- | dependencies just have level Info
lintLevel :: Lint -> Level
lintLevel (Lint h) = hintLevel h
lintLevel _ = Info