From c7f3def10b73056a60e5ffe28c3af63b8b1ecb9c Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Sun, 5 Jan 2025 15:20:59 -0500 Subject: [PATCH 1/3] Remove CPP MIN_VERSION_base(4,11,0) in Cabal.Monad --- cabal-testsuite/src/Test/Cabal/Monad.hs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cabal-testsuite/src/Test/Cabal/Monad.hs b/cabal-testsuite/src/Test/Cabal/Monad.hs index 31e1e07bf52..22dc999ee98 100644 --- a/cabal-testsuite/src/Test/Cabal/Monad.hs +++ b/cabal-testsuite/src/Test/Cabal/Monad.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE ScopedTypeVariables #-} -- | The test monad @@ -88,9 +87,6 @@ import Distribution.Verbosity import Distribution.Version import Control.Concurrent.Async -#if !MIN_VERSION_base(4,11,0) -import Data.Monoid ((<>)) -#endif import Data.Monoid (mempty) import qualified Control.Exception as E import Control.Monad From 217f08ac58a597d14222d6c0fe1322a91387653f Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 6 Jan 2025 08:48:12 -0500 Subject: [PATCH 2/3] Follow hlint suggestion: use fewer imports - Use fewer imports with CPP in Compat.Time - Use fewer imports in IntegrationTests2 - Use fewer imports in Distribution.Client.ProjectPlanning - Use fewer imports in Distribution.Client.Config - Use fewer imports in Distribution.Client.NixStyleOptions - Use fewer imports in Internal.TempFile - Use fewer imports in Distribution.Client.Store - Use fewer imports in Distribution.Client.SetupWrapper - Use fewer imports in Disribution.Simple.GHC - Use fewer imports in NeedleHaystack - Remove unused -XCPP from Client.ProjectPlanning - Enable hlint suggestion "Use fewer imports" - Ignore custom setup test files from Idris and Doctest --- .hlint.yaml | 3 ++- .../Distribution/Compat/Internal/TempFile.hs | 4 ++-- Cabal/src/Distribution/Compat/Time.hs | 9 ++++---- Cabal/src/Distribution/Simple/GHC.hs | 23 +++++++++++-------- .../src/Distribution/Client/CmdTest.hs | 4 ++-- .../src/Distribution/Client/Config.hs | 8 +++---- .../Distribution/Client/ProjectPlanning.hs | 15 +++++++++--- .../src/Distribution/Client/SetupWrapper.hs | 6 +++-- .../src/Distribution/Client/Store.hs | 3 +-- cabal-install/tests/IntegrationTests2.hs | 7 ++++-- .../src/Test/Cabal/NeedleHaystack.hs | 3 +-- 11 files changed, 52 insertions(+), 33 deletions(-) diff --git a/.hlint.yaml b/.hlint.yaml index 26dc61fbbd1..2202651dc9a 100644 --- a/.hlint.yaml +++ b/.hlint.yaml @@ -48,7 +48,6 @@ - ignore: {name: "Use concatMap"} # 2 hints - ignore: {name: "Use const"} # 36 hints - ignore: {name: "Use elem"} # 2 hints -- ignore: {name: "Use fewer imports"} # 13 hints - ignore: {name: "Use first"} # 4 hints - ignore: {name: "Use fmap"} # 26 hints - ignore: {name: "Use fold"} # 1 hint @@ -95,6 +94,8 @@ - arguments: - --ignore-glob=Cabal-syntax/src/Distribution/Fields/Lexer.hs + - --ignore-glob=Cabal-tests/tests/custom-setup/CabalDoctestSetup.hs + - --ignore-glob=Cabal-tests/tests/custom-setup/IdrisSetup.hs - --ignore-glob=cabal-testsuite/PackageTests/BuildWays/q/app/Main.hs - --ignore-glob=cabal-testsuite/PackageTests/CmmSources/src/Demo.hs - --ignore-glob=cabal-testsuite/PackageTests/CmmSourcesDyn/src/Demo.hs diff --git a/Cabal/src/Distribution/Compat/Internal/TempFile.hs b/Cabal/src/Distribution/Compat/Internal/TempFile.hs index 5d3683be079..89f8575b6e8 100644 --- a/Cabal/src/Distribution/Compat/Internal/TempFile.hs +++ b/Cabal/src/Distribution/Compat/Internal/TempFile.hs @@ -15,17 +15,17 @@ import System.FilePath (()) import System.IO (Handle, openBinaryTempFile, openTempFile) #if defined(__IO_MANAGER_WINIO__) import System.IO (openBinaryTempFileWithDefaultPermissions) +import System.Posix.Internals (c_getpid) #else import Control.Exception (onException) import Data.Bits ((.|.)) import Foreign.C (CInt, eEXIST, getErrno, errnoToIOError) import GHC.IO.Handle.FD (fdToHandle) -import System.Posix.Internals (c_open, c_close, o_EXCL, o_BINARY, withFilePath, +import System.Posix.Internals (c_getpid, c_open, c_close, o_EXCL, o_BINARY, withFilePath, o_CREAT, o_RDWR, o_NONBLOCK, o_NOCTTY) #endif import System.IO.Error (isAlreadyExistsError) -import System.Posix.Internals (c_getpid) #if defined(mingw32_HOST_OS) || defined(ghcjs_HOST_OS) import System.Directory ( createDirectory ) diff --git a/Cabal/src/Distribution/Compat/Time.hs b/Cabal/src/Distribution/Compat/Time.hs index 088c01950c0..cce1ceaf819 100644 --- a/Cabal/src/Distribution/Compat/Time.hs +++ b/Cabal/src/Distribution/Compat/Time.hs @@ -41,13 +41,14 @@ import System.Win32.Types ( BOOL, DWORD, LPCTSTR, LPVOID, withTString ) #else -import System.Posix.Files ( FileStatus, getFileStatus ) - +import System.Posix.Files + ( FileStatus, getFileStatus #if MIN_VERSION_unix(2,6,0) -import System.Posix.Files ( modificationTimeHiRes ) + , modificationTimeHiRes #else -import System.Posix.Files ( modificationTime ) + , modificationTime #endif + ) #endif diff --git a/Cabal/src/Distribution/Simple/GHC.hs b/Cabal/src/Distribution/Simple/GHC.hs index 728d5c5ef9b..45fbee0fed1 100644 --- a/Cabal/src/Distribution/Simple/GHC.hs +++ b/Cabal/src/Distribution/Simple/GHC.hs @@ -124,24 +124,29 @@ import Distribution.Utils.Path import Distribution.Verbosity import Distribution.Version import Language.Haskell.Extension -import System.Directory - ( canonicalizePath - , createDirectoryIfMissing - , doesDirectoryExist - , doesFileExist - , getAppUserDataDirectory - , getDirectoryContents - ) import System.FilePath ( isRelative , takeDirectory ) import qualified System.Info #ifndef mingw32_HOST_OS -import System.Directory (renameFile) import System.Posix (createSymbolicLink) #endif /* mingw32_HOST_OS */ +{- FOURMOLU_DISABLE -} +import System.Directory + ( canonicalizePath + , createDirectoryIfMissing + , doesDirectoryExist + , doesFileExist + , getAppUserDataDirectory + , getDirectoryContents +#ifndef mingw32_HOST_OS + , renameFile +#endif + ) +{- FOURMOLU_ENABLE -} + import Distribution.Simple.Setup (BuildingWhat (..)) import Distribution.Simple.Setup.Build diff --git a/cabal-install/src/Distribution/Client/CmdTest.hs b/cabal-install/src/Distribution/Client/CmdTest.hs index 7c1adffdc91..3812bd6af87 100644 --- a/cabal-install/src/Distribution/Client/CmdTest.hs +++ b/cabal-install/src/Distribution/Client/CmdTest.hs @@ -33,7 +33,8 @@ import Distribution.Client.NixStyleOptions ) import Distribution.Client.ProjectOrchestration import Distribution.Client.Setup - ( ConfigFlags (..) + ( CommonSetupFlags (..) + , ConfigFlags (..) , GlobalFlags (..) ) import Distribution.Client.TargetProblem @@ -66,7 +67,6 @@ import Distribution.Verbosity import qualified System.Exit (exitSuccess) import Distribution.Client.Errors -import Distribution.Client.Setup (CommonSetupFlags (..)) import GHC.Environment ( getFullArgs ) diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs index d4214cc383b..7322927aa24 100644 --- a/cabal-install/src/Distribution/Client/Config.hs +++ b/cabal-install/src/Distribution/Client/Config.hs @@ -49,7 +49,10 @@ module Distribution.Client.Config ) where import Distribution.Client.Compat.Prelude -import Distribution.Compat.Environment (lookupEnv) +import Distribution.Compat.Environment + ( getEnvironment + , lookupEnv + ) import Prelude () import Language.Haskell.Extension (Language (Haskell2010)) @@ -126,9 +129,6 @@ import Distribution.Client.Version ( cabalInstallVersion ) import qualified Distribution.Compat.CharParsing as P -import Distribution.Compat.Environment - ( getEnvironment - ) import Distribution.Compiler ( CompilerFlavor (..) , defaultCompilerFlavor diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index 582e526af53..8f2250257ff 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE LambdaCase #-} @@ -99,7 +98,18 @@ module Distribution.Client.ProjectPlanning ) where import Distribution.Client.Compat.Prelude -import Text.PrettyPrint (render) +import Text.PrettyPrint + ( colon + , comma + , fsep + , hang + , punctuate + , quotes + , render + , text + , vcat + , ($$) + ) import Prelude () import Distribution.Client.Config @@ -222,7 +232,6 @@ import qualified Data.Set as Set import Distribution.Client.Errors import Distribution.Solver.Types.ProjectConfigPath import System.FilePath -import Text.PrettyPrint (colon, comma, fsep, hang, punctuate, quotes, text, vcat, ($$)) import qualified Text.PrettyPrint as Disp -- | Check that an 'ElaboratedConfiguredPackage' actually makes diff --git a/cabal-install/src/Distribution/Client/SetupWrapper.hs b/cabal-install/src/Distribution/Client/SetupWrapper.hs index 1b401ff6f7c..78833af6d15 100644 --- a/cabal-install/src/Distribution/Client/SetupWrapper.hs +++ b/cabal-install/src/Distribution/Client/SetupWrapper.hs @@ -143,7 +143,10 @@ import Distribution.Simple.Program.GHC , renderGhcOptions ) import Distribution.Simple.Setup - ( Flag (..), CommonSetupFlags (..), GlobalFlags (..) + ( CommonSetupFlags (..) + , Flag (..) + , GlobalFlags (..) + , globalCommand ) import Distribution.Simple.Utils ( cabalVersion @@ -175,7 +178,6 @@ import Distribution.Verbosity import Data.List (foldl1') import qualified Data.Map.Lazy as Map -import Distribution.Simple.Setup (globalCommand) import Distribution.Client.Compat.ExecutablePath (getExecutablePath) import Distribution.Compat.Process (proc) import System.Directory (doesFileExist) diff --git a/cabal-install/src/Distribution/Client/Store.hs b/cabal-install/src/Distribution/Client/Store.hs index 9ffe6099c7f..dcf4c78d02c 100644 --- a/cabal-install/src/Distribution/Client/Store.hs +++ b/cabal-install/src/Distribution/Client/Store.hs @@ -47,8 +47,7 @@ import System.FilePath import Lukko #else import System.IO (openFile, IOMode(ReadWriteMode), hClose) -import GHC.IO.Handle.Lock (hLock, hTryLock, LockMode(ExclusiveLock)) -import GHC.IO.Handle.Lock (hUnlock) +import GHC.IO.Handle.Lock (LockMode (ExclusiveLock), hLock, hTryLock, hUnlock) #endif -- $concurrency diff --git a/cabal-install/tests/IntegrationTests2.hs b/cabal-install/tests/IntegrationTests2.hs index daf6959fbc2..04bd32add66 100644 --- a/cabal-install/tests/IntegrationTests2.hs +++ b/cabal-install/tests/IntegrationTests2.hs @@ -54,7 +54,11 @@ import qualified Distribution.Client.CmdTest as CmdTest import qualified Distribution.Client.CmdHaddockProject as CmdHaddockProject import Distribution.Client.Config (SavedConfig (savedGlobalFlags), createDefaultConfigFile, loadConfig) -import Distribution.Client.GlobalFlags (defaultGlobalFlags) +import Distribution.Client.GlobalFlags + ( GlobalFlags + , defaultGlobalFlags + , globalNix + ) import Distribution.Client.Setup (globalCommand, globalStoreDir) import Distribution.InstalledPackageInfo (InstalledPackageInfo) import Distribution.ModuleName (ModuleName) @@ -90,7 +94,6 @@ import Test.Tasty.Options import qualified Data.ByteString as BS import Data.Maybe (fromJust) -import Distribution.Client.GlobalFlags (GlobalFlags, globalNix) import Distribution.Simple.Flag (Flag (Flag, NoFlag)) import Distribution.Types.ParStrat diff --git a/cabal-testsuite/src/Test/Cabal/NeedleHaystack.hs b/cabal-testsuite/src/Test/Cabal/NeedleHaystack.hs index 42ab1031284..0e8dfae9038 100644 --- a/cabal-testsuite/src/Test/Cabal/NeedleHaystack.hs +++ b/cabal-testsuite/src/Test/Cabal/NeedleHaystack.hs @@ -20,11 +20,10 @@ module Test.Cabal.NeedleHaystack import Prelude hiding (unlines) import qualified Prelude (unlines) -import Data.List (tails) import Data.Maybe (isJust) import Distribution.System import Distribution.Utils.Generic (unsnoc) -import Data.List (isPrefixOf) +import Data.List (isPrefixOf, tails) import qualified System.FilePath.Posix as Posix import qualified System.FilePath.Windows as Windows import Network.URI (parseURI) From d165dfda4361a7c1c51b6e7869ffcb2c0311b6d0 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Mon, 6 Jan 2025 08:58:31 -0500 Subject: [PATCH 3/3] Bump hlint warning counts --- .hlint.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.hlint.yaml b/.hlint.yaml index 2202651dc9a..6c5d86998d3 100644 --- a/.hlint.yaml +++ b/.hlint.yaml @@ -1,7 +1,7 @@ # Warnings currently triggered by your code - ignore: {name: "Avoid NonEmpty.unzip"} # 1 hint - ignore: {name: "Avoid lambda"} # 47 hints -- ignore: {name: "Avoid lambda using `infix`"} # 22 hints +- ignore: {name: "Avoid lambda using `infix`"} # 23 hints - ignore: {name: "Eta reduce"} # 124 hints - ignore: {name: "Evaluate"} # 10 hints - ignore: {name: "Functor law"} # 10 hints @@ -16,11 +16,11 @@ - ignore: {name: "Monoid law, right identity"} # 3 hints - ignore: {name: "Move filter"} # 4 hints - ignore: {name: "Move guards forward"} # 4 hints -- ignore: {name: "Redundant $"} # 179 hints +- ignore: {name: "Redundant $"} # 178 hints - ignore: {name: "Redundant $!"} # 1 hint - ignore: {name: "Redundant <$>"} # 16 hints - ignore: {name: "Redundant =="} # 1 hint -- ignore: {name: "Redundant bracket"} # 239 hints +- ignore: {name: "Redundant bracket"} # 240 hints - ignore: {name: "Redundant fmap"} # 1 hint - ignore: {name: "Redundant guard"} # 2 hints - ignore: {name: "Redundant if"} # 6 hints @@ -49,7 +49,7 @@ - ignore: {name: "Use const"} # 36 hints - ignore: {name: "Use elem"} # 2 hints - ignore: {name: "Use first"} # 4 hints -- ignore: {name: "Use fmap"} # 26 hints +- ignore: {name: "Use fmap"} # 25 hints - ignore: {name: "Use fold"} # 1 hint - ignore: {name: "Use for"} # 1 hint - ignore: {name: "Use forM_"} # 1 hint @@ -65,7 +65,7 @@ - ignore: {name: "Use isNothing"} # 1 hint - ignore: {name: "Use lambda-case"} # 55 hints - ignore: {name: "Use lefts"} # 1 hint -- ignore: {name: "Use list comprehension"} # 18 hints +- ignore: {name: "Use list comprehension"} # 19 hints - ignore: {name: "Use list literal"} # 3 hints - ignore: {name: "Use list literal pattern"} # 11 hints - ignore: {name: "Use map once"} # 7 hints