summaryrefslogtreecommitdiff
path: root/lib/Properties.hs
diff options
context:
space:
mode:
authorstuebinm2021-09-18 00:27:22 +0200
committerstuebinm2021-09-18 00:27:22 +0200
commitb17396b2eeefdf113b862b254cb152557bebf68d (patch)
tree09ab8776b87a7c193d08144b3d40ecd4f249f11e /lib/Properties.hs
parentbfe45dc4996537b72436f4041d0ca819aa3444e1 (diff)
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.
Diffstat (limited to 'lib/Properties.hs')
-rw-r--r--lib/Properties.hs17
1 files changed, 9 insertions, 8 deletions
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