summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstuebinm2021-11-17 00:51:21 +0100
committerstuebinm2021-11-17 00:51:21 +0100
commita572b9e1b113e0c8bea94c4f561c35742cdf4aeb (patch)
tree478e848a77a5289356bb9acef8746f347f0b6275
parent7b079ff7a66ea0d7baa12fa16f084f025c1c9fce (diff)
exit with code 1 if maximum lint level exceeded
Diffstat (limited to '')
-rw-r--r--config.json2
-rw-r--r--lib/CheckDir.hs26
-rw-r--r--lib/LintConfig.hs2
-rw-r--r--lib/WriteRepo.hs11
4 files changed, 26 insertions, 15 deletions
diff --git a/config.json b/config.json
index f52e1a2..4870974 100644
--- a/config.json
+++ b/config.json
@@ -2,7 +2,7 @@
"AssemblyTag":"assemblyname",
"ScriptInject":null,
"AllowScripts":true,
- "MaxWarnLevel":"Suggestion",
+ "MaxLintLevel":"Suggestion",
"DontCopyAssets":true,
"LinkPrefix":"https://exit.rc3.world?link="
}
diff --git a/lib/CheckDir.hs b/lib/CheckDir.hs
index 4d81bc2..680039c 100644
--- a/lib/CheckDir.hs
+++ b/lib/CheckDir.hs
@@ -4,32 +4,33 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
+{-# LANGUAGE TypeFamilies #-}
-- | Module that contains high-level checking for an entire directory
module CheckDir (recursiveCheckDir, DirResult(..), resultIsFatal) where
-import CheckMap (MapResult (mapresultProvides),
- loadAndLintMap, mapresultDepends)
+import CheckMap (MapResult (..), loadAndLintMap)
import Control.Monad (void)
import Control.Monad.Extra (mapMaybeM)
import Data.Aeson (ToJSON, (.=))
import qualified Data.Aeson as A
import Data.Foldable (fold)
import Data.Functor ((<&>))
-import Data.Map (Map)
+import Data.Map (Map, elems, keys)
import qualified Data.Map as M
import Data.Map.Strict (mapKeys, (\\))
import Data.Maybe (mapMaybe)
import Data.Text (Text)
import qualified Data.Text as T
import GHC.Generics (Generic)
-import LintConfig (LintConfig')
+import LintConfig (LintConfig', configMaxLintLevel)
import Paths (normalise, normaliseWithFrag)
import System.Directory.Extra (doesFileExist)
import System.FilePath (splitPath, (</>))
import qualified System.FilePath as FP
import System.FilePath.Posix (takeDirectory)
-import Types (Dep (Local, LocalMap), Level)
+import Types (Dep (Local, LocalMap), Level (..),
+ hintLevel)
import Util (PrettyPrint (prettyprint))
@@ -59,9 +60,18 @@ data MissingDep = MissingDep
newtype MissingAsset = MissingAsset MissingDep
-resultIsFatal :: DirResult -> Bool
-resultIsFatal res =
- not $ null (dirresultMissingAssets res)
+resultIsFatal :: LintConfig' -> DirResult -> Bool
+resultIsFatal config res =
+ (not (null (dirresultMissingAssets res)))
+ && (configMaxLintLevel config) <= maxObservedLevel
+ where maxObservedLevel = maximum
+ . map hintLevel
+ . concatMap keys
+ . map mapresultLayer
+ . elems
+ . dirresultMaps
+ $ res
+
diff --git a/lib/LintConfig.hs b/lib/LintConfig.hs
index 5c1ae20..d237356 100644
--- a/lib/LintConfig.hs
+++ b/lib/LintConfig.hs
@@ -34,7 +34,7 @@ data LintConfig f = LintConfig
-- ^ Link to Script that should be injected
, configAssemblyTag :: HKD f Text
-- ^ Assembly name (used for jitsiRoomAdminTag)
- , configMaxWarnLevel :: HKD f Level
+ , configMaxLintLevel :: HKD f Level
-- ^ Maximum warn level allowed before the lint fails
, configDontCopyAssets :: HKD f Bool
-- ^ Don't copy map assets (mostly useful for development)
diff --git a/lib/WriteRepo.hs b/lib/WriteRepo.hs
index 89e1bea..fbe139b 100644
--- a/lib/WriteRepo.hs
+++ b/lib/WriteRepo.hs
@@ -5,9 +5,8 @@
-- | Module for writing an already linted map Repository back out again.
module WriteRepo where
-import CheckDir (DirResult (dirresultMaps),
- resultIsFatal)
-import CheckMap (MapResult (mapresultAdjusted, mapresultDepends))
+import CheckDir (DirResult (..), resultIsFatal)
+import CheckMap (MapResult (..))
import Control.Monad (forM_, unless)
import Data.Aeson (encodeFile)
import Data.Map.Strict (toList)
@@ -25,11 +24,13 @@ import System.FilePath.Posix ((</>))
import Types (Dep (Local))
+
writeAdjustedRepository :: LintConfig' -> FilePath -> FilePath -> DirResult -> IO ExitCode
writeAdjustedRepository config inPath outPath result
- | resultIsFatal result && not (configDontCopyAssets config) = do
- -- putStrLn "FATAL: Repository has missing assets; cannot write to outPath"
+ | resultIsFatal config result =
pure (ExitFailure 1)
+ | not (configDontCopyAssets config) =
+ pure (ExitSuccess)
| otherwise = do
createDirectoryIfMissing True outPath