From b17396b2eeefdf113b862b254cb152557bebf68d Mon Sep 17 00:00:00 2001 From: stuebinm Date: Sat, 18 Sep 2021 00:27:22 +0200 Subject: tame the strings Adds a PrettyPrint typeclass which operates on Text and should replace Show, since constantly converting strings from linked lists to arrays seems somewhat silly. --- lib/Properties.hs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'lib/Properties.hs') diff --git a/lib/Properties.hs b/lib/Properties.hs index 10cbf2c..f4dff3d 100644 --- a/lib/Properties.hs +++ b/lib/Properties.hs @@ -11,7 +11,7 @@ import Data.Aeson as Aeson (Value (String)) import Data.Map (Map, (!?)) import Data.Text (Text) import Tiled2 (Layer (layerProperties)) -import Util (quote, showAeson) +import Util (prettyprint) import LintWriter (Hint, LintWriter, Level(..), hint, assertWarn, complain, forbid, info, @@ -54,7 +54,7 @@ checkProperty' layer prop ty = case ty of "jitsiRoom" -> do propEqual prop "type" "string" urlValue <- lift $ getAttr prop "value" - info $ "found jitsi room: " <> showAeson urlValue + info $ "found jitsi room: " <> prettyprint urlValue suggestPropertyValue "jitsiTrigger" "onaction" "jitsiTrigger" -> requireProperty "jitsiRoom" @@ -79,16 +79,17 @@ checkProperty' layer prop ty = case ty of "startLayer" -> pure () -- could also make this a "hard error" (i.e. Left), but then it -- stops checking other properties as checkLayer short-circuits. - _ -> warn $ "unknown property type " <> quote ty + _ -> warn $ "unknown property type " <> prettyprint ty where -- | require some property in this layer requireProperty name = unless (hasProperty name layer) - $ complain $ "property "<>quote name<>" requires property "<>quote ty + $ complain $ "property "<>prettyprint name<>" requires property "<>prettyprint ty -- | This property is forbidden and should not be used - isForbidden = forbid $ "property " <> quote ty <> " should not be used" + isForbidden = forbid $ "property " <> prettyprint ty <> " should not be used" -- TODO: check if the property has the correct value + suggestPropertyValue :: Text -> Text -> LintWriter () suggestPropertyValue name value = unless (hasProperty name layer) - $ suggest $ "set property " <> quote name <> " to " <> quote value + $ suggest $ "set property " <> prettyprint name <> " to " <> prettyprint value @@ -108,6 +109,6 @@ getAttr props name = unwrapWarn msg $ props !? name propEqual :: Properties -> Text -> Aeson.Value -> LintWriter () propEqual props name value = do value' <- lift $ getAttr props name - assertWarn ("field "<>name<>" has unexpected value "<>showAeson value' - <>", should be "<>showAeson value) + assertWarn ("field "<>name<>" has unexpected value "<>prettyprint value' + <>", should be "<>prettyprint value) $ value' == value -- cgit v1.2.3