summaryrefslogtreecommitdiff
path: root/lib/LintWriter.hs
diff options
context:
space:
mode:
authorstuebinm2021-09-20 23:03:56 +0200
committerstuebinm2021-09-20 23:06:56 +0200
commitc6be6366d6411d7b0b53fd8879537a33fefd5a88 (patch)
treeefceb26894fc455c85d7ccfd436a415d8ee69985 /lib/LintWriter.hs
parent42df3cf0eb0c5877ac3320994cadec07619bcd6b (diff)
use PrettyPrinter more
Diffstat (limited to 'lib/LintWriter.hs')
-rw-r--r--lib/LintWriter.hs12
1 files changed, 9 insertions, 3 deletions
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