on master help sign in
route: Clean up lint
commitb2684bd30e969808c03e1113e8f20b11b2688b79 authorElliot Cameron <eacameron@gmail.com> dateWed 17 Jun 2020, 17:34 (6 years ago) parent7d890d6
2 files changed+23−24
lib/route/src/Obelisk/Route.hs+14−15 lib/route/src/Obelisk/Route/Frontend.hs+9−9
lib/route/src/Obelisk/Route.hs+14−15
@@ -6,7 +6,6 @@
66{-# LANGUAGE FlexibleContexts #-}
77{-# LANGUAGE FlexibleInstances #-}
88{-# LANGUAGE GADTs #-}
9−{-# LANGUAGE KindSignatures #-}
109{-# LANGUAGE LambdaCase #-}
1110{-# LANGUAGE MultiParamTypeClasses #-}
1211{-# LANGUAGE OverloadedStrings #-}
@@ -140,7 +139,6 @@ import Control.Lens
140139 , view
141140 , Wrapped (..)
142141 )
143−
144142import Control.Monad.Except
145143import qualified Control.Monad.State.Strict as State
146144import Control.Monad.Trans (lift)
@@ -154,6 +152,7 @@ import qualified Data.Dependent.Map as DMap
154152import Data.Dependent.Sum (DSum (..))
155153import Data.Either.Validation (Validation (..))
156154import Data.Foldable
155+import Data.Functor (($>))
157156import Data.Functor.Sum
158157import Data.GADT.Compare
159158import Data.GADT.Compare.TH
@@ -304,13 +303,13 @@ decode e x = runIdentity (tryDecode e x)
304303-- | Once an 'Encoder' has been checked, so that its check monad has become 'Identity', even if the same is not true of the
305304-- parse monad, we may still attempt to decode with it in its parse monad.
306305tryDecode :: Encoder Identity parse decoded encoded -> encoded -> parse decoded
307−tryDecode (Encoder (Identity impl)) x = _encoderImpl_decode impl x
306+tryDecode (Encoder (Identity impl)) = _encoderImpl_decode impl
308307
309308-- | Similar to 'decode', once an encoder has been checked so that its check monad is Identity, it
310309-- can be used to actually encode by using this. Note that while there's no constraint on the parse monad here,
311310-- one should usually be applying decode and encode to the same 'Encoder'
312311encode :: Encoder Identity parse decoded encoded -> decoded -> encoded
313−encode (Encoder (Identity impl)) x = _encoderImpl_encode impl x
312+encode (Encoder (Identity impl)) = _encoderImpl_encode impl
314313
315314-- | This is a primitive used to build encoders which can't fail to check. It should not be used unless one is
316315-- reasonably certain that the law given for 'EncoderImpl' above holds.
@@ -555,11 +554,11 @@ pathComponentEncoder f = Encoder $ do
555554 unEncoder (pathComponentEncoderImpl (enum1Encoder (extractPathSegment . f)) f')
556555
557556pathComponentEncoderImpl :: forall check parse p. (Monad check, Monad parse)
558− => (Encoder check parse (Some p) (Maybe Text))
557+ => Encoder check parse (Some p) (Maybe Text)
559558 -> (forall a. p a -> Encoder Identity parse a PageName)
560559 -> Encoder check parse (R p) PageName
561−pathComponentEncoderImpl this rest =
562− chainEncoder (lensEncoder (\(_, b) a -> (a, b)) Prelude.fst consEncoder) this rest
560+pathComponentEncoderImpl =
561+ chainEncoder (lensEncoder (\(_, b) a -> (a, b)) Prelude.fst consEncoder)
563562
564563--NOTE: Naming convention in this module is to always talk about things in the *encoding* direction, never in the *decoding* direction
565564
@@ -815,7 +814,7 @@ rPrism
815814 :: forall f f'
816815 . (forall a. Prism' (f a) (f' a))
817816 -> Prism' (R f) (R f')
818−rPrism p = dSumPrism p
817+rPrism = dSumPrism
819818
820819dSumPrism'
821820 :: forall f g a
@@ -827,7 +826,7 @@ dSumGEqPrism
827826 :: GEq f
828827 => f a
829828 -> Prism' (DSum f g) (g a)
830−dSumGEqPrism variant = dSumPrism' $ prism' (\Refl -> variant) (\x -> geq variant x)
829+dSumGEqPrism variant = dSumPrism' $ prism' (\Refl -> variant) (geq variant)
831830
832831-- | Given a 'tag :: f a', make a prism for 'R f'. This generalizes the usual
833832-- prisms for a sum type (the ones that 'mkPrisms' would make), just as 'R'
@@ -994,9 +993,9 @@ obeliskRouteSegment r appRouteSegment = case r of
994993-- be combined with other such segment encoders before 'pathComponentEncoder' turns it into a proper 'Encoder'.
995994resourceRouteSegment :: (MonadError Text check, MonadError Text parse) => ResourceRoute a -> SegmentResult check parse a
996995resourceRouteSegment = \case
997− ResourceRoute_Static -> PathSegment "static" $ pathOnlyEncoderIgnoringQuery
998− ResourceRoute_Ghcjs -> PathSegment "ghcjs" $ pathOnlyEncoder
999− ResourceRoute_JSaddleWarp -> PathSegment "jsaddle" $ jsaddleWarpRouteEncoder
996+ ResourceRoute_Static -> PathSegment "static" pathOnlyEncoderIgnoringQuery
997+ ResourceRoute_Ghcjs -> PathSegment "ghcjs" pathOnlyEncoder
998+ ResourceRoute_JSaddleWarp -> PathSegment "jsaddle" jsaddleWarpRouteEncoder
1000999 ResourceRoute_Version -> PathSegment "version" $ unitEncoder mempty
10011000
10021001data JSaddleWarpRoute :: * -> * where
@@ -1008,7 +1007,7 @@ jsaddleWarpRouteEncoder :: (MonadError Text check, MonadError Text parse) => Enc
10081007jsaddleWarpRouteEncoder = pathComponentEncoder $ \case
10091008 JSaddleWarpRoute_JavaScript -> PathSegment "jsaddle.js" $ unitEncoder mempty
10101009 JSaddleWarpRoute_WebSocket -> PathEnd $ unitEncoder mempty
1011− JSaddleWarpRoute_Sync -> PathSegment "sync" $ pathOnlyEncoder
1010+ JSaddleWarpRoute_Sync -> PathSegment "sync" pathOnlyEncoder
10121011
10131012instance GShow appRoute => GShow (ObeliskRoute appRoute) where
10141013 gshowsPrec prec = \case
@@ -1084,7 +1083,7 @@ readShowEncoder :: (MonadError Text parse, Read a, Show a, Applicative check) =>
10841083readShowEncoder = singlePathSegmentEncoder . unsafeTshowEncoder
10851084
10861085integralEncoder :: (MonadError Text parse, Applicative check, Integral a) => Encoder check parse a Integer
1087−integralEncoder = reviewEncoder (Numeric.Lens.integral)
1086+integralEncoder = reviewEncoder Numeric.Lens.integral
10881087
10891088pathSegmentEncoder :: (MonadError Text parse, Applicative check, Cons as as a a) =>
10901089 Encoder check parse (a, (as, b)) (as, b)
@@ -1159,7 +1158,7 @@ pathFieldEncoder fieldEncoder = unsafeEncoder $ do
11591158 fieldEncoderPure f = toEncoder (DMap.findWithDefault (error "bad") f fieldEncoderPureMap)
11601159 pure $ EncoderImpl
11611160 { _encoderImpl_encode = \(x, rest) -> execWriter $ do
1162− _ <- traverseWithField (\f x_i -> tell (pure $ encode (fieldEncoderPure f) x_i) *> pure x_i) x
1161+ _ <- traverseWithField (\f x_i -> tell (pure $ encode (fieldEncoderPure f) x_i) $> x_i) x
11631162 tell rest
11641163 , _encoderImpl_decode = State.runStateT $ tabulateFieldsA $ \f -> State.get >>= \case
11651164 [] -> throwError $ T.pack "not enough path components"
lib/route/src/Obelisk/Route/Frontend.hs+9−9
@@ -1,24 +1,24 @@
1−{-# LANGUAGE ApplicativeDo #-}
21{-# LANGUAGE CPP #-}
3−{-# LANGUAGE RecursiveDo #-}
4−{-# LANGUAGE StandaloneDeriving #-}
2+{-# LANGUAGE ApplicativeDo #-}
53{-# LANGUAGE ConstraintKinds #-}
4+{-# LANGUAGE DataKinds #-}
65{-# LANGUAGE DefaultSignatures #-}
76{-# LANGUAGE FlexibleContexts #-}
87{-# LANGUAGE FlexibleInstances #-}
8+{-# LANGUAGE FunctionalDependencies #-}
99{-# LANGUAGE GADTs #-}
10+{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1011{-# LANGUAGE LambdaCase #-}
1112{-# LANGUAGE OverloadedStrings #-}
1213{-# LANGUAGE PatternSynonyms #-}
1314{-# LANGUAGE RankNTypes #-}
15+{-# LANGUAGE RecursiveDo #-}
1416{-# LANGUAGE ScopedTypeVariables #-}
17+{-# LANGUAGE StandaloneDeriving #-}
1518{-# LANGUAGE TypeFamilies #-}
1619{-# LANGUAGE TypeOperators #-}
17−{-# LANGUAGE ViewPatterns #-}
18−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
1920{-# LANGUAGE UndecidableInstances #-}
20−{-# LANGUAGE DataKinds #-}
21−{-# LANGUAGE FunctionalDependencies #-}
21+{-# LANGUAGE ViewPatterns #-}
2222
2323module Obelisk.Route.Frontend
2424 ( module Obelisk.Route
@@ -254,7 +254,7 @@ dynamicIdentityCoercion = unsafeCoerce (Coercion :: Coercion (Identity ()) ()) -
254254factorRouted :: (Reflex t, MonadFix m, MonadHold t m, GEq f) => RoutedT t (DSum f (Dynamic t)) m a -> RoutedT t (DSum f Identity) m a
255255factorRouted r = RoutedT $ ReaderT $ \d -> do
256256 d' <- factorDyn d
257− runRoutedT r $ (coerceWith (dynamicCoercion $ dsumValueCoercion dynamicIdentityCoercion) d')
257+ runRoutedT r $ coerceWith (dynamicCoercion $ dsumValueCoercion dynamicIdentityCoercion) d'
258258
259259maybeRouted :: (Reflex t, MonadFix m, MonadHold t m) => RoutedT t (Maybe (Dynamic t a)) m b -> RoutedT t (Maybe a) m b
260260maybeRouted r = RoutedT $ ReaderT $ \d -> do
@@ -462,7 +462,7 @@ runRouteViewT
462462 , MonadJSM (Performable m)
463463 , MonadFix m
464464 )
465− => (Encoder Identity Identity r PageName)
465+ => Encoder Identity Identity r PageName
466466 --TODO: Get rid of the switchover and useHash arguments
467467 -- useHash can probably be baked into the encoder
468468 -> Event t () -- ^ Switchover event, nothing is done until this event fires. Used to prevent incorrect DOM expectations at hydration switchover time