From 52dc14a4f6ea05c628f1415d59c2705682e5242d Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 4 Oct 2024 16:27:18 -0700 Subject: [PATCH 01/11] Revert format-more except Makefile --- Makefile | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 639a6a82d2d..2f27bceea2b 100644 --- a/Makefile +++ b/Makefile @@ -27,18 +27,40 @@ init: ## Set up git hooks and ignored revisions. @git config core.hooksPath .githooks ## TODO +# NOTE: Keep this in sync with `.github/workflows/format.yml`. +FORMAT_DIRS := \ + bootstrap \ + buildinfo-reference-generator \ + Cabal \ + Cabal-benchmarks \ + Cabal-described \ + Cabal-dev-scripts \ + Cabal-hooks \ + cabal-install \ + cabal-install-solver \ + Cabal-QuickCheck \ + Cabal-syntax \ + Cabal-tests \ + Cabal-testsuite/src \ + Cabal-testsuite/main \ + Cabal-testsuite/static \ + Cabal-tree-diff \ + cabal-validate \ + solver-benchmarks + + .PHONY: style -style: ## Run the code styler. - @fourmolu -q -i Cabal Cabal-syntax cabal-install cabal-validate +style: ## Run the code styler + @fourmolu -q -i $(FORMAT_DIRS) .PHONY: style-modified -style-modified: ## Run the code styler on modified files. - @git ls-files --modified Cabal Cabal-syntax cabal-install cabal-validate \ +style-modified: ## Run the code styler on modified files + @git ls-files --modified $(FORMAT_DIRS) \ | grep '.hs$$' | xargs -P $(PROCS) -I {} fourmolu -q -i {} .PHONY: style-commit -style-commit: ## Run the code styler on the previous commit. - @git diff --name-only HEAD $(COMMIT) Cabal Cabal-syntax cabal-install cabal-validate \ +style-commit: ## Run the code styler on the previous commit + @git diff --name-only HEAD $(COMMIT) -- $(FORMAT_DIRS) \ | grep '.hs$$' | xargs -P $(PROCS) -I {} fourmolu -q -i {} .PHONY: whitespace From 5f66c8414a6da773225fa7643fe5859ac973090d Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 27 Dec 2024 09:45:53 -0500 Subject: [PATCH 02/11] Properly case and sort FORMAT_DIRS --- Makefile | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 2f27bceea2b..59f20026dc3 100644 --- a/Makefile +++ b/Makefile @@ -29,26 +29,25 @@ init: ## Set up git hooks and ignored revisions. # NOTE: Keep this in sync with `.github/workflows/format.yml`. FORMAT_DIRS := \ - bootstrap \ - buildinfo-reference-generator \ Cabal \ - Cabal-benchmarks \ + Cabal-QuickCheck \ Cabal-described \ - Cabal-dev-scripts \ Cabal-hooks \ - cabal-install \ - cabal-install-solver \ - Cabal-QuickCheck \ Cabal-syntax \ Cabal-tests \ - Cabal-testsuite/src \ - Cabal-testsuite/main \ - Cabal-testsuite/static \ Cabal-tree-diff \ + bootstrap \ + buildinfo-reference-generator \ + cabal-benchmarks \ + cabal-dev-scripts \ + cabal-install \ + cabal-install-solver \ + cabal-testsuite/main \ + cabal-testsuite/src \ + cabal-testsuite/static \ cabal-validate \ solver-benchmarks - .PHONY: style style: ## Run the code styler @fourmolu -q -i $(FORMAT_DIRS) From c095c54381a80d6b492ee9bfbf692436986b3548 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 27 Dec 2024 10:02:46 -0500 Subject: [PATCH 03/11] Split FORMAT_DIRS & FORMAT_DIRS_TODO --- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 59f20026dc3..216cc88c66a 100644 --- a/Makefile +++ b/Makefile @@ -30,24 +30,30 @@ init: ## Set up git hooks and ignored revisions. # NOTE: Keep this in sync with `.github/workflows/format.yml`. FORMAT_DIRS := \ Cabal \ + Cabal-syntax \ + cabal-install \ + cabal-validate + +FORMAT_DIRS_TODO := \ Cabal-QuickCheck \ Cabal-described \ Cabal-hooks \ - Cabal-syntax \ Cabal-tests \ Cabal-tree-diff \ bootstrap \ buildinfo-reference-generator \ cabal-benchmarks \ cabal-dev-scripts \ - cabal-install \ cabal-install-solver \ cabal-testsuite/main \ cabal-testsuite/src \ cabal-testsuite/static \ - cabal-validate \ solver-benchmarks +.PHONY: style-todo +style-todo: ## Configured for fourmolu, avoiding GHC parser failures + @fourmolu -q $(FORMAT_DIRS_TODO) > /dev/null + .PHONY: style style: ## Run the code styler @fourmolu -q -i $(FORMAT_DIRS) From bc7680479a6ac7069b4256d72f11c4b41726fca1 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 27 Dec 2024 10:15:41 -0500 Subject: [PATCH 04/11] FOURMOLU_DISABLE Utils.CharSet --- Cabal-described/src/Distribution/Utils/CharSet.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cabal-described/src/Distribution/Utils/CharSet.hs b/Cabal-described/src/Distribution/Utils/CharSet.hs index 9243615c7fa..93767907ef0 100644 --- a/Cabal-described/src/Distribution/Utils/CharSet.hs +++ b/Cabal-described/src/Distribution/Utils/CharSet.hs @@ -113,7 +113,9 @@ member c (CS m) = go (IM.toList m) i = ord c -- | Insert 'Char' into 'CharSet'. +{- FOURMOLU_DISABLE -} insert :: Char -> CharSet -> CharSet +{- FOURMOLU_ENABLE -} insert c (CS m) = normalise (IM.insert (ord c) (ord c) m) -- | Union of two 'CharSet's. From 197beaa47e712052e308e955c519325ff18465ce Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 27 Dec 2024 10:16:12 -0500 Subject: [PATCH 05/11] FOURMOLU_DISABLE HackageTests --- Cabal-tests/tests/HackageTests.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cabal-tests/tests/HackageTests.hs b/Cabal-tests/tests/HackageTests.hs index e400e73629d..57a777b128a 100644 --- a/Cabal-tests/tests/HackageTests.hs +++ b/Cabal-tests/tests/HackageTests.hs @@ -301,6 +301,7 @@ roundtripTest testFieldsTransform fpath bs = do putStrLn bs' exitFailure +{- FOURMOLU_DISABLE -} parse phase c = do let (_, x') = Parsec.runParseResult $ Parsec.parseGenericPackageDescription c @@ -311,6 +312,7 @@ roundtripTest testFieldsTransform fpath bs = do traverse_ print errs B.putStr c fail "parse error" +{- FOURMOLU_ENABLE -} ------------------------------------------------------------------------------- -- Main From a5352518ae826a8a1eb992ffbf6f09bff6aeefe1 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 27 Dec 2024 10:21:03 -0500 Subject: [PATCH 06/11] FOURMOLU_DISABLE ParserTests --- Cabal-tests/tests/ParserTests.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cabal-tests/tests/ParserTests.hs b/Cabal-tests/tests/ParserTests.hs index 3a87df99481..3990f19fc79 100644 --- a/Cabal-tests/tests/ParserTests.hs +++ b/Cabal-tests/tests/ParserTests.hs @@ -200,12 +200,14 @@ regressionTests = testGroup "regressions" regressionTest :: FilePath -> TestTree regressionTest fp = testGroup fp +{- FOURMOLU_DISABLE -} [ formatGoldenTest fp , formatRoundTripTest fp #ifdef MIN_VERSION_tree_diff , treeDiffGoldenTest fp #endif ] +{- FOURMOLU_ENABLE -} formatGoldenTest :: FilePath -> TestTree formatGoldenTest fp = cabalGoldenTest "format" correct $ do @@ -248,6 +250,7 @@ formatRoundTripTest fp = testCase "roundtrip" $ do y <- parse (toUTF8BS contents') -- previously we mangled licenses a bit let y' = y +{- FOURMOLU_DISABLE -} unless (x == y') $ #ifdef MIN_VERSION_tree_diff assertFailure $ unlines @@ -273,6 +276,7 @@ formatRoundTripTest fp = testCase "roundtrip" $ do void $ assertFailure $ unlines (map (showPError fp) $ NE.toList errs) fail "failure" input = "tests" "ParserTests" "regressions" fp +{- FOURMOLU_ENABLE -} ------------------------------------------------------------------------------- -- InstalledPackageInfo regressions @@ -287,6 +291,7 @@ ipiTests = testGroup "ipis" ] ipiTest :: FilePath -> TestTree +{- FOURMOLU_DISABLE -} ipiTest fp = testGroup fp $ #ifdef MIN_VERSION_tree_diff [ ipiTreeDiffGoldenTest fp ] ++ @@ -294,6 +299,7 @@ ipiTest fp = testGroup fp $ [ ipiFormatGoldenTest fp , ipiFormatRoundTripTest fp ] +{- FOURMOLU_ENABLE -} ipiFormatGoldenTest :: FilePath -> TestTree ipiFormatGoldenTest fp = cabalGoldenTest "format" correct $ do From f73f9f68f15a4b95052f863ec288c91af38386c1 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 27 Dec 2024 10:28:00 -0500 Subject: [PATCH 07/11] FOURMOLU_DISABLE CabalDoctestSetup --- Cabal-tests/tests/custom-setup/CabalDoctestSetup.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Cabal-tests/tests/custom-setup/CabalDoctestSetup.hs b/Cabal-tests/tests/custom-setup/CabalDoctestSetup.hs index a6a59c144c9..fc2268bad56 100644 --- a/Cabal-tests/tests/custom-setup/CabalDoctestSetup.hs +++ b/Cabal-tests/tests/custom-setup/CabalDoctestSetup.hs @@ -283,6 +283,7 @@ addDoctestsUserHook testsuiteName uh = uh -- | Convert only flags used by 'generateBuildModule'. haddockToBuildFlags :: HaddockFlags -> BuildFlags +{- FOURMOLU_DISABLE -} haddockToBuildFlags f = #if MIN_VERSION_Cabal(3,11,0) emptyBuildFlags @@ -293,6 +294,7 @@ haddockToBuildFlags f = , buildDistPref = haddockDistPref f } #endif +{- FOURMOLU_ENABLE -} data Name = NameLib (Maybe String) | NameExe String deriving (Eq, Show) @@ -331,6 +333,7 @@ data Component = Component Name [String] [String] [String] generateBuildModule :: String -- ^ doctests test-suite name -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO () +{- FOURMOLU_DISABLE -} generateBuildModule testSuiteName flags pkg lbi = do let verbosity = fromFlag (buildVerbosity flags) let distPref = fromFlag (buildDistPref flags) @@ -581,6 +584,7 @@ generateBuildModule testSuiteName flags pkg lbi = do #else executableName = exeName #endif +{- FOURMOLU_ENABLE -} -- | In compat settings it's better to omit the type-signature testDeps :: ComponentLocalBuildInfo -> ComponentLocalBuildInfo From a706a36c49464be61e06feaa89bcb7d886d007f4 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 27 Dec 2024 10:30:39 -0500 Subject: [PATCH 08/11] FOURMOLU_DISABLE IdrisSetup --- Cabal-tests/tests/custom-setup/IdrisSetup.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cabal-tests/tests/custom-setup/IdrisSetup.hs b/Cabal-tests/tests/custom-setup/IdrisSetup.hs index 339f9fd9c38..149f03706fa 100644 --- a/Cabal-tests/tests/custom-setup/IdrisSetup.hs +++ b/Cabal-tests/tests/custom-setup/IdrisSetup.hs @@ -92,12 +92,14 @@ idrisCmd local = Px.joinPath $ splitDirectories $ ".." Px. ".." Px. bd Px. #else idrisCmd local = ".." ".." bd "idris" "idris" #endif +{- FOURMOLU_DISABLE -} where bd = #if MIN_VERSION_Cabal(3,11,0) getSymbolicPath $ #endif buildDir local +{- FOURMOLU_ENABLE -} -- ----------------------------------------------------------------------------- -- Make Commands @@ -223,6 +225,7 @@ generateToolchainModule verbosity srcDir toolDir = do createDirectoryIfMissingVerbose verbosity True srcDir rewriteFileEx verbosity toolPath (commonContent ++ toolContent) +{- FOURMOLU_DISABLE -} idrisConfigure _ flags pkgdesc local = do configureRTS withLibLBI pkgdesc local $ \_ libcfg -> do @@ -256,6 +259,7 @@ idrisConfigure _ flags pkgdesc local = do #if !(MIN_VERSION_Cabal(2,0,0)) autogenComponentModulesDir lbi _ = autogenModulesDir lbi #endif +{- FOURMOLU_ENABLE -} #if !MIN_VERSION_Cabal(3,0,0) idrisPreSDist args flags = do @@ -372,6 +376,7 @@ idrisInstall verbosity copy pkg local -- We want it to be the install directory where we put the idris libraries. fixPkg pkg target = pkg { dataDir = target } +{- FOURMOLU_DISABLE -} idrisTestHook args pkg local hooks flags = do let target = #if MIN_VERSION_Cabal(3,11,0) @@ -403,3 +408,4 @@ main = defaultMainWithHooks $ simpleUserHooks #endif , testHook = idrisTestHook } +{- FOURMOLU_ENABLE -} From 6b78a1332641bae9760f82614a4144318728cdcc Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 27 Dec 2024 12:01:10 -0500 Subject: [PATCH 09/11] FOURMOLU_DISABLE Modular.Solver --- cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs b/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs index b57f55af1fc..58045b56814 100644 --- a/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs +++ b/cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs @@ -171,6 +171,7 @@ solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals = -- -- This only does something if the @debug-tracetree@ configure argument was -- given; otherwise this is just the identity function. +{- FOURMOLU_DISABLE -} traceTree :: #ifdef DEBUG_TRACETREE GSimpleTree a => @@ -183,6 +184,7 @@ traceTree = gtraceJson #else traceTree _ _ = id #endif +{- FOURMOLU_ENABLE -} #ifdef DEBUG_TRACETREE instance GSimpleTree (Tree d c) where From 92c1893f245878c027fda361d4cfd96c6fd9bf0f Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 27 Dec 2024 12:02:57 -0500 Subject: [PATCH 10/11] FOURMOLU_DISABLE Test.Cabal.Server --- cabal-testsuite/src/Test/Cabal/Server.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cabal-testsuite/src/Test/Cabal/Server.hs b/cabal-testsuite/src/Test/Cabal/Server.hs index d7022ed9563..85c117139e3 100644 --- a/cabal-testsuite/src/Test/Cabal/Server.hs +++ b/cabal-testsuite/src/Test/Cabal/Server.hs @@ -253,6 +253,7 @@ startServer chan senv = do -- | Unmasked initialization for the server initServer :: Server -> IO Server +{- FOURMOLU_DISABLE -} initServer s0 = do -- NB: withProcessHandle reads an MVar and is interruptible @@ -275,6 +276,7 @@ initServer s0 = do write s ":set prompt \"\"" write s "System.IO.hSetBuffering System.IO.stdout System.IO.LineBuffering" return s +{- FOURMOLU_ENABLE -} -- | Stop a GHCi session. stopServer :: Server -> IO () From a28fbcfa180e84e11cda423ec6b9aa1d1db76d73 Mon Sep 17 00:00:00 2001 From: Phil de Joux Date: Fri, 27 Dec 2024 12:19:35 -0500 Subject: [PATCH 11/11] Avoid unnecessary diffs in make comments --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 216cc88c66a..7fdcec9f3c5 100644 --- a/Makefile +++ b/Makefile @@ -55,16 +55,16 @@ style-todo: ## Configured for fourmolu, avoiding GHC parser failures @fourmolu -q $(FORMAT_DIRS_TODO) > /dev/null .PHONY: style -style: ## Run the code styler +style: ## Run the code styler. @fourmolu -q -i $(FORMAT_DIRS) .PHONY: style-modified -style-modified: ## Run the code styler on modified files +style-modified: ## Run the code styler on modified files. @git ls-files --modified $(FORMAT_DIRS) \ | grep '.hs$$' | xargs -P $(PROCS) -I {} fourmolu -q -i {} .PHONY: style-commit -style-commit: ## Run the code styler on the previous commit +style-commit: ## Run the code styler on the previous commit. @git diff --name-only HEAD $(COMMIT) -- $(FORMAT_DIRS) \ | grep '.hs$$' | xargs -P $(PROCS) -I {} fourmolu -q -i {}