From 3e96aaa42ef1feb2d6b34cf99b00e27a8cb02c36 Mon Sep 17 00:00:00 2001 From: Alexander Kobjolke Date: Sat, 19 Aug 2023 00:33:36 +0200 Subject: [PATCH 1/4] Set indentation for fourmolu --- fourmolu.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/fourmolu.yaml b/fourmolu.yaml index 9f360f9..d8c5559 100644 --- a/fourmolu.yaml +++ b/fourmolu.yaml @@ -1 +1,2 @@ haddock-style: single-line +indentation: 2 From da3b61b467a4f72cc216be0af90b50deb5835ee4 Mon Sep 17 00:00:00 2001 From: Alexander Kobjolke Date: Sat, 19 Aug 2023 00:34:40 +0200 Subject: [PATCH 2/4] Update cabal file --- hcat.cabal | 5 +---- package.yaml | 3 ++- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/hcat.cabal b/hcat.cabal index 5a28798..16dadb2 100644 --- a/hcat.cabal +++ b/hcat.cabal @@ -24,7 +24,6 @@ library hs-source-dirs: src default-extensions: - GHC2021 BlockArguments OverloadedStrings ghc-options: -Wall -Wunused-packages -fdefer-typed-holes @@ -40,7 +39,6 @@ executable hcat hs-source-dirs: app default-extensions: - GHC2021 BlockArguments OverloadedStrings ghc-options: -Wall -Wunused-packages -fdefer-typed-holes @@ -59,7 +57,6 @@ test-suite spec hs-source-dirs: test default-extensions: - GHC2021 BlockArguments OverloadedStrings ghc-options: -Wall -Wunused-packages -fdefer-typed-holes @@ -74,4 +71,4 @@ test-suite spec , quickcheck-instances , quickcheck-text , text - default-language: Haskell2010 + default-language: GHC2021 diff --git a/package.yaml b/package.yaml index cbf8e8f..d0dfbea 100644 --- a/package.yaml +++ b/package.yaml @@ -23,7 +23,6 @@ ghc-options: - -fdefer-typed-holes default-extensions: - - GHC2021 - BlockArguments - OverloadedStrings @@ -54,3 +53,5 @@ tests: - quickcheck-instances - quickcheck-text build-tools: hspec-discover + verbatim: + default-language: GHC2021 From 7a69fb2363a10a34e5456eb570570c65ce066284 Mon Sep 17 00:00:00 2001 From: Alexander Kobjolke Date: Sat, 19 Aug 2023 01:10:47 +0200 Subject: [PATCH 3/4] Make 'nix flake check' work --- flake.nix | 15 +++++++++------ hcat.cabal | 3 +++ package.yaml | 1 + src/HCat.hs | 12 ++++++------ src/HCat/Internal.hs | 14 +++++++------- test/HCatSpec.hs | 2 +- 6 files changed, 27 insertions(+), 20 deletions(-) diff --git a/flake.nix b/flake.nix index 3c4be74..dc5d57e 100644 --- a/flake.nix +++ b/flake.nix @@ -11,7 +11,7 @@ }; outputs = { self, nixpkgs, flake-utils, pre-commit-hooks }: - flake-utils.lib.eachDefaultSystem (system: + flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: let pkgs = nixpkgs.legacyPackages.${system}; @@ -27,13 +27,13 @@ # Dependency overrides go here }; - defaultPackage = self.packages.${system}.${packageName}; + packages.default = self.packages.${system}.${packageName}; apps = { # run with: nix run #.hcat hcat = { type = "app"; - program = "${self.defaultPackage.${system}}/bin/hcat"; + program = "${self.packages.${system}.default}/bin/hcat"; }; # run with: nix run @@ -43,6 +43,8 @@ checks = { pre-commit-check = pre-commit-hooks.lib.${system}.run { src = ./.; + settings = { ormolu.defaultExtensions = [ "GHC2021" ]; }; + tools.fourmolu = haskellPackages.fourmolu; hooks = { nixfmt.enable = true; fourmolu.enable = true; @@ -51,17 +53,18 @@ doctest = { enable = true; name = "Run documentation tests"; - entry = "doctest"; + entry = "${haskellPackages.doctest}/bin/doctest src app"; files = "\\.l?hs$"; + pass_filenames = false; }; }; }; }; - devShell = haskellPackages.shellFor { + devShells.default = haskellPackages.shellFor { inherit (self.checks.${system}.pre-commit-check) shellHook; - packages = p: [ self.defaultPackage.${system} ]; + packages = p: [ self.packages.${system}.default ]; withHoogle = true; diff --git a/hcat.cabal b/hcat.cabal index 16dadb2..fecf793 100644 --- a/hcat.cabal +++ b/hcat.cabal @@ -26,6 +26,7 @@ library default-extensions: BlockArguments OverloadedStrings + ImportQualifiedPost ghc-options: -Wall -Wunused-packages -fdefer-typed-holes build-depends: base >=4.13 && <5 @@ -41,6 +42,7 @@ executable hcat default-extensions: BlockArguments OverloadedStrings + ImportQualifiedPost ghc-options: -Wall -Wunused-packages -fdefer-typed-holes build-depends: base >=4.13 && <5 @@ -59,6 +61,7 @@ test-suite spec default-extensions: BlockArguments OverloadedStrings + ImportQualifiedPost ghc-options: -Wall -Wunused-packages -fdefer-typed-holes cpp-options: -DTEST build-tool-depends: diff --git a/package.yaml b/package.yaml index d0dfbea..4ddf9af 100644 --- a/package.yaml +++ b/package.yaml @@ -25,6 +25,7 @@ ghc-options: default-extensions: - BlockArguments - OverloadedStrings + - ImportQualifiedPost library: source-dirs: src diff --git a/src/HCat.hs b/src/HCat.hs index bdf9251..fa93ec5 100644 --- a/src/HCat.hs +++ b/src/HCat.hs @@ -1,6 +1,6 @@ module HCat ( - runHCat, - defaultMain, + runHCat, + defaultMain, ) where import System.Environment qualified as Env @@ -15,16 +15,16 @@ import HCat.Internal (parseArgs) runHCat :: IO () runHCat = do - fileNameOrError <- parseArgs <$> Env.getArgs - fileName <- eitherToError fileNameOrError - TextIO.readFile fileName >>= TextIO.putStr + fileNameOrError <- parseArgs <$> Env.getArgs + fileName <- eitherToError fileNameOrError + TextIO.readFile fileName >>= TextIO.putStr eitherToError :: Show a => Either a b -> IO b eitherToError = either (Exception.throwIO . IOError.userError . show) return handleError :: IOError -> IO () handleError e = do - hPutStrLn stderr $ "I ran into an issue: " <> show e + hPutStrLn stderr $ "I ran into an issue: " <> show e defaultMain :: IO () defaultMain = Exception.catch runHCat handleError diff --git a/src/HCat/Internal.hs b/src/HCat/Internal.hs index c0ec415..69f0493 100644 --- a/src/HCat/Internal.hs +++ b/src/HCat/Internal.hs @@ -7,9 +7,9 @@ module HCat.Internal where -- Right "foo" parseArgs :: [String] -> Either String FilePath parseArgs args = case args of - [] -> Left "No filename given!" - [arg] -> Right arg - _ -> Left "Only a single file is supported" + [] -> Left "No filename given!" + [arg] -> Right arg + _ -> Left "Only a single file is supported" -- | @chunksOf n@ splits a list into chunks of at most @n@ items. -- @@ -24,7 +24,7 @@ parseArgs args = case args of chunksOf :: Int -> [a] -> [[a]] chunksOf _ [] = [] chunksOf n xs@(_ : _) - | n <= 0 = [] - | otherwise = - let (chunk, rest) = splitAt n xs - in chunk : chunksOf n rest + | n <= 0 = [] + | otherwise = + let (chunk, rest) = splitAt n xs + in chunk : chunksOf n rest diff --git a/test/HCatSpec.hs b/test/HCatSpec.hs index 6862706..0054f16 100644 --- a/test/HCatSpec.hs +++ b/test/HCatSpec.hs @@ -1,4 +1,4 @@ -{-# LANGUAGE GHC2021 #-} +-- {-# LANGUAGE GHC2021 #-} module HCatSpec (spec) where From 30132088dfd495c651c693e9452495e93a91928b Mon Sep 17 00:00:00 2001 From: Alexander Kobjolke Date: Mon, 21 Aug 2023 06:34:21 +0200 Subject: [PATCH 4/4] flake: Disable doctest for now as it won't run during flake check correctly --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index dc5d57e..fa5d34f 100644 --- a/flake.nix +++ b/flake.nix @@ -51,7 +51,7 @@ hpack.enable = true; hlint.enable = true; doctest = { - enable = true; + enable = false; name = "Run documentation tests"; entry = "${haskellPackages.doctest}/bin/doctest src app"; files = "\\.l?hs$";