Skip to content

Commit 18b2ef4

Browse files
authored
Address hlint warnings/suggestions (#1826)
* Switch to fourmolu formatter and reformat all sources Some FOURMOLU_DISABLE directives were added in problematic cases (mostly CPP conditional pragmas or foreign imports). * Second pass to reduce amount of multi-line import lists * Third pass, now with fourmolu-0.18.0.0 * Address hlint warnings * Make it compile and pass tests Address some hlints that required manual attention. * Add hlint CI check * Address review concern * Drop conditional GHC-version sections * Partially apply refactors * Manually refactor return -> pure where automatic refactor failed * Replace return with pure in literal haskell files * How did this happen?
1 parent 6ea567a commit 18b2ef4

File tree

108 files changed

+781
-837
lines changed

Some content is hidden

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

108 files changed

+781
-837
lines changed

.github/workflows/code-style.yaml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Code style check
1+
name: Code style checks
22

33
concurrency:
44
group: formatting-${{ github.ref_name }}
@@ -20,4 +20,17 @@ jobs:
2020
uses: cachix/install-nix-action@v31
2121
- name: Check code formatting
2222
run: |
23-
nix develop '#haskellFormatter' --command fourmolu --mode=check --check-idempotence servant servant-*
23+
nix develop '#haskellFormatter' --command fourmolu --mode=check --check-idempotence servant servant-*
24+
25+
lint:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout Code
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 1
32+
- name: Install Nix
33+
uses: cachix/install-nix-action@v31
34+
- name: Run hlint check
35+
run: |
36+
nix develop '#haskellLinter' --command hlint servant servant-*

hlint.yaml renamed to .hlint.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,12 @@
4545
#
4646
# Generalise map to fmap, ++ to <>
4747
# - group: {name: generalise, enabled: true}
48+
#
49+
# Replace return with pure
50+
- group: {name: future, enabled: true}
4851

4952

5053
# Ignore some builtin hints
51-
- ignore: {name: Redundant do}
52-
- ignore: {name: Parse error}
53-
- ignore: {name: Use fmap}
54-
- ignore: {name: Use list comprehension}
55-
- ignore: {name: Use lambda-case}
56-
- ignore: {name: Eta reduce}
5754
# - ignore: {name: Use const, within: SpecialModule} # Only within certain modules
5855

5956

doc/cookbook/basic-auth/BasicAuth.lhs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ api :: Proxy API
7171
api = Proxy
7272

7373
server :: Server API
74-
server usr = return (site usr)
74+
server usr = pure (site usr)
7575
```
7676
7777
In order to protect our endpoint (`"mysite" :> Get '[JSON] Website`), we simply
@@ -105,10 +105,10 @@ checkBasicAuth db = BasicAuthCheck $ \basicAuthData ->
105105
password = decodeUtf8 (basicAuthPassword basicAuthData)
106106
in
107107
case Map.lookup username db of
108-
Nothing -> return NoSuchUser
108+
Nothing -> pure NoSuchUser
109109
Just u -> if pass u == password
110-
then return (Authorized u)
111-
else return BadPassword
110+
then pure (Authorized u)
111+
else pure BadPassword
112112
```
113113
114114
This check simply looks up the user in the "database" and makes sure the

doc/cookbook/basic-streaming/Streaming.lhs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ In other words, without streaming libraries.
88
- Some basic usage doesn't require usage of streaming libraries,
99
like `conduit`, `pipes`, `machines` or `streaming`.
1010
We have bindings for them though.
11-
- Similar example is bundled with each of our streaming library interop packages (see
11+
- Similar example is bundled with each of our streaming library interop packages (see
1212
[servant-pipes](https://github.com/haskell-servant/servant/blob/master/servant-pipes/example/Main.hs),
1313
[servant-conduit](https://github.com/haskell-servant/servant/blob/master/servant-conduit/example/Main.hs) and
1414
[servant-machines](https://github.com/haskell-servant/servant/blob/master/servant-machines/example/Main.hs))
1515
- `SourceT` doesn't have *Prelude* with handy combinators, so we have to write
16-
things ourselves. (Note to self: `mapM` and `foldM` would be handy to have).
16+
things ourselves. (Note to self: `mapM` and `foldM` would be handy to have).
1717

1818
## Code
1919

@@ -64,19 +64,19 @@ server :: Server API
6464
server = fast :<|> slow :<|> readme :<|> proxy where
6565
fast n = liftIO $ do
6666
putStrLn $ "/get/" ++ show n
67-
return $ fastSource n
67+
pure $ fastSource n
6868
6969
slow n = liftIO $ do
7070
putStrLn $ "/slow/" ++ show n
71-
return $ slowSource n
71+
pure $ slowSource n
7272

7373
readme = liftIO $ do
7474
putStrLn "/proxy"
75-
return (S.readFile "README.md")
75+
pure (S.readFile "README.md")
7676
7777
proxy c = liftIO $ do
7878
putStrLn "/proxy"
79-
return c
79+
pure c
8080

8181
-- for some reason unfold leaks?
8282
fastSource = S.fromStepT . mk where
@@ -116,8 +116,8 @@ main = do
116116
x <- S.unSourceT src (go (0 :: Int))
117117
print x
118118
where
119-
go !acc S.Stop = return acc
120-
go !acc (S.Error err) = print err >> return acc
119+
go !acc S.Stop = pure acc
120+
go !acc (S.Error err) = print err >> pure acc
121121
go !acc (S.Skip s) = go acc s
122122
go !acc (S.Effect ms) = ms >>= go acc
123123
go !acc (S.Yield _ s) = go (acc + 1) s

doc/cookbook/curl-mock/CurlMock.lhs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ generateEndpoint :: Text -> Req Mocked -> IO Text
141141
generateEndpoint host req =
142142
case maybeBody of
143143
Just body ->
144-
body >>= \b -> return $ T.intercalate " " [ "curl", "-X", method, "-d", "'" <> b <> "'"
144+
body >>= \b -> pure $ T.intercalate " " [ "curl", "-X", method, "-d", "'" <> b <> "'"
145145
, "-H 'Content-Type: application/json'", host <> "/" <> url ]
146146
Nothing ->
147-
return $ T.intercalate " " [ "curl", "-X", method, host <> "/" <> url ]
147+
pure $ T.intercalate " " [ "curl", "-X", method, host <> "/" <> url ]
148148
where
149149
method = decodeUtf8 $ req ^. reqMethod
150150

doc/cookbook/custom-errors/CustomErrors.lhs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ server :: Server TestApi
6767
server = helloH :<|> postGreetH :<|> deleteGreetH
6868

6969
where helloH name Nothing = helloH name (Just False)
70-
helloH name (Just False) = return . Greet $ "Hello, " <> name
71-
helloH name (Just True) = return . Greet . Text.toUpper $ "Hello, " <> name
70+
helloH name (Just False) = pure . Greet $ "Hello, " <> name
71+
helloH name (Just True) = pure . Greet . Text.toUpper $ "Hello, " <> name
7272

73-
postGreetH greet = return greet
73+
postGreetH greet = pure greet
7474

75-
deleteGreetH _ = return NoContent
75+
deleteGreetH _ = pure NoContent
7676
```
7777
7878
## Error formatters

doc/cookbook/db-mysql-basics/MysqlBasics.lhs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ doMigration :: IO ()
141141
doMigration = runNoLoggingT $ runResourceT $ withMySQLConn connInfo $ runReaderT $ runMigration migrateAll
142142

143143
server :: Server Api
144-
server =
145-
personGET :<|>
146-
personGETById :<|>
144+
server =
145+
personGET :<|>
146+
personGETById :<|>
147147
personDELETE :<|>
148148
personPOST
149149
where
@@ -155,20 +155,20 @@ server =
155155
selectPersons :: Handler [Person]
156156
selectPersons = do
157157
personList <- runDB $ selectList [] []
158-
return $ map (\(Entity _ u) -> u) personList
158+
pure $ map (\(Entity _ u) -> u) personList
159159
160160
selectPersonById :: Int -> Handler Person
161161
selectPersonById id = do
162162
sqlResult <- runDB $ get $ PersonKey id
163163
case sqlResult of
164-
Just person -> return person
164+
Just person -> pure person
165165
Nothing -> throwError err404 { errBody = JSON.encode "Person with ID not found." }
166166
167167
createPerson :: Person -> Handler Person
168168
createPerson person = do
169169
attemptCreate <- runDB $ insert person
170170
case attemptCreate of
171-
PersonKey k -> return person
171+
PersonKey k -> pure person
172172
_ -> throwError err503 { errBody = JSON.encode "Could not create Person." }
173173
174174
deletePerson :: Int -> Handler ()

doc/cookbook/db-postgres-pool/PostgresPool.lhs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ initDB :: DBConnectionString -> IO ()
5151
initDB connstr = bracket (connectPostgreSQL connstr) close $ \conn -> do
5252
execute_ conn
5353
"CREATE TABLE IF NOT EXISTS messages (msg text not null)"
54-
return ()
54+
pure ()
5555
```
5656
5757
Next, our server implementation. It will be parametrised (take as
@@ -76,7 +76,7 @@ server conns = postMessage :<|> getMessages
7676
execute conn
7777
"INSERT INTO messages VALUES (?)"
7878
(Only msg)
79-
return NoContent
79+
pure NoContent
8080
8181
getMessages :: Handler [Message]
8282
getMessages = fmap (map fromOnly) . liftIO $

doc/cookbook/db-sqlite-simple/DBConnection.lhs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ server dbfile = postMessage :<|> getMessages
5959
execute conn
6060
"INSERT INTO messages VALUES (?)"
6161
(Only msg)
62-
return NoContent
62+
pure NoContent
6363
6464
getMessages :: Handler [Message]
6565
getMessages = fmap (map fromOnly) . liftIO $

doc/cookbook/file-upload/FileUpload.lhs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ upload multipartData = do
8282
let content = fdPayload file
8383
putStrLn $ "Content of " ++ show (fdFileName file)
8484
LBS.putStr content
85-
return 0
85+
pure 0
8686
8787
startServer :: IO ()
8888
startServer = run 8080 (serve api upload)

0 commit comments

Comments
 (0)