Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@
- ignore: {name: "Use unless"} # 23 hints
- ignore: {name: "Use void"} # 23 hints

- group:
name: cabal-suggestions
enabled: true
rules:
- hint:
lhs: fromMaybe x (Data.Map.lookup k m)
rhs: Map.findWithDefault x k m
name: Use findWithDefault

- arguments:
- --ignore-glob=Cabal-syntax/src/Distribution/Fields/Lexer.hs
- --ignore-glob=Cabal-tests/tests/custom-setup/CabalDoctestSetup.hs
Expand Down
4 changes: 1 addition & 3 deletions Cabal/src/Distribution/Backpack/LinkedComponent.hs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ toLinkedComponent

lookupUid :: ComponentId -> (OpenUnitId, ModuleShape)
lookupUid cid =
fromMaybe
(error "linkComponent: lookupUid")
(Map.lookup cid pkg_map)
Map.findWithDefault (error "linkComponent: lookupUid") cid pkg_map

let orErr (Right x) = return x
orErr (Left [err]) = dieProgress err
Expand Down
2 changes: 1 addition & 1 deletion cabal-dev-scripts/src/GenUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ combine f t
unDiff (Diff.Both _ a) = a -- important we prefer latter versions!

addTags :: a -> (a, Set.Set tag)
addTags a = (a, fromMaybe Set.empty (Map.lookup (f a) tags))
addTags a = (a, Map.findWithDefault Set.empty (f a) tags)

process :: tag -> [a] -> [a]
process tag as = map unDiff $ Diff.getDiffBy (\x y -> f x == f y) (t tag) as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ internalError name = error ("PackageIndex." ++ name ++ ": internal error")
-- case-sensitively.
--
lookup :: PackageIndex pkg -> PackageName -> [pkg]
lookup (PackageIndex m) name = fromMaybe [] $ Map.lookup name m
lookup (PackageIndex m) name = Map.findWithDefault [] name m

--
-- * Construction
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ interpretPackagesPreference selected defaultPref prefs =
where
versionPref :: PackageName -> [VersionRange]
versionPref pkgname =
fromMaybe [anyVersion] (Map.lookup pkgname versionPrefs)
Map.findWithDefault [anyVersion] pkgname versionPrefs
versionPrefs =
Map.fromListWith
(++)
Expand All @@ -895,7 +895,7 @@ interpretPackagesPreference selected defaultPref prefs =

installPref :: PackageName -> InstalledPreference
installPref pkgname =
fromMaybe (installPrefDefault pkgname) (Map.lookup pkgname installPrefs)
Map.findWithDefault (installPrefDefault pkgname) pkgname installPrefs
installPrefs =
Map.fromList
[ (pkgname, pref)
Expand All @@ -914,7 +914,7 @@ interpretPackagesPreference selected defaultPref prefs =

stanzasPref :: PackageName -> [OptionalStanza]
stanzasPref pkgname =
fromMaybe [] (Map.lookup pkgname stanzasPrefs)
Map.findWithDefault [] pkgname stanzasPrefs
stanzasPrefs =
Map.fromListWith
(\a b -> nub (a ++ b))
Expand Down
8 changes: 2 additions & 6 deletions cabal-install/src/Distribution/Client/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ getPkgList verbosity packageDBs repoCtxt mcompprogdb listFlags pats = do

let sourcePkgIndex = packageIndex sourcePkgDb
prefs name =
fromMaybe
anyVersion
(Map.lookup name (packagePreferences sourcePkgDb))
Map.findWithDefault anyVersion name (packagePreferences sourcePkgDb)

pkgsInfoMatching
:: [(PackageName, [Installed.InstalledPackageInfo], [UnresolvedSourcePackage])]
Expand Down Expand Up @@ -269,9 +267,7 @@ info
sourcePkgDb <- getSourcePackages verbosity repoCtxt
let sourcePkgIndex = packageIndex sourcePkgDb
prefs name =
fromMaybe
anyVersion
(Map.lookup name (packagePreferences sourcePkgDb))
Map.findWithDefault anyVersion name (packagePreferences sourcePkgDb)

-- Users may specify names of packages that are only installed, not
-- just available source packages, so we must resolve targets using
Expand Down
2 changes: 1 addition & 1 deletion doc/cabal-package-description-file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3156,7 +3156,7 @@ package-related constants:
copyright :: String
homepage :: String

Unlike :file:`Paths_{pkgname}` (see <#accessing-data-files-from-package-code>),
Unlike :file:`Paths_{pkgname}` (see :ref:`accessing-data-files`),
:file:`PackageInfo_{pkgname}` is system- and path-independent. It aims to be
easier to work with for hash-based tools such as Nix.

Expand Down
Loading