Skip to content

Commit 1329d44

Browse files
committed
Third pass, now with fourmolu-0.18.0.0
1 parent e1a2157 commit 1329d44

File tree

142 files changed

+805
-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

+805
-664
lines changed

.github/workflows/code-style.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
pull_request:
10+
workflow_dispatch: {}
11+
12+
jobs:
13+
formatting:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout Code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 1
20+
- name: Install Nix
21+
uses: cachix/install-nix-action@v31
22+
- name: Check code formatting
23+
run: |
24+
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.

0 commit comments

Comments
 (0)