Skip to content

Commit

Permalink
Follow hlint suggestion: use fewer imports
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
philderbeast committed Jan 7, 2025
1 parent c7f3def commit 217f08a
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Cabal/src/Distribution/Compat/Internal/TempFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
9 changes: 5 additions & 4 deletions Cabal/src/Distribution/Compat/Time.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
23 changes: 14 additions & 9 deletions Cabal/src/Distribution/Simple/GHC.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/CmdTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import Distribution.Client.NixStyleOptions
)
import Distribution.Client.ProjectOrchestration
import Distribution.Client.Setup
( ConfigFlags (..)
( CommonSetupFlags (..)
, ConfigFlags (..)
, GlobalFlags (..)
)
import Distribution.Client.TargetProblem
Expand Down Expand Up @@ -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
)
Expand Down
8 changes: 4 additions & 4 deletions cabal-install/src/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions cabal-install/src/Distribution/Client/SetupWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions cabal-install/src/Distribution/Client/Store.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions cabal-testsuite/src/Test/Cabal/NeedleHaystack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 217f08a

Please sign in to comment.