Skip to content

Commit 441f8bd

Browse files
committed
Third pass, now with fourmolu-0.18.0.0
1 parent e1a2157 commit 441f8bd

File tree

142 files changed

+806
-664
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+806
-664
lines changed

.github/workflows/code-style.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Code style check
2+
3+
concurrency:
4+
group: formatting-${{ github.ref_name }}
5+
cancel-in-progress: true
6+
7+
on:
8+
push:
9+
branches:
10+
- master
11+
pull_request:
12+
workflow_dispatch: {}
13+
14+
jobs:
15+
formatting:
16+
steps:
17+
- name: Checkout Code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 1
21+
- name: Install Nix
22+
uses: cachix/install-nix-action@v31
23+
- name: Check code formatting
24+
run: |
25+
nix develop '#formatters' --command fourmolu --mode=check --check-idempotence servant servant-*

CONTRIBUTING.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ Some things we like:
3535
- Few dependencies
3636
- -Werror-compatible (7.8, 7.10 and 8.0)
3737

38-
Though we aren't sticklers for style, the `fourmolu.yaml` and `HLint.hs` files in the repository provide a good baseline for consistency.
39-
For nix, `nixfmt-rfc-style` is preferred.
38+
Haskell code should be formatted with `fourmolu` (`>= 0.18.0.0`).
39+
Please try to avoid introducing new `hlint` warnings.
40+
For Nix files, `nixfmt-rfc-style` is preferred.
4041

4142
**Important**: please do not modify the versions of the servant packages you are sending patches for.
4243

flake.nix

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
let
1818
pkgs = import nixpkgs { inherit system; };
1919

20+
format-tools = [
21+
# We use fourmolu compiled with GHC 9.12
22+
# as getting it to compile with lower GHC versions
23+
# is complicated and this works out of the box.
24+
pkgs.haskell.packages.ghc912.fourmolu_0_18_0_0
25+
pkgs.nixfmt-rfc-style
26+
];
27+
2028
mkDevShell =
2129
{
2230
compiler ? "ghc92",
@@ -44,10 +52,9 @@
4452
postgresql
4553
openssl
4654
stack
47-
fourmolu
48-
nixfmt-rfc-style
4955
haskellPackages.hspec-discover
5056
]
57+
++ format-tools
5158
++ (
5259
if tutorial then
5360
[
@@ -68,6 +75,9 @@
6875
devShells = {
6976
default = mkDevShell { };
7077
tutorial = mkDevShell { tutorial = true; };
78+
formatters = pkgs.mkShell {
79+
buildInputs = format-tools;
80+
};
7181
};
7282
}
7383
);

servant-auth/servant-auth-client/src/Servant/Auth/Client/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Servant.Client.Core
2020

2121
-- | A simple bearer token.
2222
newtype Token = Token {getToken :: BS.ByteString}
23-
deriving (Eq, Show, Read, Generic, IsString)
23+
deriving (Eq, Generic, IsString, Read, Show)
2424

2525
type family HasBearer xs :: Constraint where
2626
HasBearer (Bearer ': xs) = ()

servant-auth/servant-auth-client/test/Servant/Auth/ClientSpec.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ import Control.Monad.Trans.Except (runExceptT)
4242
#define ClientError ServantError
4343
#endif
4444

45-
import Servant.Auth.Client
4645
import Servant.Auth.Server
4746
import Servant.Auth.Server.SetCookieOrphan ()
4847

48+
import Servant.Auth.Client
49+
4950
spec :: Spec
5051
spec = describe "The JWT combinator" $ do
5152
hasClientSpec
@@ -152,7 +153,7 @@ data User = User
152153
{ name :: String
153154
, _id :: String
154155
}
155-
deriving (Eq, Show, Read, Generic)
156+
deriving (Eq, Generic, Read, Show)
156157

157158
instance FromJWT User
158159

servant-auth/servant-auth-docs/src/Servant/Auth/Docs.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class AllDocs (x :: [Type]) where
6969
-- intro, req
7070
-> [(String, String)]
7171

72-
instance (OneDoc a, AllDocs as) => AllDocs (a ': as) where
72+
instance (AllDocs as, OneDoc a) => AllDocs (a ': as) where
7373
allDocs _ = oneDoc (Proxy :: Proxy a) : allDocs (Proxy :: Proxy as)
7474

7575
instance AllDocs '[] where

servant-auth/servant-auth-server/src/Servant/Auth/Server.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ import Data.Default (Default (def))
151151
import Servant (BasicAuthData (..))
152152
import Servant.Auth
153153
import Servant.Auth.JWT
154+
import Web.Cookie (SetCookie)
155+
import Prelude hiding (readFile, writeFile)
156+
154157
import Servant.Auth.Server.Internal ()
155158
import Servant.Auth.Server.Internal.BasicAuth
156159
import Servant.Auth.Server.Internal.Class
@@ -159,8 +162,6 @@ import Servant.Auth.Server.Internal.Cookie
159162
import Servant.Auth.Server.Internal.JWT
160163
import Servant.Auth.Server.Internal.ThrowAll
161164
import Servant.Auth.Server.Internal.Types
162-
import Web.Cookie (SetCookie)
163-
import Prelude hiding (readFile, writeFile)
164165

165166
-- | Generate a key suitable for use with 'defaultConfig'.
166167
generateKey :: IO Jose.JWK

servant-auth/servant-auth-server/src/Servant/Auth/Server/Internal.hs

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,61 +14,63 @@ import Servant
1414
)
1515
import Servant.Auth
1616
import Servant.Auth.JWT (ToJWT)
17+
import Servant.Server.Internal (DelayedIO, addAuthCheck, withRequest)
18+
1719
import Servant.Auth.Server.Internal.AddSetCookie
1820
import Servant.Auth.Server.Internal.Class
1921
import Servant.Auth.Server.Internal.ConfigTypes
2022
import Servant.Auth.Server.Internal.Cookie
2123
import Servant.Auth.Server.Internal.JWT
2224
import Servant.Auth.Server.Internal.Types
23-
import Servant.Server.Internal (DelayedIO, addAuthCheck, withRequest)
2425

2526
instance
26-
( n ~ 'S ('S 'Z)
27-
, HasServer (AddSetCookiesApi n api) ctxs
27+
( -- this constraint is needed to implement hoistServer
28+
AddSetCookies n (ServerT api Handler) (ServerT (AddSetCookiesApi n api) Handler)
2829
, AreAuths auths ctxs v
29-
, HasServer api ctxs -- this constraint is needed to implement hoistServer
30-
, AddSetCookies n (ServerT api Handler) (ServerT (AddSetCookiesApi n api) Handler)
31-
, ToJWT v
3230
, HasContextEntry ctxs CookieSettings
3331
, HasContextEntry ctxs JWTSettings
32+
, HasServer (AddSetCookiesApi n api) ctxs
33+
, HasServer api ctxs
34+
, ToJWT v
35+
, n ~ 'S ('S 'Z)
3436
)
3537
=> HasServer (Auth auths v :> api) ctxs
3638
where
3739
type ServerT (Auth auths v :> api) m = AuthResult v -> ServerT api m
3840

39-
#if MIN_VERSION_servant_server(0,12,0)
40-
hoistServerWithContext _ pc nt s = hoistServerWithContext (Proxy :: Proxy api) pc nt . s
41-
#endif
41+
route _ context subserver =
42+
route
43+
(Proxy :: Proxy (AddSetCookiesApi n api))
44+
context
45+
(fmap go subserver `addAuthCheck` authCheck)
46+
where
47+
authCheck :: DelayedIO (AuthResult v, SetCookieList ('S ('S 'Z)))
48+
authCheck = withRequest $ \req -> liftIO $ do
49+
authResult <- runAuthCheck (runAuths (Proxy :: Proxy auths) context) req
50+
cookies <- makeCookies authResult
51+
return (authResult, cookies)
4252

43-
route _ context subserver =
44-
route
45-
(Proxy :: Proxy (AddSetCookiesApi n api))
46-
context
47-
(fmap go subserver `addAuthCheck` authCheck)
48-
where
49-
authCheck :: DelayedIO (AuthResult v, SetCookieList ('S ('S 'Z)))
50-
authCheck = withRequest $ \req -> liftIO $ do
51-
authResult <- runAuthCheck (runAuths (Proxy :: Proxy auths) context) req
52-
cookies <- makeCookies authResult
53-
return (authResult, cookies)
53+
jwtSettings :: JWTSettings
54+
jwtSettings = getContextEntry context
5455

55-
jwtSettings :: JWTSettings
56-
jwtSettings = getContextEntry context
56+
cookieSettings :: CookieSettings
57+
cookieSettings = getContextEntry context
5758

58-
cookieSettings :: CookieSettings
59-
cookieSettings = getContextEntry context
59+
makeCookies :: AuthResult v -> IO (SetCookieList ('S ('S 'Z)))
60+
makeCookies authResult = do
61+
case authResult of
62+
(Authenticated v) -> do
63+
ejwt <- makeSessionCookie cookieSettings jwtSettings v
64+
xsrf <- makeXsrfCookie cookieSettings
65+
return $ Just xsrf `SetCookieCons` (ejwt `SetCookieCons` SetCookieNil)
66+
_ -> return $ Nothing `SetCookieCons` (Nothing `SetCookieCons` SetCookieNil)
6067

61-
makeCookies :: AuthResult v -> IO (SetCookieList ('S ('S 'Z)))
62-
makeCookies authResult = do
63-
case authResult of
64-
(Authenticated v) -> do
65-
ejwt <- makeSessionCookie cookieSettings jwtSettings v
66-
xsrf <- makeXsrfCookie cookieSettings
67-
return $ Just xsrf `SetCookieCons` (ejwt `SetCookieCons` SetCookieNil)
68-
_ -> return $ Nothing `SetCookieCons` (Nothing `SetCookieCons` SetCookieNil)
68+
go
69+
:: (AuthResult v -> ServerT api Handler)
70+
-> (AuthResult v, SetCookieList n)
71+
-> ServerT (AddSetCookiesApi n api) Handler
72+
go fn (authResult, cookies) = addSetCookies cookies $ fn authResult
6973

70-
go
71-
:: (AuthResult v -> ServerT api Handler)
72-
-> (AuthResult v, SetCookieList n)
73-
-> ServerT (AddSetCookiesApi n api) Handler
74-
go fn (authResult, cookies) = addSetCookies cookies $ fn authResult
74+
#if MIN_VERSION_servant_server(0,12,0)
75+
hoistServerWithContext _ pc nt s = hoistServerWithContext (Proxy :: Proxy api) pc nt . s
76+
#endif

servant-auth/servant-auth-server/src/Servant/Auth/Server/Internal/AddSetCookie.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ instance orig1 ~ orig2 => AddSetCookies 'Z orig1 orig2 where
8080

8181
instance
8282
{-# OVERLAPPABLE #-}
83-
( Functor m
83+
( AddHeader mods "Set-Cookie" SetCookie cookied new
8484
, AddSetCookies n (m old) (m cookied)
85-
, AddHeader mods "Set-Cookie" SetCookie cookied new
85+
, Functor m
8686
)
8787
=> AddSetCookies ('S n) (m old) (m new)
8888
where
@@ -108,8 +108,8 @@ instance
108108
instance
109109
{-# OVERLAPS #-}
110110
( AddSetCookies ('S n) (ServerT (ToServantApi api) m) cookiedApi
111-
, Generic (api (AsServerT m))
112111
, GServantProduct (Rep (api (AsServerT m)))
112+
, Generic (api (AsServerT m))
113113
, ToServant api (AsServerT m) ~ ServerT (ToServantApi api) m
114114
)
115115
=> AddSetCookies ('S n) (api (AsServerT m)) cookiedApi

servant-auth/servant-auth-server/src/Servant/Auth/Server/Internal/BasicAuth.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ module Servant.Auth.Server.Internal.BasicAuth where
88

99
import qualified Data.ByteString as BS
1010
import Servant (BasicAuthData (..), ServerError (..), err401)
11-
import Servant.Auth.Server.Internal.Types
1211
import Servant.Server.Internal.BasicAuth (decodeBAHdr, mkBAChallengerHdr)
1312

13+
import Servant.Auth.Server.Internal.Types
14+
1415
-- | A 'ServerError' that asks the client to authenticate via Basic
1516
-- Authentication, should be invoked by an application whenever
1617
-- appropriate. The argument is the realm.

servant-auth/servant-auth-server/src/Servant/Auth/Server/Internal/Class.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Data.Monoid
77
import Servant hiding (BasicAuth)
88
import Servant.Auth
99
import Servant.Auth.JWT
10+
1011
import Servant.Auth.Server.Internal.BasicAuth
1112
import Servant.Auth.Server.Internal.ConfigTypes
1213
import Servant.Auth.Server.Internal.Cookie
@@ -41,10 +42,10 @@ instance AreAuths '[] ctxs v where
4142
runAuths _ _ = mempty
4243

4344
instance
44-
( AuthCheck v ~ App (AuthArgs a) (Unapp (AuthArgs a) (AuthCheck v))
45-
, IsAuth a v
45+
( AppCtx ctxs (AuthArgs a) (Unapp (AuthArgs a) (AuthCheck v))
4646
, AreAuths as ctxs v
47-
, AppCtx ctxs (AuthArgs a) (Unapp (AuthArgs a) (AuthCheck v))
47+
, AuthCheck v ~ App (AuthArgs a) (Unapp (AuthArgs a) (AuthCheck v))
48+
, IsAuth a v
4849
)
4950
=> AreAuths (a ': as) ctxs v
5051
where
@@ -70,8 +71,8 @@ class AppCtx ctx ls res where
7071
appCtx :: proxy ls -> Context ctx -> res -> App ls res
7172

7273
instance
73-
( HasContextEntry ctxs ctx
74-
, AppCtx ctxs rest res
74+
( AppCtx ctxs rest res
75+
, HasContextEntry ctxs ctx
7576
)
7677
=> AppCtx ctxs (ctx ': rest) (ctx -> res)
7778
where

servant-auth/servant-auth-server/src/Servant/Auth/Server/Internal/ConfigTypes.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ import GHC.Generics (Generic)
1313
import Servant.API (IsSecure (..))
1414

1515
data IsMatch = Matches | DoesNotMatch
16-
deriving (Eq, Show, Read, Generic, Ord)
16+
deriving (Eq, Generic, Ord, Read, Show)
1717

1818
data IsPasswordCorrect = PasswordCorrect | PasswordIncorrect
19-
deriving (Eq, Show, Read, Generic, Ord)
19+
deriving (Eq, Generic, Ord, Read, Show)
2020

2121
-- The @SameSite@ attribute of cookies determines whether cookies will be sent
2222
-- on cross-origin requests.
2323
--
2424
-- See <https://tools.ietf.org/html/draft-west-first-party-cookies-07 this document>
2525
-- for more information.
2626
data SameSite = AnySite | SameSiteStrict | SameSiteLax
27-
deriving (Eq, Show, Read, Generic, Ord)
27+
deriving (Eq, Generic, Ord, Read, Show)
2828

2929
-- | @JWTSettings@ are used to generate cookies, and to verify JWTs.
3030
data JWTSettings = JWTSettings
@@ -77,7 +77,7 @@ data CookieSettings = CookieSettings
7777
, cookieXsrfSetting :: !(Maybe XsrfCookieSettings)
7878
-- ^ The optional settings to use for XSRF protection. Default: @Just def@.
7979
}
80-
deriving (Eq, Show, Generic)
80+
deriving (Eq, Generic, Show)
8181

8282
instance Default CookieSettings where
8383
def = defaultCookieSettings
@@ -106,7 +106,7 @@ data XsrfCookieSettings = XsrfCookieSettings
106106
, xsrfExcludeGet :: !Bool
107107
-- ^ Exclude GET request method from XSRF protection.
108108
}
109-
deriving (Eq, Show, Generic)
109+
deriving (Eq, Generic, Show)
110110

111111
instance Default XsrfCookieSettings where
112112
def = defaultXsrfCookieSettings

servant-auth/servant-auth-server/src/Servant/Auth/Server/Internal/Cookie.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import Network.HTTP.Types.Header (hCookie)
1919
import Network.Wai (Request, requestHeaders, requestMethod)
2020
import Servant (AddHeader, addHeader')
2121
import Servant.Auth.JWT (FromJWT, ToJWT)
22+
import System.Entropy (getEntropy)
23+
import Web.Cookie
24+
2225
import Servant.Auth.Server.Internal.ConfigTypes
2326
import Servant.Auth.Server.Internal.JWT (makeJWT, verifyJWT)
2427
import Servant.Auth.Server.Internal.Types
25-
import System.Entropy (getEntropy)
26-
import Web.Cookie
2728

2829
cookieAuthCheck :: FromJWT usr => CookieSettings -> JWTSettings -> AuthCheck usr
2930
cookieAuthCheck ccfg jwtSettings = do
@@ -131,9 +132,9 @@ applySessionCookieSettings cookieSettings setCookie =
131132
-- provided response object with XSRF and session cookies. This should be used
132133
-- when a user successfully authenticates with credentials.
133134
acceptLogin
134-
:: ( ToJWT session
135-
, AddHeader mods "Set-Cookie" SetCookie response withOneCookie
135+
:: ( AddHeader mods "Set-Cookie" SetCookie response withOneCookie
136136
, AddHeader mods "Set-Cookie" SetCookie withOneCookie withTwoCookies
137+
, ToJWT session
137138
)
138139
=> CookieSettings
139140
-> JWTSettings

servant-auth/servant-auth-server/src/Servant/Auth/Server/Internal/JWT.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Data.Maybe (fromMaybe)
1212
import Data.Time (UTCTime)
1313
import Network.Wai (requestHeaders)
1414
import Servant.Auth.JWT (FromJWT (..), ToJWT (..))
15+
1516
import Servant.Auth.Server.Internal.ConfigTypes
1617
import Servant.Auth.Server.Internal.Types
1718

servant-auth/servant-auth-server/src/Servant/Auth/Server/Internal/ThrowAll.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ instance (ThrowAll a, ThrowAll b) => ThrowAll (a :<|> b) where
3030
throwAll e = throwAll e :<|> throwAll e
3131

3232
instance
33-
(ThrowAll (ToServant api (AsServerT m)), GenericServant api (AsServerT m))
33+
(GenericServant api (AsServerT m), ThrowAll (ToServant api (AsServerT m)))
3434
=> ThrowAll (api (AsServerT m))
3535
where
3636
throwAll = fromServant . throwAll

0 commit comments

Comments
 (0)