Skip to content
Snippets Groups Projects
Commit 687e2369 authored by stuebinm's avatar stuebinm
Browse files

missing entrypoints can be non-fatal

parents ee61cc5c f992cb79
No related branches found
No related tags found
No related merge requests found
Pipeline #11959 passed
......@@ -19,8 +19,8 @@ import Data.Functor ((<&>))
import Data.Map (Map, elems, keys)
import qualified Data.Map as M
import Data.Map.Strict (mapKeys, mapWithKey, (\\))
import Data.Maybe (mapMaybe)
import Data.Text (Text)
import Data.Maybe (mapMaybe, isJust)
import Data.Text (Text, isInfixOf)
import qualified Data.Text as T
import Dirgraph (graphToDot, invertGraph, resultToGraph,
unreachableFrom)
......@@ -57,7 +57,8 @@ data DirResult = DirResult
} deriving (Generic)
data MissingDep = MissingDep
{ entrypoint :: Text
{ depFatal :: Maybe Bool
, entrypoint :: Text
, neededBy :: [FilePath]
} deriving (Generic, ToJSON)
......@@ -69,7 +70,7 @@ 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)
not (null (dirresultMissingAssets res) || not (any (isJust . depFatal) (dirresultDeps res)))
|| maximumLintLevel res > configMaxLintLevel config
-- | maximum lint level that was observed anywhere in any map.
......@@ -124,7 +125,7 @@ instance PrettyPrint (Level, DirResult) where
"\nin " <> T.pack p <> ":\n" <> prettyprint (level, lint)
instance PrettyPrint MissingDep where
prettyprint (MissingDep f n) =
prettyprint (MissingDep _ f n) =
" - " <> f <> " does not exist, but is required by "
<> prettyDependents <> "\n"
where
......@@ -172,7 +173,7 @@ recursiveCheckDir config prefix root = do
missingDeps :: FilePath -> Map FilePath MapResult -> [MissingDep]
missingDeps entrypoint maps =
let simple = M.insert (T.pack entrypoint) [] used \\ M.union defined trivial
in M.foldMapWithKey (\f n -> [MissingDep f n]) simple
in M.foldMapWithKey (\f n -> [MissingDep (Just $ not ("#" `isInfixOf` f)) f n]) simple
where
-- which maps are linked somewhere?
used :: Map Text [FilePath]
......@@ -201,7 +202,7 @@ missingAssets prefix maps =
let asset = normalise (takeDirectory path) relpath
in doesFileExist (prefix </> asset) <&>
\case True -> Nothing
False -> Just $ MissingDep (T.pack asset) [path]
False -> Just $ MissingDep Nothing (T.pack asset) [path]
_ -> pure Nothing)
(mapresultDepends mapres)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment