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

(cherry picked from commit 217f08a)

# Conflicts:
#	.hlint.yaml
#	cabal-install/tests/IntegrationTests2.hs
#	cabal-testsuite/src/Test/Cabal/NeedleHaystack.hs
  • Loading branch information
philderbeast authored and mergify[bot] committed Jan 9, 2025
1 parent 43b6128 commit 9cac543
Show file tree
Hide file tree
Showing 11 changed files with 346 additions and 28 deletions.
9 changes: 9 additions & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
- ignore: {name: "Use concatMap"} # 1 hint
- ignore: {name: "Use const"} # 36 hints
- ignore: {name: "Use elem"} # 2 hints
<<<<<<< HEAD
- ignore: {name: "Use fewer imports"} # 19 hints
=======
>>>>>>> 217f08ac5 (Follow hlint suggestion: use fewer imports)
- ignore: {name: "Use first"} # 4 hints
- ignore: {name: "Use fmap"} # 24 hints
- ignore: {name: "Use fold"} # 1 hint
Expand Down Expand Up @@ -96,6 +99,12 @@

- arguments:
- --ignore-glob=Cabal-syntax/src/Distribution/Fields/Lexer.hs
<<<<<<< HEAD
=======
- --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
>>>>>>> 217f08ac5 (Follow hlint suggestion: use fewer imports)
- --ignore-glob=cabal-testsuite/PackageTests/CmmSources/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/CmmSourcesDyn/src/Demo.hs
- --ignore-glob=cabal-testsuite/PackageTests/CmmSourcesExe/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 @@ -125,24 +125,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 DeriveDataTypeable #-}
{-# LANGUAGE DeriveFunctor #-}
Expand Down Expand Up @@ -100,7 +99,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 @@ -220,7 +230,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
17 changes: 17 additions & 0 deletions cabal-install/tests/IntegrationTests2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ import qualified Distribution.Client.CmdBench as CmdBench
import qualified Distribution.Client.CmdHaddock as CmdHaddock
import qualified Distribution.Client.CmdListBin as CmdListBin

<<<<<<< HEAD
=======
import qualified Distribution.Client.CmdHaddockProject as CmdHaddockProject
import Distribution.Client.Config (SavedConfig (savedGlobalFlags), createDefaultConfigFile, loadConfig)
import Distribution.Client.GlobalFlags
( GlobalFlags
, defaultGlobalFlags
, globalNix
)
import Distribution.Client.Setup (globalCommand, globalStoreDir)
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
import Distribution.ModuleName (ModuleName)
>>>>>>> 217f08ac5 (Follow hlint suggestion: use fewer imports)
import Distribution.Package
import Distribution.PackageDescription
import Distribution.InstalledPackageInfo (InstalledPackageInfo)
Expand Down Expand Up @@ -83,7 +96,11 @@ import Test.Tasty.Options
import Data.Tagged (Tagged(..))

import qualified Data.ByteString as BS
<<<<<<< HEAD
import Distribution.Client.GlobalFlags (GlobalFlags, globalNix)
=======
import Data.Maybe (fromJust)
>>>>>>> 217f08ac5 (Follow hlint suggestion: use fewer imports)
import Distribution.Simple.Flag (Flag (Flag, NoFlag))
import Distribution.Types.ParStrat
import Data.Maybe (fromJust)
Expand Down
Loading

0 comments on commit 9cac543

Please sign in to comment.