Skip to content

Commit

Permalink
server: add tshow :: Show a => a -> Text, including hlint hint (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
Auke Booij authored Dec 8, 2020
1 parent 8c80998 commit 627a555
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions server/.hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions server/src-lib/Hasura/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Hasura.Prelude
, spanMaybeM
, liftEitherM
, hoistMaybe
, tshow
-- * Efficient coercions
, coerce
, findWithIndex
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions server/src-lib/Network/URI/Extended.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{-# OPTIONS_GHC -fno-warn-orphans #-}

module Network.URI.Extended
(module Network.URI
( module Network.URI
)
where

Expand All @@ -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

0 comments on commit 627a555

Please sign in to comment.