server: add tshow :: Show a => a -> Text, including hlint hint (#142)

GitOrigin-RevId: 627a55533831b51aa0d01f8a8d95e3d013744dc5
This commit is contained in:
Auke Booij 2020-12-08 13:37:35 +01:00 committed by hasura-bot
parent f5e56e8981
commit 5edca3a5c2
3 changed files with 9 additions and 4 deletions

View File

@ -110,6 +110,7 @@
- warn: {lhs: "case x of {Nothing -> a; Just b -> return b}", rhs: "onNothing x a"}
- warn: {lhs: "case x of {Just b -> return b; Nothing -> a}", rhs: "onNothing x a"}
- warn: {lhs: "fromMaybe [] x", rhs: "maybeToList x"}
- warn: {lhs: "Data.Text.pack (Prelude.show x)", rhs: "Hasura.Prelude.tshow x"}
- group:
name: data-text-extended

View File

@ -16,6 +16,7 @@ module Hasura.Prelude
, spanMaybeM
, liftEitherM
, hoistMaybe
, tshow
-- * Efficient coercions
, coerce
, findWithIndex
@ -184,3 +185,6 @@ startTimer = do
-- copied from http://hackage.haskell.org/package/errors-2.3.0/docs/src/Control.Error.Util.html#hoistMaybe
hoistMaybe :: (Monad m) => Maybe b -> MaybeT m b
hoistMaybe = MaybeT . return
tshow :: Show a => a -> Text
tshow = T.pack . show

View File

@ -1,7 +1,7 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Network.URI.Extended
(module Network.URI
( module Network.URI
)
where
@ -20,10 +20,10 @@ instance {-# INCOHERENT #-} FromJSON URI where
parseJSON _ = fail "not a valid URI"
instance {-# INCOHERENT #-} ToJSON URI where
toJSON = String . T.pack . show
toJSON = String . tshow
instance {-# INCOHERENT #-} ToJSONKey URI where
toJSONKey = toJSONKeyText (T.pack . show)
toJSONKey = toJSONKeyText tshow
instance Hashable URI where
hashWithSalt i = hashWithSalt i . (T.pack . show)
hashWithSalt i = hashWithSalt i . tshow