Skip to content
Snippets Groups Projects
Commit 6a67d3e4 authored by stuebinm's avatar stuebinm
Browse files

lints for names that are used more than twice

(previously it would just lint "can't use name twice" multiple times,
which looks kind of silly)
parent bbde46e7
Branches
No related tags found
No related merge requests found
...@@ -14,7 +14,8 @@ import Control.Monad (forM_, unless, when) ...@@ -14,7 +14,8 @@ import Control.Monad (forM_, unless, when)
import Data.Text (Text, isPrefixOf) import Data.Text (Text, isPrefixOf)
import qualified Data.Vector as V import qualified Data.Vector as V
import Tiled (Layer (..), Object (..), Property (..), import Tiled (Layer (..), Object (..), Property (..),
PropertyValue (..), Tiledmap (..), Tileset (..)) PropertyValue (..), Tile (..), Tiledmap (..),
Tileset (..))
import TiledAbstract (HasName (..), HasProperties (..), import TiledAbstract (HasName (..), HasProperties (..),
HasTypeName (..), IsProperty (..)) HasTypeName (..), IsProperty (..))
import Util (layerIsEmpty, mkProxy, naiveEscapeHTML, import Util (layerIsEmpty, mkProxy, naiveEscapeHTML,
...@@ -368,13 +369,18 @@ refuseDoubledNames ...@@ -368,13 +369,18 @@ refuseDoubledNames
=> (Foldable t, Functor t) => (Foldable t, Functor t)
=> t a => t a
-> LintWriter b -> LintWriter b
refuseDoubledNames things = foldr folding base things mempty refuseDoubledNames things = foldr folding base things (mempty,mempty)
where where
-- this accumulates a function that complains about things it's already seen -- this accumulates a function that complains about things it's
folding thing cont seen = do -- already seen, except if they've already occured twice and then
when (name `elem` seen) -- occur again …
$ complain $ "cannot use " <> typeName (mkProxy thing) <> " name \"" <> name <> "\" twice" folding thing cont (seen, twice)
cont (S.insert name seen) | name `elem` seen && name `notElem` twice = do
complain $ "cannot use " <> typeName (mkProxy thing)
<> " name \"" <> name <> "\" multiple times."
cont (seen, S.insert name twice)
| otherwise =
cont (S.insert name seen, twice)
where name = getName thing where name = getName thing
base _ = pure () base _ = pure ()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment