summaryrefslogtreecommitdiff
path: root/lib/LintWriter.hs
diff options
context:
space:
mode:
authorstuebinm2021-09-23 04:34:02 +0200
committerstuebinm2021-09-23 04:34:58 +0200
commit68af04a4da6ba4ec61d1469337ce53457526d861 (patch)
treecb882c03ebe2c88450f16702cd4467a73e2c22a3 /lib/LintWriter.hs
parent04b98e4d62fe33b4fa357f2b52ffcc4f2c413302 (diff)
prettier pretty printing and stuff
also, configurable log level, which only required relaxing the type system once!
Diffstat (limited to 'lib/LintWriter.hs')
-rw-r--r--lib/LintWriter.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/LintWriter.hs b/lib/LintWriter.hs
index 5ff56bd..e704a3c 100644
--- a/lib/LintWriter.hs
+++ b/lib/LintWriter.hs
@@ -1,5 +1,7 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE FlexibleContexts #-}
+{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
@@ -41,17 +43,21 @@ newtype LintResult ctxt = LintResult (LintResult' ctxt)
instance ToJSON (LintResult a) where
toJSON (LintResult res) = toJSON $ snd res
-instance PrettyPrint ctxt => PrettyPrint (LintResult ctxt) where
- prettyprint (LintResult (ctxt, res)) =
- T.concat (map showHint res)
- where showHint hint = prettyprint hint <> context
- context = " (" <> prettyprint ctxt <> ")\n"
+instance PrettyPrint ctxt => PrettyPrint (Level, LintResult ctxt) where
+ prettyprint (level, LintResult (ctxt, res)) =
+ T.concat $ map ((<> context) . prettyprint) (filterLintLevel level res)
+ where context = " (" <> prettyprint ctxt <> ")\n"
lintToDep :: Lint -> Maybe Dep
lintToDep = \case
Depends dep -> Just dep
_ -> Nothing
+filterLintLevel :: Level -> [Lint] -> [Lint]
+filterLintLevel level = mapMaybe $ \l -> if level <= lintLevel l
+ then Just l
+ else Nothing
+
resultToDeps :: LintResult a -> [Dep]
resultToDeps (LintResult a) = mapMaybe lintToDep $ snd a