Skip to content

Commit 92213d7

Browse files
committed
treewide: use stub
1 parent 4de75f0 commit 92213d7

File tree

10 files changed

+58
-27
lines changed

10 files changed

+58
-27
lines changed

.hlint.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
name: Use Foldable.forM_
2121
- hint:
2222
lhs: "pure ()"
23-
note: "Use 'pass'"
24-
rhs: pass
23+
note: "Use 'stub'"
24+
rhs: stub
2525
- hint:
2626
lhs: "return ()"
27-
note: "Use 'pass'"
28-
rhs: pass
27+
note: "Use 'stub'"
28+
rhs: stub
2929
- hint:
3030
lhs: "(: [])"
3131
note: "Use `one`"
@@ -2667,11 +2667,22 @@
26672667
lhs: sum xs / length xs
26682668
note: "Use `average` from `Relude.Extra.Foldable`"
26692669
rhs: average xs
2670+
26702671
- hint:
26712672
lhs: "\\a -> (a, a)"
2672-
note: "Use `dup` from `Relude.Extra.Tuple`"
2673+
note: "Use `dup`"
26732674
rhs: dup
26742675

26752676
- warn:
26762677
lhs: "() <$ a"
26772678
rhs: void a
2679+
2680+
- hint:
2681+
lhs: "pass"
2682+
note: "Use 'stub'"
2683+
rhs: stub
2684+
2685+
- warn:
2686+
lhs: "Data.Bool.bool True"
2687+
rhs: "Use `whenTrue` from HNix Prelude"
2688+

main/Main.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,10 @@ main' opts@Options{..} = runWithBasicEffectsIO opts execContentsFilesOrRepl
240240
liftIO $ Text.putStrLn path
241241
when descend $
242242
maybe
243-
pass
243+
stub
244244
(\case
245245
NVSet _ s' -> go (path <> ".") s'
246-
_ -> pass
246+
_ -> stub
247247
)
248248
mv
249249
)

main/Repl.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ exec update source = do
226226
-- If the result value is a set, update our context with it
227227
case val of
228228
NVSet _ (coerce -> scope) -> put state { replCtx = scope <> replCtx state }
229-
_ -> pass
229+
_ -> stub
230230

231231
pure $ pure val
232232
)
@@ -258,7 +258,7 @@ cmd source =
258258
do
259259
mVal <- exec True source
260260
maybe
261-
pass
261+
stub
262262
printValue
263263
mVal
264264

src/Nix/Convert.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ instance Convertible e t f m
147147
fromValueMay =
148148
pure .
149149
\case
150-
NVConstant' NNull -> pass
150+
NVConstant' NNull -> stub
151151
_ -> mempty
152152

153153
fromValue = fromMayToValue TNull

src/Nix/Utils.hs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ module Nix.Utils
1515
, trace
1616
, traceM
1717
, stub
18+
, pass
1819
, whenTrue
1920
, list
2021
, whenText
2122
, free
23+
, whenJust
2224
, dup
2325
, mapPair
2426
, both
@@ -30,7 +32,8 @@ module Nix.Utils
3032
)
3133
where
3234

33-
import Relude hiding ( force
35+
import Relude hiding ( pass
36+
, force
3437
, readFile
3538
, whenJust
3639
, whenNothing
@@ -66,7 +69,7 @@ trace :: String -> a -> a
6669
trace = const id
6770
{-# inline trace #-}
6871
traceM :: Monad m => String -> m ()
69-
traceM = const pass
72+
traceM = const stub
7073
{-# inline traceM #-}
7174
#endif
7275

@@ -187,6 +190,17 @@ whenTrue =
187190
mempty
188191
{-# inline whenTrue #-}
189192

193+
whenJust
194+
:: Monoid b
195+
=> (a -> b)
196+
-> Maybe a
197+
-> b
198+
whenJust f ma =
199+
maybe
200+
mempty
201+
f
202+
ma
203+
190204

191205
-- | Apply a single function to both components of a pair.
192206
--
@@ -214,6 +228,11 @@ stub :: (Applicative f, Monoid a) => f a
214228
stub = pure mempty
215229
{-# inline stub #-}
216230

231+
-- | Alias for @stub@, since @Relude@ has more specialized @pure ()@.
232+
pass :: (Applicative f) => f ()
233+
pass = stub
234+
{-# inline pass #-}
235+
217236
readFile :: Path -> IO Text
218237
readFile = Text.readFile . coerce
219238

src/Nix/Value/Equal.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ checkComparable
3131
-> m ()
3232
checkComparable x y =
3333
case (x, y) of
34-
(NVConstant (NFloat _), NVConstant (NInt _)) -> pass
35-
(NVConstant (NInt _), NVConstant (NFloat _)) -> pass
36-
(NVConstant (NInt _), NVConstant (NInt _)) -> pass
37-
(NVConstant (NFloat _), NVConstant (NFloat _)) -> pass
38-
(NVStr _ , NVStr _ ) -> pass
39-
(NVPath _ , NVPath _ ) -> pass
34+
(NVConstant (NFloat _), NVConstant (NInt _)) -> stub
35+
(NVConstant (NInt _), NVConstant (NFloat _)) -> stub
36+
(NVConstant (NInt _), NVConstant (NInt _)) -> stub
37+
(NVConstant (NFloat _), NVConstant (NFloat _)) -> stub
38+
(NVStr _ , NVStr _ ) -> stub
39+
(NVPath _ , NVPath _ ) -> stub
4040
_ -> throwError $ Comparison x y
4141

4242
-- | Checks whether two containers are equal, using the given item equality

src/Prelude.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ module Prelude
99
) where
1010

1111
import Nix.Utils
12-
import Relude hiding ( force
12+
import Relude hiding ( pass
13+
, force
1314
, readFile
1415
, whenJust
1516
, whenNothing

tests/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ ensureNixpkgsCanParse =
7070
-- Parse and deepseq the resulting expression tree, to ensure the
7171
-- parser is fully executed.
7272
_ <- consider (coerce file) (parseNixFileLoc (coerce file)) $ Exc.evaluate . force
73-
pass
73+
stub
7474
v -> fail $ "Unexpected parse from default.nix: " <> show v
7575
where
7676
getExpr k m = let Just (Just r) = lookup k m in r

tests/NixLanguageTests.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ assertParse _opts file =
109109
x <- parseNixFileLoc file
110110
either
111111
(\ err -> assertFailure $ "Failed to parse " <> coerce file <> ":\n" <> show err)
112-
(const pass) -- pure $! runST $ void $ lint opts expr
112+
(const stub) -- pure $! runST $ void $ lint opts expr
113113
x
114114

115115
assertParseFail :: Options -> Path -> Assertion
116116
assertParseFail opts file = do
117117
eres <- parseNixFileLoc file
118-
(`catch` \(_ :: SomeException) -> pass)
118+
(`catch` \(_ :: SomeException) -> stub)
119119
(either
120-
(const pass)
120+
(const stub)
121121
(\ expr ->
122122
do
123123
_ <- pure $! runST $ void $ lint opts expr
@@ -147,8 +147,8 @@ assertEval _opts files =
147147
[] -> void $ hnixEvalFile opts (name <> ".nix")
148148
[".exp" ] -> assertLangOk opts name
149149
[".exp.xml" ] -> assertLangOkXml opts name
150-
[".exp.disabled" ] -> pass
151-
[".exp-disabled" ] -> pass
150+
[".exp.disabled" ] -> stub
151+
[".exp-disabled" ] -> stub
152152
[".exp", ".flags"] ->
153153
do
154154
liftIO $ setEnv "NIX_PATH" "lang/dir4:lang/dir5"
@@ -177,7 +177,7 @@ assertEval _opts files =
177177
fixup [] = mempty
178178

179179
assertEvalFail :: Path -> Assertion
180-
assertEvalFail file = (`catch` (\(_ :: SomeException) -> pass)) $ do
180+
assertEvalFail file = (`catch` (\(_ :: SomeException) -> stub)) $ do
181181
time <- liftIO getCurrentTime
182182
evalResult <- printNix <$> hnixEvalFile (defaultOptions time) file
183183
evalResult `seq` assertFailure $ "File: ''" <> coerce file <> "'' should not evaluate.\nThe evaluation result was `" <> evalResult <> "`."

tests/ParserTests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ assertParseFile file expected =
740740
assertParseFail :: NixLang -> Assertion
741741
assertParseFail str =
742742
either
743-
(const pass)
743+
(const stub)
744744
(\ r ->
745745
assertFailure $ toString $ "\nUnexpected success parsing string ''" <> str <> "'':\n''Parsed value: ''" <> show r <> "''."
746746
)

0 commit comments

Comments
 (0)