Skip to content
Snippets Groups Projects
Commit 887540e3 authored by stuebinm's avatar stuebinm
Browse files

don't print doubled lints twice

parent 73feaafc
No related branches found
No related tags found
No related merge requests found
......@@ -30,8 +30,7 @@ import Properties (checkLayer, checkMap, checkTileset)
import Tiled (Layer (layerLayers, layerName),
LoadResult (..),
Tiledmap (tiledmapLayers, tiledmapTilesets),
Tileset, loadTiledmap)
import TiledAbstract (HasName (..))
loadTiledmap)
import Types (Dep, Hint (Hint, hintLevel, hintMsg),
Level (..), lintsToHints)
import Util (PrettyPrint (prettyprint), prettyprint)
......@@ -40,9 +39,9 @@ import Util (PrettyPrint (prettyprint), prettyprint)
-- | What this linter produces: lints for a single map
data MapResult = MapResult
{ mapresultLayer :: Map Hint [Layer]
{ mapresultLayer :: Map Hint [Text]
-- ^ lints that occurred in one or more layers
, mapresultTileset :: Map Hint [Tileset]
, mapresultTileset :: Map Hint [Text]
-- ^ lints that occurred in one or more tilesets
, mapresultDepends :: [Dep]
-- ^ (external and local) dependencies of this map
......@@ -58,8 +57,8 @@ data MapResult = MapResult
instance ToJSON MapResult where
toJSON res = A.object
[ "layer" .= CollectedLints (fmap getName <$> mapresultLayer res)
, "tileset" .= CollectedLints (fmap getName <$> mapresultTileset res)
[ "layer" .= CollectedLints (mapresultLayer res)
, "tileset" .= CollectedLints (mapresultTileset res)
, "general" .= mapresultGeneral res
, "offers" .= mapresultProvides res
]
......@@ -178,7 +177,7 @@ instance PrettyPrint (Level, MapResult) where
-- | pretty-prints a collection of Hints, printing each
-- Hint only once, then a list of its occurences line-wrapped
-- to fit onto a decent-sized terminal
prettyLints :: HasName a => (MapResult -> Map Hint [a]) -> [Text]
prettyLints :: (MapResult -> Map Hint [Text]) -> [Text]
prettyLints getter = fmap
(\(h, cs) -> prettyprint h
<> "\n (in "
......@@ -188,7 +187,7 @@ instance PrettyPrint (Level, MapResult) where
_ | l < 70 -> (l+2+T.length c, a <> ", " <> c)
_ -> (6+T.length c, a <> ",\n " <> c)
)
(0, "") (fmap getName cs))
(0, "") cs)
<> ")\n")
(toList . getter $ mapResult)
......
......@@ -52,8 +52,9 @@ import Control.Monad.Writer.Lazy (lift)
import Data.Bifunctor (Bifunctor (second))
import Data.Map (Map, fromListWith)
import Data.Maybe (mapMaybe)
import qualified Data.Set as S
import LintConfig (LintConfig')
import TiledAbstract (HasName)
import TiledAbstract (HasName (getName))
import Types (Dep, Hint, Level (..), Lint (..),
hint, lintsToHints)
......@@ -106,9 +107,9 @@ zoom embed extract operation = do
-- | "invert" a linter's result, grouping lints by their messages
invertLintResult :: HasName ctxt => LintResult ctxt -> Map Hint [ctxt]
invertLintResult :: HasName ctxt => LintResult ctxt -> Map Hint [Text]
invertLintResult (LinterState (lints, ctxt)) =
fromListWith (<>) $ (, [ctxt]) <$> lintsToHints lints
fmap (S.toList . S.fromList . fmap getName) . fromListWith (<>) $ (, [ctxt]) <$> lintsToHints lints
resultToDeps :: LintResult a -> [Dep]
resultToDeps (LinterState (lints,_)) = mapMaybe lintToDep lints
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment