From afdc9d8d145d29803b2c472c0224ab2b184b78c1 Mon Sep 17 00:00:00 2001 From: drlkf Date: Tue, 20 Oct 2026 22:06:01 +0200 Subject: [PATCH] build: add more compile-time checks --- .github/workflows/stack.yml | 27 ++++++++++++++++++- .hlint.yaml | 2 ++ AGENTS.md | 18 +++++++++++++ .../test/Effectful/Cache/OpenTelemetrySpec.hs | 4 +-- fourmolu.yaml | 16 +++++++++++ 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 .hlint.yaml create mode 100644 AGENTS.md create mode 100644 fourmolu.yaml diff --git a/.github/workflows/stack.yml b/.github/workflows/stack.yml index 61b976c..207b1f1 100644 --- a/.github/workflows/stack.yml +++ b/.github/workflows/stack.yml @@ -14,6 +14,31 @@ jobs: - id: matrix uses: freckle/stack-action/generate-matrix@v5 + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: haskell-actions/hlint-setup@v2 + with: + version: "3.10" + + - uses: haskell-actions/hlint-run@v2 + with: + path: '["src/", "test/", "effectful-data-cache-opentelemetry/src/", "effectful-data-cache-opentelemetry/test/"]' + fail-on: warning + + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: haskell-actions/run-fourmolu@v13 + with: + version: "0.21.0.0" + pattern: | + src/**/*.hs + test/**/*.hs + effectful-data-cache-opentelemetry/src/**/*.hs + effectful-data-cache-opentelemetry/test/**/*.hs build: needs: generate-matrix @@ -21,7 +46,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-15] stack-yaml: ${{ fromJSON(needs.generate-matrix.outputs.stack-yamls) }} steps: - uses: actions/checkout@v6 diff --git a/.hlint.yaml b/.hlint.yaml new file mode 100644 index 0000000..eb6982f --- /dev/null +++ b/.hlint.yaml @@ -0,0 +1,2 @@ +- warn: {lhs: map, rhs: fmap, name: Use fmap} +- warn: {lhs: a ++ b, rhs: a <> b, name: Use <>} diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..55ce694 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,18 @@ +# AGENTS + +Haskell library (stack + hpack). Edit `package.yaml`, never generated `.cabal`. + +## Commands + +- build and test (GHC 9.10): `stack build --test --ghc-options=-Werror` +- format: `fourmolu -i src test effectful-data-cache-opentelemetry/{src,test}` (fourmolu 0.21.0.0, config in `fourmolu.yaml`) +- lint: `hlint src test effectful-data-cache-opentelemetry/{src,test}` (rules in `.hlint.yaml`; HLS has no hlint plugin on GHC 9.10) + +CI (`.github/workflows/stack.yml`) runs all of the above; keep it green. + +## Style + +- `fmap` over `map`, `<>` over `++` (enforced by hlint) +- curried constraints: `Read a => Ord a => a`, not `(Read a, Ord a) => a`; + not enforced by tooling +- `-Wredundant-constraints` on: only add `Show e` for `throwError` where needed diff --git a/effectful-data-cache-opentelemetry/test/Effectful/Cache/OpenTelemetrySpec.hs b/effectful-data-cache-opentelemetry/test/Effectful/Cache/OpenTelemetrySpec.hs index 1a1cd5f..0f5fea7 100644 --- a/effectful-data-cache-opentelemetry/test/Effectful/Cache/OpenTelemetrySpec.hs +++ b/effectful-data-cache-opentelemetry/test/Effectful/Cache/OpenTelemetrySpec.hs @@ -40,7 +40,7 @@ attr :: ImmutableSpan -> Text -> Maybe Attribute -attr s k = lookupAttribute (spanAttributes s) k +attr s = lookupAttribute (spanAttributes s) spec :: Spec spec = do @@ -49,7 +49,7 @@ spec = do insert @String @Int "a" (1 :: Int) _ <- lookup @String @Int "a" purge @String @Int - map spanName spans `shouldBe` ["cache.insert", "cache.lookup", "cache.purge"] + fmap spanName spans `shouldBe` ["cache.insert", "cache.lookup", "cache.purge"] it "records hits and misses" $ do (_, spans) <- traced $ do diff --git a/fourmolu.yaml b/fourmolu.yaml new file mode 100644 index 0000000..b6a9652 --- /dev/null +++ b/fourmolu.yaml @@ -0,0 +1,16 @@ +--- +column-limit: 90 +comma-style: leading +function-arrows: leading +haddock-style: single-line +haddock-style-module: single-line +import-export-style: diff-friendly +indentation: 2 +let-style: inline +respectful: false +single-constraint-parens: never +single-deriving-parens: never +sort-constraints: true +sort-derived-classes: true +sort-deriving-clauses: true +...