Skip to content

Commit 8ec64a1

Browse files
authored
Fix some hlint warnings (#1056)
* Fix some hlint warnings * Apply review suggestions + tiny bonus fix
1 parent e88e25a commit 8ec64a1

Some content is hidden

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

65 files changed

+163
-186
lines changed

exes/BuildClient.hs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ main = topHandler $ do
109109
" hackage-build build [packages] [options]",
110110
" hackage-build stats",
111111
"Options:"]
112-
mapM_ putStrLn $ strs
112+
mapM_ putStrLn strs
113113
putStrLn $ usageInfo usageHeader buildFlagDescrs
114114
unless (null strs) exitFailure
115115
Init uri auxUris -> initialise opts uri auxUris
@@ -339,18 +339,18 @@ infoStats verbosity mDetailedStats pkgIdsHaveDocs = do
339339
-- NOTE: Expects the same number of columns in every row!
340340
printTable :: [[String]] -> String
341341
printTable xss = intercalate "\n"
342-
. map (intercalate " ")
342+
. map unwords
343343
. map padCols
344344
$ xss
345345
where
346346
colWidths :: [[Int]]
347-
colWidths = map (map length) $ xss
347+
colWidths = map (map length) xss
348348

349349
maxColWidths :: [Int]
350-
maxColWidths = foldr1 (\xs ys -> map (uncurry max) (zip xs ys)) colWidths
350+
maxColWidths = map maximum (transpose colWidths)
351351

352352
padCols :: [String] -> [String]
353-
padCols cols = map (uncurry padTo) (zip maxColWidths cols)
353+
padCols cols = zipWith padTo maxColWidths cols
354354

355355
padTo :: Int -> String -> String
356356
padTo len str = str ++ replicate (len - length str) ' '
@@ -401,7 +401,7 @@ getDocumentationStats verbosity opts config pkgs = do
401401
False -> return Nothing
402402
mPackages <- fmap parseJsonStats <$> requestGET' (packagesUri False curGhcVersion)
403403
mCandidates <- fmap parseJsonStats <$> requestGET' (packagesUri True curGhcVersion)
404-
liftIO $ putStrLn $ show curGhcVersion
404+
liftIO $ print curGhcVersion
405405
case (mPackages, mCandidates) of
406406
-- Download failure
407407
(Nothing, _) -> fail $ "Could not download " ++ show (packagesUri False curGhcVersion)
@@ -426,9 +426,9 @@ getDocumentationStats verbosity opts config pkgs = do
426426
hClose moutput
427427
handler <- openFile dirloc ReadWriteMode
428428
contents <- hGetContents handler
429-
let res = read contents :: [(String, String)]
430-
version' = fmap (\(_,b) -> b) $ find (\(a,_)-> a=="Project version") res
431-
return $ version'
429+
let res = read contents :: [(String, String)]
430+
version' = lookup "Project version" res
431+
return version'
432432

433433
getQry :: [PackageIdentifier] -> String
434434
getQry [] = ""
@@ -576,7 +576,7 @@ processPkg verbosity opts config docInfo = do
576576
coverageFile <- mapM (coveragePackage verbosity opts docInfo) hpcLoc
577577

578578
-- Modify test-outcome and rewrite report file.
579-
mapM (setTestStatus mRpt buildReport) testOutcome
579+
mapM_ (setTestStatus mRpt buildReport) testOutcome
580580

581581
case bo_dryRun opts of
582582
True -> return ()
@@ -610,7 +610,7 @@ processPkg verbosity opts config docInfo = do
610610
let buildReport' = fmap (unlines.setTestOutcome testOutcome) $ fmap lines buildReport
611611
rewriteRpt mRpt buildReport'
612612

613-
coveragePackage :: Verbosity -> BuildOpts -> DocInfo -> FilePath -> IO (FilePath)
613+
coveragePackage :: Verbosity -> BuildOpts -> DocInfo -> FilePath -> IO FilePath
614614
coveragePackage verbosity opts docInfo loc = do
615615
let pkgid = docInfoPackage docInfo
616616
dir = takeDirectory loc
@@ -886,7 +886,7 @@ putBuildFiles config docInfo reportFile buildLogFile coverageFile installOk = do
886886
(_, response) <- request Request {
887887
rqURI = uri,
888888
rqMethod = PUT,
889-
rqHeaders = [Header HdrContentType ("application/json"),
889+
rqHeaders = [Header HdrContentType "application/json",
890890
Header HdrContentLength (show (BS.length body))],
891891
rqBody = body
892892
}

exes/ImportClient.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ main = topHandler $ do
119119
printHelp help = getProgName >>= putStr . help
120120
printOptionsList = putStr . unlines
121121
printErrors errs = do
122-
putStr (concat (intersperse "\n" errs))
122+
putStr (intercalate "\n" errs)
123123
exitWith (ExitFailure 1)
124124
printVersion = putStrLn $ "hackage-import " ++ display Paths.version
125125

@@ -408,7 +408,7 @@ importIndex jobs indexFile baseURI = do
408408
=<< LBS.readFile indexFile
409409

410410
pkgs' <- evaluate (sortBy (comparing fst) pkgs)
411-
info $ "Uploading..."
411+
info "Uploading..."
412412

413413
concForM_ jobs pkgs' $ \tasks ->
414414
httpSession $ do
@@ -802,7 +802,7 @@ downloadCountCommand =
802802
where
803803
name = "downloads"
804804
shortDesc = "Import download counts"
805-
longDesc = Just $ \_ -> unlines $ [
805+
longDesc = Just $ \_ -> unlines [
806806
"Replace the on-disk download statistics with the download statistics"
807807
, "extracted from Apache log files (in .gz format)"
808808
]

exes/Main.hs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
{-# LANGUAGE PatternGuards #-}
2-
31
module Main where
42

53
import qualified Distribution.Server as Server
@@ -44,8 +42,8 @@ import Data.Maybe
4442
( isNothing )
4543
import Data.List
4644
( intercalate, isInfixOf )
47-
import Data.Traversable
48-
( forM )
45+
import Data.Foldable
46+
( forM_ )
4947
import Data.Version
5048
( showVersion )
5149
import Control.Monad
@@ -377,7 +375,7 @@ runAction opts = do
377375
fail $ "Sorry, the server assumes it will be served (or proxied) "
378376
++ " via http or https, so cannot use uri scheme " ++ uriScheme uri
379377
| isNothing (uriAuthority uri) ->
380-
fail $ "The base-uri has to include the full host name"
378+
fail "The base-uri has to include the full host name"
381379
| uriPath uri `notElem` ["", "/"] ->
382380
fail $ "Sorry, the server assumes the base-uri to be at the root of "
383381
++ " the domain, so cannot use " ++ uriPath uri
@@ -689,7 +687,7 @@ testBackupCommand =
689687
flagTestBackupScrubbed (\v flags -> flags { flagTestBackupScrubbed = v })
690688
(noArg (Flag True))
691689
, option [] ["features"]
692-
("Only test the specified features")
690+
"Only test the specified features"
693691
flagTestBackupFeatures (\v flags -> flags { flagTestBackupFeatures = v })
694692
(reqArgFlag "FEATURES")
695693
]
@@ -920,7 +918,7 @@ withServer config doTemp = bracket initialise shutdown
920918
loginfo verbosity "Initializing happstack-state..."
921919
server <- Server.initialise config
922920
loginfo verbosity "Server data loaded into memory"
923-
void $ forM mtemp $ \temp -> do
921+
forM_ mtemp $ \temp -> do
924922
loginfo verbosity "Tearing down temp server"
925923
Server.tearDownTemp temp
926924
return server

exes/MirrorClient.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ mirrorOnce verbosity opts
126126
ignoreCount = length pkgsToMirror - mirrorCount
127127

128128
if mirrorCount == 0
129-
then liftIO $ notice verbosity $ "No packages to mirror"
129+
then liftIO $ notice verbosity "No packages to mirror"
130130
else do
131131
liftIO $ notice verbosity $
132132
show mirrorCount ++ " packages to mirror."

src/Distribution/Client.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ data PkgIndexInfo = PkgIndexInfo
100100
downloadIndex :: URI -> FilePath -> HttpSession [PkgIndexInfo]
101101
downloadIndex uri | isOldHackageURI uri = downloadOldIndex uri
102102
| otherwise = downloadNewIndex uri
103-
where
103+
104104

105105
isOldHackageURI :: URI -> Bool
106106
isOldHackageURI uri

src/Distribution/Client/Mirror/Repo/Secure.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ finalizeLocalMirror' cache repoRoot = (`runContT` return) $ do
187187
let (dir, template) = splitFileName dst
188188
bracket (openBinaryTempFileWithDefaultPermissions dir template)
189189
(\(temp, h) -> ignoreIOErrors (hClose h >> removeFile temp)) $
190-
(\(temp, h) -> do
190+
\(temp, h) -> do
191191
BS.L.hPut h =<< BS.L.readFile src
192192
hClose h
193193
a <- callback ()
194194
renameFile temp dst
195-
return a)
195+
return a
196196

197197
ignoreIOErrors :: IO () -> IO ()
198198
ignoreIOErrors = handle $ \(_ :: IOException) -> return ()

src/Distribution/Client/Mirror/State.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Distribution.Client.Mirror.State (
1111
-- stdlib
1212
import Control.Exception
1313
import Control.Monad
14-
import Data.Maybe (catMaybes)
14+
import Data.Maybe (mapMaybe)
1515
import Data.Set (Set)
1616
import Network.URI
1717
import System.Directory
@@ -115,7 +115,7 @@ readPkgProblemFile file = do
115115
exists <- doesFileExist file
116116
if exists
117117
then evaluate . Set.fromList
118-
. catMaybes . map simpleParse . lines
118+
. mapMaybe simpleParse . lines
119119
=<< readFile file
120120
else return Set.empty
121121

src/Distribution/Server.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE NamedFieldPuns, RecordWildCards #-}
1+
{-# LANGUAGE NamedFieldPuns #-}
22
module Distribution.Server (
33
-- * Server control
44
Server(..),
@@ -287,7 +287,7 @@ initState server (admin, pass) = do
287287
Nothing -> fail "Couldn't parse admin name (should be alphanumeric)"
288288
case muid of
289289
Right uid -> Group.addUserToGroup adminGroup uid
290-
Left Users.ErrUserNameClash -> fail $ "Inconceivable!! failed to create admin user"
290+
Left Users.ErrUserNameClash -> fail "Inconceivable!! failed to create admin user"
291291

292292
-- The top-level server part.
293293
-- It collects resources from Distribution.Server.Features, collects
@@ -341,7 +341,7 @@ setUpTemp sconf secs = do
341341
-- cost to it
342342
threadDelay $ secs*1000000
343343
-- could likewise specify a mirror to redirect to for tarballs, and 503 for everything else
344-
runServer listenOn $ (resp 503 $ setHeader "Content-Type" "text/html" $ toResponse html503)
344+
runServer listenOn $ resp 503 $ setHeader "Content-Type" "text/html" $ toResponse html503
345345
return (TempServer tid)
346346
where listenOn = confListenOn sconf
347347

@@ -362,4 +362,4 @@ tearDownTemp :: TempServer -> IO ()
362362
tearDownTemp (TempServer tid) = do
363363
killThread tid
364364
-- give the server enough time to release the bind
365-
threadDelay $ 1000000
365+
threadDelay 1000000

src/Distribution/Server/Features/AdminLog.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Distribution.Server.Features.Users
1414

1515
import Data.SafeCopy (base, deriveSafeCopy)
1616
import Data.Typeable
17-
import Data.Maybe(catMaybes)
17+
import Data.Maybe(mapMaybe)
1818
import Control.Monad.Reader
1919
import qualified Control.Monad.State as State
2020
import Data.Time (UTCTime)
@@ -161,7 +161,7 @@ restoreAdminLogBackup =
161161

162162
importLogs :: AdminLog -> BS.ByteString -> AdminLog
163163
importLogs (AdminLog ls) =
164-
AdminLog . (++ls) . catMaybes . map fromRecord . lines . unpackUTF8
164+
AdminLog . (++ls) . mapMaybe fromRecord . lines . unpackUTF8
165165
where
166166
fromRecord :: String -> Maybe (UTCTime,UserId,AdminAction,BS.ByteString)
167167
fromRecord = readMaybe

src/Distribution/Server/Features/Browse.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{-# LANGUAGE BlockArguments, NamedFieldPuns, TupleSections #-}
1+
{-# LANGUAGE BlockArguments, NamedFieldPuns #-}
22
module Distribution.Server.Features.Browse (initBrowseFeature, PaginationConfig(..), StartIndex(..), NumElems(..), paginate) where
33

44
import Control.Arrow (left)

src/Distribution/Server/Features/Browse/ApplyFilter.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ applyFilter now isSearch coreResource userResource tagsResource DistroFeature{qu
2828
packages <- filterM filterForItem items
2929
pure $
3030
map packageIndexInfoToValue $
31-
sort isSearch (boSort browseOptions) $
32-
packages
31+
sort isSearch (boSort browseOptions) packages
3332
where
3433
packageIndexInfoToValue :: PackageItem -> Value
3534
packageIndexInfoToValue PackageItem{..} =
@@ -85,7 +84,7 @@ applyFilter now isSearch coreResource userResource tagsResource DistroFeature{qu
8584

8685
filterForItem :: PackageItem -> IO Bool
8786
filterForItem item =
88-
all id <$> traverse (includeItem item) filtersWithDefaults
87+
and <$> traverse (includeItem item) filtersWithDefaults
8988

9089
sort :: IsSearch -> Sort -> [PackageItem] -> [PackageItem]
9190
sort isSearch Sort {sortColumn, sortDirection} =

src/Distribution/Server/Features/BuildReports/State.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE DeriveDataTypeable, TypeFamilies, TemplateHaskell,
22
FlexibleInstances, FlexibleContexts, MultiParamTypeClasses,
3-
TypeOperators, TypeSynonymInstances #-}
3+
TypeOperators #-}
44
{-# OPTIONS_GHC -fno-warn-orphans #-}
55
module Distribution.Server.Features.BuildReports.State where
66

@@ -67,7 +67,7 @@ setFailStatus pkgid status = do
6767
let reports = BuildReports.setFailStatus pkgid status buildReports
6868
State.put reports
6969

70-
resetFailCount :: PackageId -> Update BuildReports (Bool)
70+
resetFailCount :: PackageId -> Update BuildReports Bool
7171
resetFailCount pkgid = do
7272
buildReports <- State.get
7373
case BuildReports.resetFailCount pkgid buildReports of

src/Distribution/Server/Features/Core.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ coreFeature ServerEnv{serverBlobStore = store} UserFeature{..}
502502
-- Queries
503503
--
504504
queryGetPackageIndex :: MonadIO m => m (PackageIndex PkgInfo)
505-
queryGetPackageIndex = return . packageIndex =<< queryState packagesState GetPackagesState
505+
queryGetPackageIndex = packageIndex <$> queryState packagesState GetPackagesState
506506

507507
queryGetIndexTarballInfo :: MonadIO m => m IndexTarballInfo
508508
queryGetIndexTarballInfo = readAsyncCache cacheIndexTarball
@@ -753,11 +753,11 @@ coreFeature ServerEnv{serverBlobStore = store} UserFeature{..}
753753
deauth _ = do
754754
return $ (toResponse ("<script>window.location='/'</script>"::String)) {
755755
rsCode = 401
756-
, rsHeaders = mkHeaders ([("Content-Type", "text/html")])
756+
, rsHeaders = mkHeaders [("Content-Type", "text/html")]
757757
}
758758

759759
packageExists, packageIdExists :: (Package pkg, Package pkg') => PackageIndex pkg -> pkg' -> Bool
760760
-- | Whether a package exists in the given package index.
761761
packageExists pkgs pkg = not . null $ PackageIndex.lookupPackageName pkgs (packageName pkg)
762762
-- | Whether a particular package version exists in the given package index.
763-
packageIdExists pkgs pkg = maybe False (const True) $ PackageIndex.lookupPackageId pkgs (packageId pkg)
763+
packageIdExists pkgs pkg = isJust $ PackageIndex.lookupPackageId pkgs (packageId pkg)

src/Distribution/Server/Features/Core/Backup.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ forceLast :: BS.ByteString -> BS.ByteString
292292
forceLast = BS.fromChunks . forceLastBlock . BS.toChunks
293293
where
294294
forceLastBlock [] = []
295-
forceLastBlock (c:[]) = c : []
295+
forceLastBlock [c] = [c]
296296
forceLastBlock (c:cs) = c : forceLastBlock cs
297297

298298
--------------------------------------------------------------------------------

src/Distribution/Server/Features/Distro.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ distroFeature UserFeature{..}
115115

116116
textEnumDistros _ = fmap (toResponse . intercalate ", " . map display) (queryState distrosState EnumerateDistros)
117117
textDistroPkgs dpath = withDistroPath dpath $ \dname pkgs -> do
118-
let pkglines = map (\(name, info) -> display name ++ " at " ++ display (distroVersion info) ++ ": " ++ distroUrl info) $ pkgs
118+
let pkglines = map (\(name, info) -> display name ++ " at " ++ display (distroVersion info) ++ ": " ++ distroUrl info) pkgs
119119
return $ toResponse (unlines $ ("Packages for " ++ display dname):pkglines)
120120
csvDistroPackageList dpath = withDistroPath dpath $ \_dname pkgs -> do
121-
return $ toResponse $ packageListToCSV $ pkgs
121+
return $ toResponse $ packageListToCSV pkgs
122122
textDistroPkg dpath = withDistroPackagePath dpath $ \_ _ info -> return . toResponse $ show info
123123

124124
-- result: see-other uri, or an error: not authenticated or not found (todo)
@@ -127,7 +127,7 @@ distroFeature UserFeature{..}
127127
guardAuthorised_ [InGroup adminGroup] --TODO: use the per-distro maintainer groups
128128
-- should also check for existence here of distro here
129129
void $ updateState distrosState $ RemoveDistro distro
130-
seeOther ("/distros/") (toResponse ())
130+
seeOther "/distros/" (toResponse ())
131131

132132
-- result: ok response or not-found error
133133
distroPackageDelete dpath =

src/Distribution/Server/Features/Documentation.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Distribution.Server.Features.Users
1414
import Distribution.Server.Features.Core
1515
import Distribution.Server.Features.TarIndexCache
1616
import Distribution.Server.Features.BuildReports
17-
import Distribution.Version ( Version )
17+
import Distribution.Version (Version, nullVersion)
1818

1919
import Distribution.Server.Framework.BackupRestore
2020
import qualified Distribution.Server.Framework.ResponseContentTypes as Resource
@@ -29,7 +29,6 @@ import qualified Codec.Archive.Tar.Check as Tar
2929

3030
import Distribution.Text
3131
import Distribution.Package
32-
import Distribution.Version (nullVersion)
3332
import qualified Distribution.Parsec as P
3433

3534
import qualified Data.ByteString.Char8 as C
@@ -113,7 +112,7 @@ documentationStateComponent name stateDir = do
113112
}
114113
where
115114
dumpBackup doc =
116-
let exportFunc (pkgid, blob) = BackupBlob ([display pkgid, "documentation.tar"]) blob
115+
let exportFunc (pkgid, blob) = BackupBlob [display pkgid, "documentation.tar"] blob
117116
in map exportFunc . Map.toList $ documentation doc
118117

119118
updateDocumentation :: Documentation -> RestoreBackup Documentation
@@ -227,7 +226,7 @@ documentationFeature name
227226
parseVersion' (Just k) = P.simpleParsec k
228227

229228
parsePkgs :: String -> [PackageIdentifier]
230-
parsePkgs pkgsStr = map fromJust $ filter isJust $ map (P.simpleParsec . C.unpack) $ C.split ',' (C.pack pkgsStr)
229+
parsePkgs pkgsStr = mapMaybe (P.simpleParsec . C.unpack) (C.split ',' (C.pack pkgsStr))
231230

232231
isSelectedPackage pkgid pkgid'@(PackageIdentifier _ v)
233232
| nullVersion == v =

0 commit comments

Comments
 (0)