From efb64e0228c19ef7936446d3ca14a7d7a6e2540b Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sun, 28 Nov 2021 22:24:30 +0100 Subject: various fixes to bugs Among them - always set correct exit codes - refuse to write out files if the out path already exists - calculate the overall severity correctly - slightly changed the json output schema - also output the text output format in json - make the default config.json suitable for a production environment --- lib/CheckDir.hs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'lib/CheckDir.hs') diff --git a/lib/CheckDir.hs b/lib/CheckDir.hs index 3901336..d5ea440 100644 --- a/lib/CheckDir.hs +++ b/lib/CheckDir.hs @@ -64,25 +64,35 @@ 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 <= maximumLintLevel res +resultIsFatal config res = maximumLintLevel res > configMaxLintLevel config -- | 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 = (\t -> if null t then Info else maximum t) - . map hintLevel - . concatMap (keys . mapresultLayer) - . elems - . dirresultMaps +maximumLintLevel res + | not (null (dirresultMissingAssets res)) = Fatal + | otherwise = + (\t -> if null t then Info else maximum t) + . map hintLevel + . concatMap (\map -> keys (mapresultLayer map) + <> keys (mapresultTileset map) + <> mapresultGeneral map + ) + . elems + . dirresultMaps + $ res + + instance ToJSON DirResult where - toJSON res = A.object - [ "missingDeps" .= dirresultDeps res - , "missingAssets" .= dirresultMissingAssets res - , "mapLints" .= dirresultMaps res + toJSON res = A.object [ + "result" .= A.object + [ "missingDeps" .= dirresultDeps res + , "missingAssets" .= dirresultMissingAssets res + , "mapLints" .= dirresultMaps res + ] + , "resultText" .= prettyprint (Suggestion, res) , "severity" .= maximumLintLevel res ] -- cgit v1.2.3