From 34c1949525e711beaeb6465a54338ec3bd811712 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Thu, 28 Oct 2021 23:15:55 +0200 Subject: flipping the output map structure for now, just with layers. Instead of listing by layer (and giving lints multiple times), list by lint type (and list all layers in which this lint was applicable). This is a bit wonky for now, but readability of output is much better. --- lib/Types.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/Types.hs') diff --git a/lib/Types.hs b/lib/Types.hs index c39297f..ab9f8a2 100644 --- a/lib/Types.hs +++ b/lib/Types.hs @@ -10,11 +10,12 @@ module Types where import Control.Monad.Trans.Maybe () -import Data.Aeson (ToJSON (toJSON), (.=)) +import Data.Aeson (ToJSON (toJSON), ToJSONKey, (.=)) import Data.Text (Text) import GHC.Generics (Generic) import qualified Data.Aeson as A +import Data.Maybe (mapMaybe) import Paths (RelPath) import Util (PrettyPrint (..), showText) import WithCli (Argument, Proxy (..), @@ -46,6 +47,7 @@ instance HasArguments Level where -- | 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 + deriving (Ord, Eq, Generic, ToJSONKey) -- | TODO: add a reasonable representation of possible urls data Dep = Local RelPath | Link Text | MapLink Text | LocalMap RelPath @@ -54,7 +56,7 @@ data Dep = Local RelPath | Link Text | MapLink Text | LocalMap RelPath data Hint = Hint { hintLevel :: Level , hintMsg :: Text - } deriving (Generic) + } deriving (Generic, Ord, Eq) -- | shorter constructor (called hint because (a) older name and -- (b) lint also exists and is monadic) @@ -66,6 +68,9 @@ lintLevel :: Lint -> Level lintLevel (Lint h) = hintLevel h lintLevel _ = Info +lintsToHints :: [Lint] -> [Hint] +lintsToHints = mapMaybe (\case {Lint hint -> Just hint ; _ -> Nothing}) + instance PrettyPrint Lint where prettyprint (Lint Hint { hintMsg, hintLevel } ) = " " <> showText hintLevel <> ": " <> hintMsg -- cgit v1.2.3