Skip to content

Commit

Permalink
Merge pull request #113 from commercialhaskell/lint
Browse files Browse the repository at this point in the history
Add HLint to CI
  • Loading branch information
mpilgrem authored Nov 1, 2023
2 parents 3ec3ba1 + 0d900a4 commit 711448a
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 40 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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/
9 changes: 9 additions & 0 deletions .hlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Not considered useful hints
- ignore:
name: "Use camelCase"
within:
- System.Terminal
- ignore:
name: "Use fewer imports"
within:
- Pantry.Types
14 changes: 14 additions & 0 deletions .yamllint.yaml
Original file line number Diff line number Diff line change
@@ -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
23 changes: 11 additions & 12 deletions app/test-pretty-exceptions/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -286,8 +285,8 @@ wantedCompilerExamples =
, WCGhcjs versionExample versionExample
]

data ExceptionExample
= ExceptionExample !Text
newtype ExceptionExample
= ExceptionExample Text
deriving (Show, Typeable)

instance Exception ExceptionExample where
Expand Down Expand Up @@ -400,7 +399,7 @@ packageNameExamples =

duplicatePackageNamesExamples :: [(PackageName, [RawPackageLocationImmutable])]
duplicatePackageNamesExamples = map
((, rawPackageLocationImmutableExamples))
(, rawPackageLocationImmutableExamples)
packageNameExamples

descriptionExample :: Text
Expand Down
24 changes: 12 additions & 12 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/commercialhaskell/pantry#readme>
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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions test/Pantry/BuildPlanSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions test/Pantry/CabalSpec.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Pantry.CabalSpec
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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' &&
Expand Down Expand Up @@ -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' &&
Expand Down
4 changes: 2 additions & 2 deletions test/Pantry/CasaSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/Pantry/HackageSpec.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Pantry.HackageSpec
Expand All @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions test/Pantry/TypesSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 $
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 711448a

Please sign in to comment.