summaryrefslogtreecommitdiff
path: root/lib/Types.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Types.hs')
-rw-r--r--lib/Types.hs60
1 files changed, 59 insertions, 1 deletions
diff --git a/lib/Types.hs b/lib/Types.hs
index 082b30e..79bbfab 100644
--- a/lib/Types.hs
+++ b/lib/Types.hs
@@ -1,3 +1,61 @@
--- | basic types for workadventure maps
+{-# LANGUAGE DeriveAnyClass #-}
+{-# LANGUAGE DeriveGeneric #-}
+{-# 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 (ToJSON (toJSON), (.=))
+import Data.Text (Text)
+import GHC.Generics (Generic)
+
+import qualified Data.Aeson as A
+import Util (PrettyPrint (..), showText)
+
+
+-- | Levels of errors and warnings, collectively called
+-- "Hints" until I can think of some better name
+data Level = Warning | Suggestion | Info | Forbidden | Error | Fatal
+ deriving (Show, Generic, ToJSON)
+
+-- | 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 | Lint Hint
+
+-- | TODO: add a reasonable representation of possible urls
+newtype Dep = Dep Text
+ deriving (Generic, ToJSON)
+
+data Hint = Hint
+ { hintLevel :: Level
+ , hintMsg :: Text
+ } deriving (Generic, ToJSON)
+
+-- | shorter constructor (called lint 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 (Depends dep) = Info
+
+instance PrettyPrint Lint where
+ prettyprint (Lint Hint { hintMsg, hintLevel } ) =
+ showText hintLevel <> ": " <> hintMsg
+ prettyprint (Depends dep) =
+ "Info: found dependency: " <> prettyprint dep
+
+instance ToJSON Lint where
+ toJSON (Lint l) = toJSON l
+ toJSON (Depends dep) = A.object
+ [ "hintMsg" .= prettyprint dep
+ , "hintLevel" .= A.String "Dependency Info" ]
+
+instance PrettyPrint Dep where
+ prettyprint (Dep txt) = txt