Skip to content

Commit c7ed72d

Browse files
authored
Merge pull request #11150 from cabalism/hlint/list-literal
HLint list literals
2 parents 42150df + 5da1cef commit c7ed72d

File tree

10 files changed

+15
-17
lines changed

10 files changed

+15
-17
lines changed

.hlint.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@
4747
- ignore: {name: "Use fst"} # 2 hints
4848
- ignore: {name: "Use lambda-case"} # 58 hints
4949
- ignore: {name: "Use list comprehension"} # 19 hints
50-
- ignore: {name: "Use list literal"} # 3 hints
51-
- ignore: {name: "Use list literal pattern"} # 11 hints
5250
- ignore: {name: "Use map once"} # 7 hints
5351
- ignore: {name: "Use map with tuple-section"} # 3 hints
5452
- ignore: {name: "Use mapMaybe"} # 13 hints

Cabal-syntax/src/Distribution/ModuleName.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ components :: ModuleName -> [String]
116116
components mn = split (unModuleName mn)
117117
where
118118
split cs = case break (== '.') cs of
119-
(chunk, []) -> chunk : []
119+
(chunk, []) -> [chunk]
120120
(chunk, _ : rest) -> chunk : split rest
121121

122122
-- | Convert a module name to a file path, but without any file extension.

Cabal-syntax/src/Distribution/Types/Version.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ mkVersion :: [Int] -> Version
141141
-- TODO: add validity check; disallow 'mkVersion []' (we have
142142
-- 'nullVersion' for that)
143143
mkVersion [] = nullVersion
144-
mkVersion (v1 : [])
144+
mkVersion [v1]
145145
| inWord16VerRep1 v1 = PV0 (mkWord64VerRep1 v1)
146146
| otherwise = PV1 v1 []
147147
where
148148
inWord16VerRep1 x1 = inWord16 (x1 .|. (x1 + 1))
149149
mkWord64VerRep1 y1 = mkWord64VerRep (y1 + 1) 0 0 0
150-
mkVersion (v1 : vs@(v2 : []))
150+
mkVersion (v1 : vs@[v2])
151151
| inWord16VerRep2 v1 v2 = PV0 (mkWord64VerRep2 v1 v2)
152152
| otherwise = PV1 v1 vs
153153
where
@@ -159,7 +159,7 @@ mkVersion (v1 : vs@(v2 : []))
159159
.|. (x2 + 1)
160160
)
161161
mkWord64VerRep2 y1 y2 = mkWord64VerRep (y1 + 1) (y2 + 1) 0 0
162-
mkVersion (v1 : vs@(v2 : v3 : []))
162+
mkVersion (v1 : vs@[v2, v3])
163163
| inWord16VerRep3 v1 v2 v3 = PV0 (mkWord64VerRep3 v1 v2 v3)
164164
| otherwise = PV1 v1 vs
165165
where
@@ -173,7 +173,7 @@ mkVersion (v1 : vs@(v2 : v3 : []))
173173
.|. (x3 + 1)
174174
)
175175
mkWord64VerRep3 y1 y2 y3 = mkWord64VerRep (y1 + 1) (y2 + 1) (y3 + 1) 0
176-
mkVersion (v1 : vs@(v2 : v3 : v4 : []))
176+
mkVersion (v1 : vs@[v2, v3, v4])
177177
| inWord16VerRep4 v1 v2 v3 v4 = PV0 (mkWord64VerRep4 v1 v2 v3 v4)
178178
| otherwise = PV1 v1 vs
179179
where

Cabal-syntax/src/Distribution/Types/VersionRange.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ isAnyVersionLight _vr = False
183183
isWildcardRange :: Version -> Version -> Bool
184184
isWildcardRange ver1 ver2 = check (versionNumbers ver1) (versionNumbers ver2)
185185
where
186-
check (n : []) (m : []) | n + 1 == m = True
186+
check [n] [m] | n + 1 == m = True
187187
check (n : ns) (m : ms) | n == m = check ns ms
188188
check _ _ = False
189189

Cabal/src/Distribution/GetOpt.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ getOpt' ordering optDescr (arg : args) = procNextOpt opt ordering
230230

231231
-- take a look at the next cmd line arg and decide what to do with it
232232
getNext :: String -> [String] -> [OptDescr a] -> (OptKind a, [String])
233-
getNext ('-' : '-' : []) rest _ = (EndOfOpts, rest)
233+
getNext ['-', '-'] rest _ = (EndOfOpts, rest)
234234
getNext ('-' : '-' : xs) rest optDescr = longOpt xs rest optDescr
235235
getNext ('-' : x : xs) rest optDescr = shortOpt x xs rest optDescr
236236
getNext a rest _ = (NonOpt a, rest)

Cabal/src/Distribution/Simple/Program/GHC.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,8 @@ renderGhcOptions comp _platform@(Platform _arch os) opts
905905
, if null (ghcOptInstantiatedWith opts)
906906
then []
907907
else
908-
"-instantiated-with"
909-
: intercalate
908+
[ "-instantiated-with"
909+
, intercalate
910910
","
911911
( map
912912
( \(n, m) ->
@@ -916,7 +916,7 @@ renderGhcOptions comp _platform@(Platform _arch os) opts
916916
)
917917
(ghcOptInstantiatedWith opts)
918918
)
919-
: []
919+
]
920920
, concat [["-fno-code", "-fwrite-interface"] | flagBool ghcOptNoCode]
921921
, ["-hide-all-packages" | flagBool ghcOptHideAllPackages]
922922
, ["-Wmissing-home-modules" | flagBool ghcOptWarnMissingHomeModules]

Cabal/src/Distribution/Simple/Utils.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,7 @@ createDirectoryIfMissingVerbose verbosity create_parents path0
15941594
parents = reverse . scanl1 (</>) . splitDirectories . normalise
15951595

15961596
createDirs [] = return ()
1597-
createDirs (dir : []) = createDir dir throwIO
1597+
createDirs [dir] = createDir dir throwIO
15981598
createDirs (dir : dirs) =
15991599
createDir dir $ \_ -> do
16001600
createDirs dirs

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2104,5 +2104,5 @@ monoidFieldParsec name showF readF get' set =
21042104
showTokenQ :: String -> Doc
21052105
showTokenQ "" = Disp.empty
21062106
showTokenQ x@('-' : '-' : _) = Disp.text (show x)
2107-
showTokenQ x@('.' : []) = Disp.text (show x)
2107+
showTokenQ x@['.'] = Disp.text (show x)
21082108
showTokenQ x = showToken x

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,9 +1496,9 @@ dieOnBuildFailures verbosity currentCommand plan buildOutcomes
14961496
renderDependencyOf pkgid =
14971497
case ultimateDeps pkgid of
14981498
[] -> ""
1499-
(p1 : []) ->
1499+
[p1] ->
15001500
" (which is required by " ++ elabPlanPackageName verbosity p1 ++ ")"
1501-
(p1 : p2 : []) ->
1501+
[p1, p2] ->
15021502
" (which is required by "
15031503
++ elabPlanPackageName verbosity p1
15041504
++ " and "

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ gitProgram =
637637
where
638638
isTypical c = isDigit c || c == '.'
639639
split cs = case break (== '.') cs of
640-
(chunk, []) -> chunk : []
640+
(chunk, []) -> [chunk]
641641
(chunk, _ : rest) -> chunk : split rest
642642

643643
-- | VCS driver for Mercurial.

0 commit comments

Comments
 (0)