Skip to content

Commit de666a7

Browse files
authored
Merge pull request #6454 from commercialhaskell/sundry-prefix
Remove prefixes from field names of various types
2 parents d5dc00b + 7600636 commit de666a7

File tree

14 files changed

+302
-274
lines changed

14 files changed

+302
-274
lines changed

.stan.toml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,24 @@
4343
# Infinite: base/isSuffixOf
4444
# Usage of the 'isSuffixOf' function that hangs on infinite lists
4545
[[ignore]]
46-
id = "OBS-STAN-0102-luLR/n-523:30"
46+
id = "OBS-STAN-0102-luLR/n-524:30"
4747
# ✦ Category: #Infinite #List
4848
# ✦ File: src\Stack\New.hs
4949
#
50-
# 522
51-
# 523 ┃ let isPkgSpec f = ".cabal" `L.isSuffixOf` f || "package.yaml" `L.isSuffixOf` f
52-
# 524 ┃ ^^^^^^^^^^^^^^
50+
# 523
51+
# 524 ┃ let isPkgSpec f = ".cabal" `L.isSuffixOf` f || "package.yaml" `L.isSuffixOf` f
52+
# 525 ┃ ^^^^^^^^^^^^^^
5353

5454
# Infinite: base/isSuffixOf
5555
# Usage of the 'isSuffixOf' function that hangs on infinite lists
5656
[[ignore]]
57-
id = "OBS-STAN-0102-luLR/n-523:65"
57+
id = "OBS-STAN-0102-luLR/n-524:65"
5858
# ✦ Category: #Infinite #List
5959
# ✦ File: src\Stack\New.hs
6060
#
61-
# 522
62-
# 523 ┃ let isPkgSpec f = ".cabal" `L.isSuffixOf` f || "package.yaml" `L.isSuffixOf` f
63-
# 524 ┃ ^^^^^^^^^^^^^^
61+
# 523
62+
# 524 ┃ let isPkgSpec f = ".cabal" `L.isSuffixOf` f || "package.yaml" `L.isSuffixOf` f
63+
# 525 ┃ ^^^^^^^^^^^^^^
6464

6565
# Infinite: base/length
6666
# Usage of the 'length' function that hangs on infinite lists
@@ -116,14 +116,14 @@
116116

117117
# Anti-pattern: Data.ByteString.Char8.pack
118118
[[ignore]]
119-
id = "OBS-STAN-0203-axv1UG-353:32"
119+
id = "OBS-STAN-0203-axv1UG-354:32"
120120
# ✦ Description: Usage of 'pack' function that doesn't handle Unicode characters
121121
# ✦ Category: #AntiPattern
122122
# ✦ File: src\Stack\Docker.hs
123123
#
124-
# 352
125-
# 353 ┃ hashRepoName = Hash.hash . BS.pack . takeWhile (\c -> c /= ':' && c /= '@')
126-
# 354 ┃ ^^^^^^^
124+
# 353
125+
# 354 ┃ hashRepoName = Hash.hash . BS.pack . takeWhile (\c -> c /= ':' && c /= '@')
126+
# 355 ┃ ^^^^^^^
127127

128128
# Data types with non-strict fields
129129
# Defining lazy fields in data types can lead to unexpected space leaks

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ library:
279279
- Stack.Types.BuildOpts
280280
- Stack.Types.BuildOptsCLI
281281
- Stack.Types.BuildOptsMonoid
282-
283282
- Stack.Types.CabalConfigKey
284283
- Stack.Types.Cache
285284
- Stack.Types.Casa
@@ -299,6 +298,7 @@ library:
299298
- Stack.Types.DependencyTree
300299
- Stack.Types.Docker
301300
- Stack.Types.DockerEntrypoint
301+
- Stack.Types.DotConfig
302302
- Stack.Types.DotOpts
303303
- Stack.Types.DownloadInfo
304304
- Stack.Types.DumpLogs

src/Stack/Coverage.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
22
{-# LANGUAGE DuplicateRecordFields #-}
33
{-# LANGUAGE LambdaCase #-}
4+
{-# LANGUAGE NoFieldSelectors #-}
45
{-# LANGUAGE OverloadedRecordDot #-}
56
{-# LANGUAGE OverloadedStrings #-}
67

@@ -102,20 +103,20 @@ instance Exception CoveragePrettyException
102103

103104
-- | Type representing command line options for the @stack hpc report@ command.
104105
data HpcReportOpts = HpcReportOpts
105-
{ hroptsInputs :: [Text]
106-
, hroptsAll :: Bool
107-
, hroptsDestDir :: Maybe String
108-
, hroptsOpenBrowser :: Bool
106+
{ inputs :: [Text]
107+
, all :: Bool
108+
, destDir :: Maybe String
109+
, openBrowser :: Bool
109110
}
110111
deriving Show
111112

112113
-- | Function underlying the @stack hpc report@ command.
113114
hpcReportCmd :: HpcReportOpts -> RIO Runner ()
114115
hpcReportCmd hropts = do
115116
let (tixFiles, targetNames) =
116-
L.partition (".tix" `T.isSuffixOf`) hropts.hroptsInputs
117+
L.partition (".tix" `T.isSuffixOf`) hropts.inputs
117118
boptsCLI = defaultBuildOptsCLI
118-
{ targetsCLI = if hropts.hroptsAll then [] else targetNames }
119+
{ targetsCLI = if hropts.all then [] else targetNames }
119120
withConfig YesReexec $ withEnvConfig AllowNoTargets boptsCLI $
120121
generateHpcReportForTargets hropts tixFiles targetNames
121122

@@ -363,10 +364,10 @@ generateHpcReportForTargets opts tixFiles targetNames = do
363364
targetTixFiles <-
364365
-- When there aren't any package component arguments, and --all
365366
-- isn't passed, default to not considering any targets.
366-
if not opts.hroptsAll && null targetNames
367+
if not opts.all && null targetNames
367368
then pure []
368369
else do
369-
when (opts.hroptsAll && not (null targetNames)) $
370+
when (opts.all && not (null targetNames)) $
370371
prettyWarnL
371372
$ "Since"
372373
: style Shell "--all"
@@ -404,7 +405,7 @@ generateHpcReportForTargets opts tixFiles targetNames = do
404405
mapM (resolveFile' . T.unpack) tixFiles
405406
when (null tixPaths) $ prettyThrowIO NoTargetsOrTixSpecified
406407
outputDir <- hpcReportDir
407-
reportDir <- case opts.hroptsDestDir of
408+
reportDir <- case opts.destDir of
408409
Nothing -> pure (outputDir </> relDirCombined </> relDirCustom)
409410
Just destDir -> do
410411
dest <- resolveDir' destDir
@@ -414,7 +415,7 @@ generateHpcReportForTargets opts tixFiles targetNames = do
414415
reportHtml = "combined coverage report"
415416
mreportPath <- generateUnionReport report reportHtml reportDir tixPaths
416417
forM_ mreportPath $ \reportPath ->
417-
if opts.hroptsOpenBrowser
418+
if opts.openBrowser
418419
then do
419420
prettyInfo $ "Opening" <+> pretty reportPath <+> "in the browser."
420421
void $ liftIO $ openBrowser (toFilePath reportPath)

src/Stack/DependencyGraph.hs

Lines changed: 15 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
22
{-# LANGUAGE DuplicateRecordFields #-}
3+
{-# LANGUAGE NoFieldSelectors #-}
34
{-# LANGUAGE OverloadedRecordDot #-}
45
{-# LANGUAGE OverloadedStrings #-}
56

@@ -19,7 +20,6 @@ import Distribution.License ( License (..) )
1920
import qualified Distribution.PackageDescription as PD
2021
import Distribution.Types.PackageName ( mkPackageName )
2122
import Path ( parent )
22-
import RIO.Process ( HasProcessContext (..) )
2323
import Stack.Build ( loadPackage )
2424
import Stack.Build.Installed ( getInstalled, toInstallMap )
2525
import Stack.Build.Source
@@ -41,18 +41,16 @@ import Stack.Types.BuildOptsCLI
4141
import Stack.Types.BuildOptsMonoid
4242
( buildOptsMonoidBenchmarksL, buildOptsMonoidTestsL )
4343
import Stack.Types.Compiler ( wantedToActual )
44-
import Stack.Types.Config ( HasConfig (..) )
4544
import Stack.Types.DependencyTree ( DotPayload (..) )
45+
import Stack.Types.DotConfig ( DotConfig (..) )
4646
import Stack.Types.DotOpts ( DotOpts (..) )
4747
import Stack.Types.DumpPackage ( DumpPackage (..) )
4848
import Stack.Types.EnvConfig ( EnvConfig (..), HasSourceMap (..) )
49-
import Stack.Types.GHCVariant ( HasGHCVariant (..) )
5049
import Stack.Types.GhcPkgId
5150
( GhcPkgId, ghcPkgIdString, parseGhcPkgId )
5251
import Stack.Types.GlobalOpts ( globalOptsBuildOptsMonoidL )
5352
import Stack.Types.Package ( LocalPackage (..) )
54-
import Stack.Types.Platform ( HasPlatform (..) )
55-
import Stack.Types.Runner ( HasRunner (..), Runner, globalOptsL )
53+
import Stack.Types.Runner ( Runner, globalOptsL )
5654
import Stack.Types.SourceMap
5755
( CommonPackage (..), DepPackage (..), ProjectPackage (..)
5856
, SMActual (..), SMWanted (..), SourceMap (..)
@@ -109,15 +107,15 @@ withDotConfig opts inner =
109107
else withConfig YesReexec withReal
110108
where
111109
withGlobalHints = do
112-
bconfig <- view buildConfigL
113-
globals <- globalsFromHints bconfig.smWanted.compiler
110+
buildConfig <- view buildConfigL
111+
globals <- globalsFromHints buildConfig.smWanted.compiler
114112
fakeGhcPkgId <- parseGhcPkgId "ignored"
115113
actual <- either throwIO pure $
116-
wantedToActual bconfig.smWanted.compiler
114+
wantedToActual buildConfig.smWanted.compiler
117115
let smActual = SMActual
118116
{ compiler = actual
119-
, project = bconfig.smWanted.project
120-
, deps = bconfig.smWanted.deps
117+
, project = buildConfig.smWanted.project
118+
, deps = buildConfig.smWanted.deps
121119
, global = Map.mapWithKey toDump globals
122120
}
123121
toDump :: PackageName -> Version -> DumpPackage
@@ -143,9 +141,9 @@ withDotConfig opts inner =
143141
logDebug "Loading source map"
144142
sourceMap <- loadSourceMap targets boptsCLI smActual
145143
let dc = DotConfig
146-
{ dcBuildConfig = bconfig
147-
, dcSourceMap = sourceMap
148-
, dcGlobalDump = toList smActual.global
144+
{ buildConfig
145+
, sourceMap
146+
, globalDump = toList smActual.global
149147
}
150148
logDebug "DotConfig fully loaded"
151149
runRIO dc inner
@@ -156,9 +154,9 @@ withDotConfig opts inner =
156154
installMap <- toInstallMap sourceMap
157155
(_, globalDump, _, _) <- getInstalled installMap
158156
let dc = DotConfig
159-
{ dcBuildConfig = envConfig.buildConfig
160-
, dcSourceMap = sourceMap
161-
, dcGlobalDump = globalDump
157+
{ buildConfig = envConfig.buildConfig
158+
, sourceMap
159+
, globalDump
162160
}
163161
runRIO dc inner
164162

@@ -186,7 +184,7 @@ createDependencyGraph dotOpts = do
186184
locals <- for (toList sourceMap.project) loadLocalPackage
187185
let graph =
188186
Map.fromList $ projectPackageDependencies dotOpts (filter (.wanted) locals)
189-
globalDump <- view $ to (.dcGlobalDump)
187+
globalDump <- view $ to (.globalDump)
190188
-- TODO: Can there be multiple entries for wired-in-packages? If so,
191189
-- this will choose one arbitrarily..
192190
let globalDumpMap = Map.fromList $
@@ -355,48 +353,3 @@ pruneUnreachable dontPrune = fixpoint prune
355353

356354
localPackageToPackage :: LocalPackage -> Package
357355
localPackageToPackage lp = fromMaybe lp.package lp.testBench
358-
359-
data DotConfig = DotConfig
360-
{ dcBuildConfig :: !BuildConfig
361-
, dcSourceMap :: !SourceMap
362-
, dcGlobalDump :: ![DumpPackage]
363-
}
364-
365-
instance HasLogFunc DotConfig where
366-
logFuncL = runnerL . logFuncL
367-
368-
instance HasPantryConfig DotConfig where
369-
pantryConfigL = configL . pantryConfigL
370-
371-
instance HasTerm DotConfig where
372-
useColorL = runnerL . useColorL
373-
termWidthL = runnerL . termWidthL
374-
375-
instance HasStylesUpdate DotConfig where
376-
stylesUpdateL = runnerL . stylesUpdateL
377-
378-
instance HasGHCVariant DotConfig where
379-
ghcVariantL = configL . ghcVariantL
380-
{-# INLINE ghcVariantL #-}
381-
382-
instance HasPlatform DotConfig where
383-
platformL = configL . platformL
384-
{-# INLINE platformL #-}
385-
platformVariantL = configL . platformVariantL
386-
{-# INLINE platformVariantL #-}
387-
388-
instance HasRunner DotConfig where
389-
runnerL = configL . runnerL
390-
391-
instance HasProcessContext DotConfig where
392-
processContextL = runnerL . processContextL
393-
394-
instance HasConfig DotConfig where
395-
configL = buildConfigL . lens (.config) (\x y -> x { config = y })
396-
{-# INLINE configL #-}
397-
398-
instance HasBuildConfig DotConfig where
399-
buildConfigL = lens (.dcBuildConfig) (\x y -> x { dcBuildConfig = y })
400-
401-
instance HasSourceMap DotConfig where
402-
sourceMapL = lens (.dcSourceMap) (\x y -> x { dcSourceMap = y })

src/Stack/Docker.hs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
2+
{-# LANGUAGE NoFieldSelectors #-}
23
{-# LANGUAGE OverloadedRecordDot #-}
34
{-# LANGUAGE OverloadedStrings #-}
45

@@ -235,8 +236,8 @@ runContainerAndExit = do
235236
| otherwise -> throwM (NotPulledException image)
236237
projectRoot <- getProjectRoot
237238
sandboxDir <- projectDockerSandboxDir projectRoot
238-
let ic = imageInfo.iiConfig
239-
imageEnvVars = map (break (== '=')) ic.icEnv
239+
let ic = imageInfo.config
240+
imageEnvVars = map (break (== '=')) ic.env
240241
platformVariant = show $ hashRepoName image
241242
stackRoot = view stackRootL config
242243
sandboxHomeDir = sandboxDir </> homeDirName
@@ -323,8 +324,8 @@ runContainerAndExit = do
323324
-- Disable the deprecated entrypoint in FP Complete-generated images
324325
, [ "--entrypoint=/usr/bin/env"
325326
| isJust (lookupImageEnv oldSandboxIdEnvVar imageEnvVars)
326-
&& ( ic.icEntrypoint == ["/usr/local/sbin/docker-entrypoint"]
327-
|| ic.icEntrypoint == ["/root/entrypoint.sh"]
327+
&& ( ic.entrypoint == ["/usr/local/sbin/docker-entrypoint"]
328+
|| ic.entrypoint == ["/root/entrypoint.sh"]
328329
)
329330
]
330331
, concatMap (\(k,v) -> ["-e", k ++ "=" ++ v]) envVars
@@ -627,10 +628,10 @@ oldSandboxIdEnvVar = "DOCKER_SANDBOX_ID"
627628

628629
-- | Parsed result of @docker inspect@.
629630
data Inspect = Inspect
630-
{ iiConfig :: ImageConfig
631-
, iiCreated :: UTCTime
632-
, iiId :: Text
633-
, iiVirtualSize :: Maybe Integer
631+
{ config :: ImageConfig
632+
, created :: UTCTime
633+
, iiId :: Text
634+
, virtualSize :: Maybe Integer
634635
}
635636
deriving Show
636637

@@ -646,8 +647,8 @@ instance FromJSON Inspect where
646647

647648
-- | Parsed @Config@ section of @docker inspect@ output.
648649
data ImageConfig = ImageConfig
649-
{ icEnv :: [String]
650-
, icEntrypoint :: [String]
650+
{ env :: [String]
651+
, entrypoint :: [String]
651652
}
652653
deriving Show
653654

src/Stack/Eval.hs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
{-# LANGUAGE NoImplicitPrelude #-}
2-
{-# LANGUAGE OverloadedRecordDot #-}
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
{-# LANGUAGE DuplicateRecordFields #-}
3+
{-# LANGUAGE NoFieldSelectors #-}
4+
{-# LANGUAGE OverloadedRecordDot #-}
35

46
-- | Types and functions related to Stack's @eval@ command.
57
module Stack.Eval
@@ -16,8 +18,8 @@ import Stack.Types.Runner ( Runner )
1618

1719
-- Type representing command line options for the @stack eval@ command.
1820
data EvalOpts = EvalOpts
19-
{ evalArg :: !String
20-
, evalExtra :: !ExecOptsExtra
21+
{ arg :: !String
22+
, extra :: !ExecOptsExtra
2123
}
2224
deriving Show
2325

@@ -27,7 +29,7 @@ evalCmd :: EvalOpts -> RIO Runner ()
2729
evalCmd eval = execCmd execOpts
2830
where
2931
execOpts = ExecOpts
30-
{ eoCmd = ExecGhc
31-
, eoArgs = ["-e", eval.evalArg]
32-
, eoExtra = eval.evalExtra
32+
{ cmd = ExecGhc
33+
, args = ["-e", eval.arg]
34+
, extra = eval.extra
3335
}

0 commit comments

Comments
 (0)