From c45ea476fc3b3af99c08c8b77aa78c5782260bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tao=20Bojl=C3=A9n?= Date: Sat, 20 Jun 2026 11:55:36 +0100 Subject: [PATCH] ci: compile with --warnings-as-errors in hooks and CI Add a mix-compile pre-commit step (hk) and run the CI setup compile with --warnings-as-errors so compiler warnings block commits and fail the build. Fix the pre-existing LiveView 1.2 deprecation warning in website/components/component_doc.ex (EEx.compile_string with the deprecated TagEngine-as-EEx.Engine -> Phoenix.LiveView.TagEngine.compile/2) that otherwise made --warnings-as-errors fail out of the box. --- .tangled/workflows/ci.yml | 5 +++-- CLAUDE.md | 7 +++++-- hk.pkl | 9 +++++++++ website/components/component_doc.ex | 8 +++----- 4 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.tangled/workflows/ci.yml b/.tangled/workflows/ci.yml index 2131b5a..45d5251 100644 --- a/.tangled/workflows/ci.yml +++ b/.tangled/workflows/ci.yml @@ -36,7 +36,8 @@ steps: # Install the Elixir toolchain into the workspace and pre-compile, so the # later steps are quiet and just run their one check. The workspace (incl. # .elixir, deps/, _build/) persists across steps; PATH does not, so each - # Elixir step re-exports it. + # Elixir step re-exports it. The compile is run with --warnings-as-errors so + # any compiler warning fails the build here rather than slipping through. - name: "Setup (toolchain + deps)" command: | set -eu @@ -59,7 +60,7 @@ steps: mix local.hex --force mix local.rebar --force mix deps.get - mix compile + mix compile --warnings-as-errors - name: "Format" command: | diff --git a/CLAUDE.md b/CLAUDE.md index f0c4f46..b3a32c2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -27,8 +27,11 @@ mise run setup # install tools, deps, wire git hooks (hk) ``` `hk` runs a pre-commit hook: `mix format --check-formatted` on staged `.ex/.exs`, -`tsc --noEmit` when staged `.ts` files exist, and `shadix-registry` (regenerate + -re-stage `priv/registry/*.json`) when a component source or `assets/ts/*.ts` is staged. +`mix compile --warnings-as-errors` when staged `.ex/.exs` exists (compiler warnings +block the commit), `tsc --noEmit` when staged `.ts` files exist, and `shadix-registry` +(regenerate + re-stage `priv/registry/*.json`) when a component source or +`assets/ts/*.ts` is staged. CI mirrors this: the setup step compiles with +`--warnings-as-errors`, so warnings fail the build. A11y tests are a **separate** Playwright/axe-core suite under `test/a11y/` (its own `package.json`, not run by `mix test`). They drive the live docs site. diff --git a/hk.pkl b/hk.pkl index faef573..9e0b780 100644 --- a/hk.pkl +++ b/hk.pkl @@ -6,6 +6,15 @@ local linters = new Mapping { check = "mix format --check-formatted {{files}}" fix = "mix format {{files}}" } + // Compile with --warnings-as-errors so compiler warnings block the commit. + // Gated on staged Elixir sources (mirrors mix-format) so it stays dormant + // for non-code changes; no glob would make it run on every commit. It's a + // check-only step (compile can't auto-fix), so it runs in both `hk check` + // and the `fix = true` pre-commit hook. + ["mix-compile"] { + glob = List("*.ex", "*.exs") + check = "mix compile --warnings-as-errors" + } // Whole-project type check; gated on staged .ts files so it stays dormant // until the TypeScript hooks land under assets/. ["tsc"] { diff --git a/website/components/component_doc.ex b/website/components/component_doc.ex index 6c6c6a4..4d2e2e0 100644 --- a/website/components/component_doc.ex +++ b/website/components/component_doc.ex @@ -49,14 +49,12 @@ defmodule Shadix.Website.Components.ComponentDoc do end compiled = - EEx.compile_string(source, - engine: Phoenix.LiveView.TagEngine, - tag_handler: Phoenix.LiveView.HTMLEngine, + Phoenix.LiveView.TagEngine.compile(source, caller: __CALLER__, - source: source, file: __CALLER__.file, line: __CALLER__.line, - indentation: 0 + indentation: 0, + tag_handler: Phoenix.LiveView.HTMLEngine ) trimmed_source = String.trim_trailing(source) -- 2.51.2