Skip to content

Commit a405aed

Browse files
committed
Follow hlint suggestion: use void
- Redo counts - Minimize diffs - Inline monitorReason' = void monitorReason - One more application of void - Use $ and not parentheses - Use -XLambdaCase for instantiate unitId work
1 parent 28fe856 commit a405aed

12 files changed

Lines changed: 38 additions & 45 deletions

File tree

.hlint.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
11
# Warnings currently triggered by your code
22
- ignore: {name: "Avoid NonEmpty.unzip"} # 1 hint
3-
- ignore: {name: "Avoid lambda"} # 49 hints
4-
- ignore: {name: "Eta reduce"} # 139 hints
3+
- ignore: {name: "Avoid lambda"} # 54 hints
4+
- ignore: {name: "Eta reduce"} # 136 hints
55
- ignore: {name: "Hoist not"} # 16 hints
66
- ignore: {name: "Move filter"} # 4 hints
7-
- ignore: {name: "Redundant $!"} # 1 hint
8-
- ignore: {name: "Redundant bracket"} # 273 hints
7+
- ignore: {name: "Redundant $!"} # 3 hints
8+
- ignore: {name: "Redundant bracket"} # 253 hints
99
- ignore: {name: "Redundant guard"} # 1 hint
1010
- ignore: {name: "Redundant if"} # 6 hints
1111
- ignore: {name: "Redundant lambda"} # 16 hints
1212
- ignore: {name: "Redundant multi-way if"} # 1 hint
13-
- ignore: {name: "Redundant return"} # 9 hints
13+
- ignore: {name: "Redundant return"} # 7 hints
1414
- ignore: {name: "Use $>"} # 5 hints
1515
- ignore: {name: "Use ++"} # 4 hints
16-
- ignore: {name: "Use :"} # 29 hints
16+
- ignore: {name: "Use :"} # 30 hints
1717
- ignore: {name: "Use <$"} # 2 hints
18-
- ignore: {name: "Use <$>"} # 82 hints
18+
- ignore: {name: "Use <$>"} # 83 hints
1919
- ignore: {name: "Use <&>"} # 16 hints
2020
- ignore: {name: "Use <=<"} # 4 hints
2121
- ignore: {name: "Use =<<"} # 7 hints
2222
- ignore: {name: "Use >=>"} # 3 hints
2323
- ignore: {name: "Use Down"} # 3 hints
2424
- ignore: {name: "Use bimap"} # 7 hints
25-
- ignore: {name: "Use camelCase"} # 97 hints
25+
- ignore: {name: "Use camelCase"} # 96 hints
2626
- ignore: {name: "Use const"} # 36 hints
2727
- ignore: {name: "Use fst"} # 2 hints
28-
- ignore: {name: "Use newtype instead of data"} # 31 hints
28+
- ignore: {name: "Use newtype instead of data"} # 32 hints
2929
- ignore: {name: "Use null"} # 2 hints
30-
- ignore: {name: "Use record patterns"} # 16 hints
31-
- ignore: {name: "Use void"} # 23 hints
30+
- ignore: {name: "Use record patterns"} # 15 hints
3231

3332
- ignore: {name: "Functor law", within: [Test.Laws]}
3433
- ignore: {name: "Monoid law, left identity", within: [Test.Laws, UnitTests.Distribution.Utils.NubList]}

Cabal-syntax/src/Distribution/Compat/Parsing.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ option x p = p <|> pure x
8282
-- It only fails if @p@ fails after consuming input. It discards the result
8383
-- of @p@. (Plays the role of parsec's optional, which conflicts with Applicative's optional)
8484
skipOptional :: Alternative m => m a -> m ()
85-
skipOptional p = (() <$ p) <|> pure ()
85+
skipOptional p = void p <|> pure ()
8686
{-# INLINE skipOptional #-}
8787

8888
-- | @between open close p@ parses @open@, followed by @p@ and @close@.
@@ -224,7 +224,7 @@ class Alternative m => Parsing m where
224224
-- | A version of many that discards its input. Specialized because it
225225
-- can often be implemented more cheaply.
226226
skipMany :: m a -> m ()
227-
skipMany p = () <$ many p
227+
skipMany p = void $ many p
228228
{-# INLINE skipMany #-}
229229

230230
-- | @skipSome p@ applies the parser @p@ /one/ or more times, skipping

Cabal/src/Distribution/Backpack/ReadyComponent.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,9 @@ toReadyComponents pid_map subst0 comps =
403403
-- Top-level instantiation per subst0
404404
| not (Map.null subst0)
405405
, [lc] <- filter lc_public (Map.elems cmap) =
406-
do
407-
_ <- instantiateUnitId (lc_cid lc) subst0
408-
return ()
406+
void $ instantiateUnitId (lc_cid lc) subst0
409407
| otherwise =
410408
forM_ (Map.elems cmap) $ \lc ->
411409
if null (lc_insts lc)
412-
then instantiateUnitId (lc_cid lc) Map.empty >> return ()
413-
else indefiniteUnitId (lc_cid lc) >> return ()
410+
then void $ instantiateUnitId (lc_cid lc) Map.empty
411+
else void $ indefiniteUnitId (lc_cid lc)

Cabal/src/Distribution/Simple/Glob/Internal.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ instance Parsec Glob where
7979
where
8080
dirSep :: CabalParsing m => m ()
8181
dirSep =
82-
() <$ P.char '/'
82+
void (P.char '/')
8383
<|> P.try
8484
( do
8585
_ <- P.char '\\'

cabal-install/src/Distribution/Client/ProjectBuilding/PackageFileMonitor.hs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ checkPackageFileMonitorChanged
151151
pkgconfig
152152
case configChanged of
153153
MonitorChanged monitorReason ->
154-
return (Left (BuildStatusConfigure monitorReason'))
155-
where
156-
monitorReason' = fmap (const ()) monitorReason
154+
return (Left (BuildStatusConfigure $ void monitorReason))
157155
MonitorUnchanged () _
158156
-- The configChanged here includes the identity of the dependencies,
159157
-- so depsBuildStatus is just needed for the changes in the content
@@ -182,16 +180,14 @@ checkPackageFileMonitorChanged
182180
(MonitorChanged monitorReason, _) ->
183181
return (Left (BuildStatusBuild mreg buildReason))
184182
where
185-
buildReason = BuildReasonFilesChanged monitorReason'
186-
monitorReason' = fmap (const ()) monitorReason
183+
buildReason = BuildReasonFilesChanged $ void monitorReason
187184
(MonitorUnchanged _ _, MonitorChanged monitorReason) ->
188185
-- this should only happen if the file is corrupt or been
189186
-- manually deleted. We don't want to bother with another
190187
-- phase just for this, so we'll reregister by doing a build.
191188
return (Left (BuildStatusBuild Nothing buildReason))
192189
where
193-
buildReason = BuildReasonFilesChanged monitorReason'
194-
monitorReason' = fmap (const ()) monitorReason
190+
buildReason = BuildReasonFilesChanged $ void monitorReason
195191
(MonitorUnchanged _ _, MonitorUnchanged _ _)
196192
| pkgHasEphemeralBuildTargets pkg ->
197193
return (Left (BuildStatusBuild mreg buildReason))

cabal-install/src/Distribution/Client/ProjectConfig/Legacy.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,8 +1329,8 @@ parsePackageLocationTokenQ =
13291329
where
13301330
outerTerm = alternateEither1 outerToken (braces innerTerm)
13311331
innerTerm = alternateEither innerToken (braces innerTerm)
1332-
outerToken = Parse.munch1 outerChar >> return ()
1333-
innerToken = Parse.munch1 innerChar >> return ()
1332+
outerToken = void $ Parse.munch1 outerChar
1333+
innerToken = void $ Parse.munch1 innerChar
13341334
outerChar c = not (isSpace c || c == '{' || c == '}' || c == ',')
13351335
innerChar c = not (isSpace c || c == '{' || c == '}')
13361336
braces = Parse.between (Parse.char '{') (Parse.char '}')

cabal-install/src/Distribution/Client/ProjectOrchestration.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ selectBuildableTargetsWith' p =
10181018
(fmap . map) forgetTargetDetail . unzip . zipBuildableTargetsWith p
10191019

10201020
forgetTargetDetail :: AvailableTarget k -> AvailableTarget ()
1021-
forgetTargetDetail = fmap (const ())
1021+
forgetTargetDetail = void
10221022

10231023
forgetTargetsDetail :: [AvailableTarget k] -> [AvailableTarget ()]
10241024
forgetTargetsDetail = map forgetTargetDetail

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,15 +3048,11 @@ instantiateInstallPlan storeDirLayout defaultInstallDirs elaboratedShared plan =
30483048

30493049
ready_map = execState work Map.empty
30503050

3051-
work = for_ pkgs $ \pkg ->
3052-
case pkg of
3053-
InstallPlan.Configured elab
3054-
| not (Map.null (elabLinkedInstantiatedWith elab)) ->
3055-
indefiniteUnitId (elabComponentId elab)
3056-
>> return ()
3057-
_ ->
3058-
instantiateUnitId (getComponentId pkg) Map.empty
3059-
>> return ()
3051+
work = for_ pkgs $ \case
3052+
InstallPlan.Configured elab
3053+
| not (Map.null (elabLinkedInstantiatedWith elab)) ->
3054+
void $ indefiniteUnitId (elabComponentId elab)
3055+
pkg -> void $ instantiateUnitId (getComponentId pkg) Map.empty
30603056

30613057
---------------------------
30623058
-- Build targets

cabal-testsuite/PackageTests/ExternalCommand/cabal.test.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import qualified System.Process as Process
33
import Control.Concurrent (threadDelay)
44
import System.Directory (removeFile)
55
import Control.Exception (catch, throwIO)
6+
import Control.Monad (void)
67
import System.IO.Error (isDoesNotExistError)
78
import qualified Data.Time.Clock as Time
89
import qualified Data.Time.Format as Time
@@ -16,18 +17,18 @@ main = do
1617
exe_path <- withPlan $ planExePath "setup-test" "cabal-aaaa"
1718
addToPath (takeDirectory exe_path) $ do
1819
-- Test that the thing works at all
19-
res <- cabal_raw_action ["aaaa"] (\h -> () <$ Process.waitForProcess h)
20+
res <- cabal_raw_action ["aaaa"] (\h -> void (Process.waitForProcess h))
2021

2122
-- Test that the extra arguments are passed on
22-
res <- cabal_raw_action ["aaaa", "--foobaz"] (\h -> () <$ Process.waitForProcess h)
23+
res <- cabal_raw_action ["aaaa", "--foobaz"] (\h -> void (Process.waitForProcess h))
2324
assertOutputContains "--foobaz" res
2425

2526
-- Test what happens with "global" flags
26-
res <- cabal_raw_action ["aaaa", "--version"] (\h -> () <$ Process.waitForProcess h)
27+
res <- cabal_raw_action ["aaaa", "--version"] (\h -> void (Process.waitForProcess h))
2728
assertOutputContains "--version" res
2829

2930
-- Test what happens with "global" flags
30-
res <- cabal_raw_action ["aaaa", "--config-file", "abc"] (\h -> () <$ Process.waitForProcess h)
31+
res <- cabal_raw_action ["aaaa", "--config-file", "abc"] (\h -> void (Process.waitForProcess h))
3132
assertOutputContains "--config-file" res
3233

3334

cabal-testsuite/PackageTests/ExternalCommandEnv/cabal.test.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import qualified System.Process as Process
33
import Control.Concurrent (threadDelay)
44
import System.Directory (removeFile)
55
import Control.Exception (catch, throwIO)
6+
import Control.Monad (void)
67
import System.IO.Error (isDoesNotExistError)
78
import qualified Data.Time.Clock as Time
89
import qualified Data.Time.Format as Time
@@ -16,7 +17,7 @@ main =
1617
env <- getTestEnv
1718
let new_env = (("OTHER_VAR", Just "is set") : (testEnvironment env))
1819
withEnv new_env $ addToPath (takeDirectory exe_path) $ do
19-
res <- cabal_raw_action ["aaaa"] (\h -> () <$ Process.waitForProcess h)
20+
res <- cabal_raw_action ["aaaa"] (\h -> void (Process.waitForProcess h))
2021
assertOutputContains "cabal-install" res
2122
assertOutputContains "is set" res
2223

0 commit comments

Comments
 (0)