From c6be6366d6411d7b0b53fd8879537a33fefd5a88 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Mon, 20 Sep 2021 23:03:56 +0200 Subject: use PrettyPrinter more --- lib/LintWriter.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'lib/LintWriter.hs') diff --git a/lib/LintWriter.hs b/lib/LintWriter.hs index de7d314..5ff56bd 100644 --- a/lib/LintWriter.hs +++ b/lib/LintWriter.hs @@ -14,12 +14,12 @@ import Control.Monad.Writer (MonadWriter (tell), WriterT, import Data.Aeson (ToJSON (toJSON)) import Data.Text (Text) -import Control.Monad.Reader (local) import Control.Monad.Trans.Reader (Reader, asks, runReader) import Control.Monad.Writer.Lazy (lift) import Data.Maybe (mapMaybe) -import GHC.Generics (Generic) +import qualified Data.Text as T import Types +import Util (PrettyPrint (..)) -- | for now, all context we have is how "deep" in the directory tree @@ -38,9 +38,15 @@ newtype LintResult ctxt = LintResult (LintResult' ctxt) -- better, less confusing serialisation of an Either Hint (a, [Hint]). -- Note that Left hint is also serialised as a list to make the resulting -- json schema more regular. -instance ToJSON a => ToJSON (LintResult a) where +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" + lintToDep :: Lint -> Maybe Dep lintToDep = \case Depends dep -> Just dep -- cgit v1.2.3