diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..744b7987 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Linting + +on: + pull_request: + push: + branches: + - master + +jobs: + style: + name: Linting + runs-on: ubuntu-latest + steps: + - name: Clone project + uses: actions/checkout@v4 + - name: Apply yamllint + uses: ibiqlik/action-yamllint@v3 + with: + format: github + - name: Set up HLint + uses: haskell-actions/hlint-setup@v2 + with: + version: "3.6.1" + - name: Apply HLint + run: | + set -ex + hlint app/test-pretty-exceptions + hlint int/ + hlint src/ + hlint test/ diff --git a/.hlint.yaml b/.hlint.yaml new file mode 100644 index 00000000..ee70d74f --- /dev/null +++ b/.hlint.yaml @@ -0,0 +1,9 @@ +# Not considered useful hints +- ignore: + name: "Use camelCase" + within: + - System.Terminal +- ignore: + name: "Use fewer imports" + within: + - Pantry.Types diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 00000000..b39b13c4 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,14 @@ +# Configuration file for yamllint +extends: default +rules: + comments: + min-spaces-from-content: 1 + document-start: disable + indentation: + spaces: 2 + indent-sequences: false + line-length: disable + new-lines: + type: platform + truthy: + check-keys: false diff --git a/app/test-pretty-exceptions/Main.hs b/app/test-pretty-exceptions/Main.hs index 1ec89596..a89cb038 100644 --- a/app/test-pretty-exceptions/Main.hs +++ b/app/test-pretty-exceptions/Main.hs @@ -258,16 +258,15 @@ treeKeyExample :: TreeKey treeKeyExample = TreeKey blobKeyExample rawPackageLocationImmutableExamples :: [RawPackageLocationImmutable] -rawPackageLocationImmutableExamples = concat - [ [ RPLIHackage packageIdentifierRevision treeKey - | packageIdentifierRevision <- packageIdentifierRevisionExamples - , treeKey <- [Nothing, Just treeKeyExample] - ] +rawPackageLocationImmutableExamples = + [ RPLIHackage packageIdentifierRevision treeKey + | packageIdentifierRevision <- packageIdentifierRevisionExamples + , treeKey <- [Nothing, Just treeKeyExample] + ] --, RPLIArchive - , [ RPLIRepo repoExample rawPackageMetadata - | rawPackageMetadata <- rawPackageMetadataExamples - ] - ] + <> [ RPLIRepo repoExample rawPackageMetadata + | rawPackageMetadata <- rawPackageMetadataExamples + ] safeFilePathExamples :: [SafeFilePath] safeFilePathExamples = @@ -286,8 +285,8 @@ wantedCompilerExamples = , WCGhcjs versionExample versionExample ] -data ExceptionExample - = ExceptionExample !Text +newtype ExceptionExample + = ExceptionExample Text deriving (Show, Typeable) instance Exception ExceptionExample where @@ -400,7 +399,7 @@ packageNameExamples = duplicatePackageNamesExamples :: [(PackageName, [RawPackageLocationImmutable])] duplicatePackageNamesExamples = map - ((, rawPackageLocationImmutableExamples)) + (, rawPackageLocationImmutableExamples) packageNameExamples descriptionExample :: Text diff --git a/package.yaml b/package.yaml index ac86645a..cdeffa3d 100644 --- a/package.yaml +++ b/package.yaml @@ -1,13 +1,13 @@ -name: pantry -version: 0.9.2 -synopsis: Content addressable Haskell package management +name: pantry +version: 0.9.2 +synopsis: Content addressable Haskell package management description: Please see the README on GitHub at -category: Development -author: Michael Snoyman -maintainer: michael@snoyman.com -copyright: 2018-2022 FP Complete -license: BSD3 -github: commercialhaskell/pantry +category: Development +author: Michael Snoyman +maintainer: michael@snoyman.com +copyright: 2018-2022 FP Complete +license: BSD3 +github: commercialhaskell/pantry extra-source-files: - README.md @@ -79,9 +79,9 @@ when: dependencies: network >= 3.1.2.9 ghc-options: - - -fwrite-ide-info - - -hiedir=.hie - - -Wall +- -fwrite-ide-info +- -hiedir=.hie +- -Wall # For testing internal-libraries: diff --git a/test/Pantry/BuildPlanSpec.hs b/test/Pantry/BuildPlanSpec.hs index 1050265f..5c43abb1 100644 --- a/test/Pantry/BuildPlanSpec.hs +++ b/test/Pantry/BuildPlanSpec.hs @@ -3,10 +3,8 @@ module Pantry.BuildPlanSpec where -import Control.Monad.Catch ( MonadThrow ) import Data.Aeson.WarningParser ( WithJSONWarnings(..) ) import qualified Data.ByteString.Char8 as S8 -import Data.List.NonEmpty ( NonEmpty ) import Data.Yaml ( decodeThrow ) import Pantry import RIO diff --git a/test/Pantry/CabalSpec.hs b/test/Pantry/CabalSpec.hs index b52c6a3c..fd6963f3 100644 --- a/test/Pantry/CabalSpec.hs +++ b/test/Pantry/CabalSpec.hs @@ -1,4 +1,5 @@ {-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} module Pantry.CabalSpec @@ -32,8 +33,7 @@ spec = describe "wrong cabal file" $ do version2 = mkVersion [0, 2] version3 = mkVersion [0, 3] size = FileSize 597 - go `shouldThrow'` \e -> - case e of + go `shouldThrow'` \case MismatchedPackageMetadata rpli' rpm _tree ident -> rpli == rpli' && rpm == RawPackageMetadata @@ -64,8 +64,7 @@ spec = describe "wrong cabal file" $ do go = loadCabalFileRawImmutable rpli acmeMissiles = mkPackageName "acme-missiles" version2 = mkVersion [0, 2] - go `shouldThrow'` \e -> - case e of + go `shouldThrow'` \case MismatchedPackageMetadata rpli' rpm' _treeKey ident -> rpli == rpli' && rpm == rpm' && @@ -94,8 +93,7 @@ spec = describe "wrong cabal file" $ do yesodAuth = mkPackageName "yesod-auth" version = mkVersion [1, 6, 4, 1] badVersion = mkVersion [1, 6, 4, 0] - go `shouldThrow'` \e -> - case e of + go `shouldThrow'` \case MismatchedPackageMetadata rpli' rpm' _treeKey ident -> rpli == rpli' && rpm == rpm' && diff --git a/test/Pantry/CasaSpec.hs b/test/Pantry/CasaSpec.hs index bc8e758f..3789833f 100644 --- a/test/Pantry/CasaSpec.hs +++ b/test/Pantry/CasaSpec.hs @@ -66,11 +66,11 @@ data Args = unliftio_0_2_12 :: Args unliftio_0_2_12 = - let cabalHash = (either + let cabalHash = either (error . show) id (fromHexText - "b089fbc2ff2628a963c2c4b12143f2020874e3e5144ffd6c62b25639a0ca1483")) + "b089fbc2ff2628a963c2c4b12143f2020874e3e5144ffd6c62b25639a0ca1483") cabalLen = FileSize 3325 cabalFileHash = CFIHash diff --git a/test/Pantry/HackageSpec.hs b/test/Pantry/HackageSpec.hs index a9fec45d..533c2c2c 100644 --- a/test/Pantry/HackageSpec.hs +++ b/test/Pantry/HackageSpec.hs @@ -1,4 +1,5 @@ {-# LANGUAGE NoImplicitPrelude #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} module Pantry.HackageSpec @@ -16,8 +17,7 @@ spec = do it "fuzzy lookup kicks in" $ do let pir = PackageIdentifierRevision "thisisnot-tobe-foundon-hackage-please" (mkVersion [1..3]) CFILatest runPantryApp (loadPackageRaw (RPLIHackage pir Nothing)) - `shouldThrow` \e -> - case e of + `shouldThrow` \case UnknownHackagePackage pir' _ -> pir == pir' _ -> False -- Flaky test, can be broken by new packages on Hackage. diff --git a/test/Pantry/TypesSpec.hs b/test/Pantry/TypesSpec.hs index e2195ca8..c9227876 100644 --- a/test/Pantry/TypesSpec.hs +++ b/test/Pantry/TypesSpec.hs @@ -34,7 +34,7 @@ hh name p = it name $ do unless result $ throwString "Hedgehog property failed" :: IO () genBlobKey :: Gen BlobKey -genBlobKey = BlobKey <$> genSha256 <*> (FileSize <$> (Gen.word (Range.linear 1 10000))) +genBlobKey = BlobKey <$> genSha256 <*> (FileSize <$> Gen.word (Range.linear 1 10000)) genSha256 :: Gen SHA256 genSha256 = SHA256.hashBytes <$> Gen.bytes (Range.linear 1 500) @@ -109,13 +109,13 @@ spec = do RawSnapshotLayer{..} <- parseSl $ "name: 'test'\n" ++ "resolver: lts-2.10\n" - rslParent `shouldBe` (RSLSynonym $ LTS 2 10) + rslParent `shouldBe` RSLSynonym (LTS 2 10) it "parses snapshot using 'snapshot'" $ do RawSnapshotLayer{..} <- parseSl $ "name: 'test'\n" ++ "snapshot: lts-2.10\n" - rslParent `shouldBe` (RSLSynonym $ LTS 2 10) + rslParent `shouldBe` RSLSynonym (LTS 2 10) it "throws if both 'resolver' and 'snapshot' are present" $ do let go = parseSl $ @@ -190,7 +190,7 @@ spec = do Right sha' -> pure sha' _ -> fail "parseHackagetext: failed decoding the sha256" let Right (pkgIdentifier, blobKey) = parseHackageText txt - blobKey `shouldBe` (BlobKey sha (FileSize 5058)) + blobKey `shouldBe` BlobKey sha (FileSize 5058) pkgIdentifier `shouldBe` PackageIdentifier (mkPackageName "persistent")