From bfe45dc4996537b72436f4041d0ca819aa3444e1 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Fri, 17 Sep 2021 23:50:45 +0200 Subject: (somewhat) reasonable representation of parse errors This makes map loading (and parsing) part of the linter, and also makes it return "general lints" and nothing else in case that failed. Possibly a sum type would be nicer here, but I guess it's not really important since everything ends up as json anyways? --- lib/LintWriter.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/LintWriter.hs') diff --git a/lib/LintWriter.hs b/lib/LintWriter.hs index ca7ff08..8e45812 100644 --- a/lib/LintWriter.hs +++ b/lib/LintWriter.hs @@ -10,20 +10,23 @@ import Control.Monad.Trans.Maybe () import Control.Monad.Writer (MonadTrans (lift), MonadWriter (tell), WriterT) import Data.Aeson (ToJSON (toJSON)) -import Data.Text (Text) +import Data.Text (Text, unpack) import GHC.Generics (Generic) - -- | Levels of errors and warnings, collectively called -- "Hints" until I can think of some better name -data Level = Warning | Suggestion | Info | Forbidden | Error +data Level = Warning | Suggestion | Info | Forbidden | Error | Fatal deriving (Show, Generic, ToJSON) -- | a hint comes with an explanation (and a level) data Hint = Hint { hintLevel :: Level , hintMsg :: Text } - deriving (Show, Generic, ToJSON) + deriving (Generic, ToJSON) + +instance Show Hint where + show Hint { hintMsg, hintLevel } = + show hintLevel <> ": " <> unpack hintMsg -- shorter constructor hint :: Level -> Text -> Hint -- cgit v1.2.3