From 61e66f41b61baf69c08ee7c9d8738ad68fde669e Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 23 Nov 2021 19:08:54 +0100 Subject: add a severity attribute to the json output --- lib/CheckDir.hs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/CheckDir.hs b/lib/CheckDir.hs index b1b5830..61ac81c 100644 --- a/lib/CheckDir.hs +++ b/lib/CheckDir.hs @@ -57,28 +57,33 @@ data MissingDep = MissingDep , neededBy :: [FilePath] } deriving (Generic, ToJSON) +-- | Missing assets are the same thing as missing dependencies, +-- but should not be confused (and also serialise differently +-- to json) newtype MissingAsset = MissingAsset MissingDep - +-- | given this config, should the result be considered to have failed? resultIsFatal :: LintConfig' -> DirResult -> Bool resultIsFatal config res = not (null (dirresultMissingAssets res)) - && configMaxLintLevel config <= maxObservedLevel - where maxObservedLevel = maximum - . map hintLevel - . concatMap (keys . mapresultLayer) - . elems - . dirresultMaps - $ res - - - + && configMaxLintLevel config <= maximumLintLevel res + +-- | maximum lint level that was observed anywhere in any map. +-- note that it really does go through all lints, so don't +-- call it too often +maximumLintLevel :: DirResult -> Level +maximumLintLevel = maximum + . map hintLevel + . concatMap (keys . mapresultLayer) + . elems + . dirresultMaps instance ToJSON DirResult where toJSON res = A.object [ "missingDeps" .= dirresultDeps res , "missingAssets" .= dirresultMissingAssets res , "mapLints" .= dirresultMaps res + , "severity" .= maximumLintLevel res ] instance ToJSON MissingAsset where -- cgit v1.2.3 From f9c693bff9f29a939afaa1e666a411464541210c Mon Sep 17 00:00:00 2001 From: stuebinm Date: Tue, 23 Nov 2021 19:20:56 +0100 Subject: why oh why does the prelude contain unsafe functions some parts of haskell are really, really old … --- lib/CheckDir.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/CheckDir.hs b/lib/CheckDir.hs index 61ac81c..3901336 100644 --- a/lib/CheckDir.hs +++ b/lib/CheckDir.hs @@ -72,7 +72,7 @@ resultIsFatal config res = -- note that it really does go through all lints, so don't -- call it too often maximumLintLevel :: DirResult -> Level -maximumLintLevel = maximum +maximumLintLevel = (\t -> if null t then Info else maximum t) . map hintLevel . concatMap (keys . mapresultLayer) . elems -- cgit v1.2.3