From fc028574a094f7600b58bcd6aee71e3669a6d1cb Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 05:56:33 +0000 Subject: [PATCH 1/2] Unused code: cargo-shear on the three Rust workspaces and Knip on the frontend in CI; snapshot-diff out of app, axum a Loco dev-dependency, the stale ts-rs bindings deleted (sc-9611) --- .github/workflows/ci.yml | 13 +++++++++++++ AGENTS.md | 3 +++ Cargo.lock | 1 - app/Cargo.toml | 5 ++++- clients/gallery/rust/examples/loco/Cargo.toml | 2 +- frontend/knip.jsonc | 12 ++++++++++++ frontend/src/bindings/ApiError.ts | 3 --- frontend/src/bindings/Page.ts | 13 ------------- mise.toml | 1 + 9 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 frontend/knip.jsonc delete mode 100644 frontend/src/bindings/ApiError.ts delete mode 100644 frontend/src/bindings/Page.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3921d2a00..da525479d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,6 +58,15 @@ jobs: - run: cargo clippy --locked --workspace --all-targets -- -D warnings # snapshot-diff goes on crates.io: it builds without its schemars feature too. - run: cargo clippy --locked -p snapshot-diff --no-default-features --all-targets -- -D warnings + # Unused dependencies, in each of the three Rust workspaces (cargo-shear; ignores in each Cargo.toml's + # [package.metadata.cargo-shear], with the reason beside them). + - uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0 + with: + install_args: github:Boshen/cargo-shear + - run: | + cargo shear + (cd clients/gallery/rust && cargo shear) + (cd clients/gallery/rust/examples/loco && cargo shear) # The app (app/, Laravel Rust, the root workspace's visualci-app). Its tests also render every customer email as HTML # and text for the visual job. clippy covers it in the lint job (formatting is the pre-commit hook's, lefthook.yml). @@ -623,6 +632,10 @@ jobs: # The production site: with the Plausible snippets (analytics.ts) and, required, the WebAssembly. - run: pnpm install --frozen-lockfile && VISUALCI_ANALYTICS=1 VISUALCI_REQUIRE_WASM=1 pnpm build working-directory: frontend + # Unused files and dependencies in the frontend (knip.jsonc; unused exports are reported, not failed). Pinned + # here rather than in package.json, so its dependency tree stays out of the frontend's lockfile. + - run: pnpm dlx knip@6.49.0 --no-progress + working-directory: frontend env: GITHUB_TOKEN: ${{ github.token }} # the docs' CLI release (scripts/cli-version.mjs) # visualci.com's static site: assembled from the build and checked (every docs page has its Markdown copy, and diff --git a/AGENTS.md b/AGENTS.md index b23b8868c..845cc5d8e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -27,6 +27,9 @@ design is in `docs/design.md`; read it before changing the architecture, and upd `@ts-expect-error`, `# noqa`, a zizmor ignore and the rest) is listed in `scripts/ci/suppressions.txt` with its reason, added in the change that adds it (`scripts/ci/check_suppressions.py`). Fix what a lint finds before you reach for a suppression. +- **Unused code fails CI:** cargo-shear finds unused Rust dependencies in the three workspaces (`lint` job), and Knip + unused files and dependencies in `frontend/` (`knip.jsonc`, `clients` job; unused exports are reported only, for now). + Delete what they find; ignore something only in their config, with the reason beside it. - **Links are checked** by lychee (`lychee.toml`): CI's `clients` job checks every page, file and `#anchor` the built site links to, offline, so a broken internal link fails the build that makes it. The Audit workflow checks every link on the live site, outside ones included, each night. Exclude a link in `lychee.toml` only with the reason beside it. diff --git a/Cargo.lock b/Cargo.lock index 78b1636dc..40f13920e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5441,7 +5441,6 @@ dependencies = [ "serde_json", "serde_path_to_error", "sha2 0.10.9", - "snapshot-diff", "sqlx", "tar", "tempfile", diff --git a/app/Cargo.toml b/app/Cargo.toml index 4234ee1f9..69a91309e 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -93,7 +93,6 @@ envschema = { path = "../crates/envschema" } # VisualCI's own crates, shared with the CLI. visualci-core = { path = "../crates/visualci-core", features = ["bundle"] } tempfile.workspace = true -snapshot-diff = { path = "../crates/snapshot-diff" } [dev-dependencies] # Hand-made bundles in tests/bundle_uploads.rs: links, bad paths, a zstd bomb @@ -106,3 +105,7 @@ regex = "1" tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "std"] } # A GitHub App key made at test time, so no private key is committed rsa = { version = "0.9", features = ["pem"] } + +# cargo-shear (CI's lint job): the migrations are compiled in by laravel::db::migrations!, not by `mod`. +[package.metadata.cargo-shear] +ignored-paths = ["database/migrations/*.rs"] diff --git a/clients/gallery/rust/examples/loco/Cargo.toml b/clients/gallery/rust/examples/loco/Cargo.toml index da2920c9a..340386ccd 100644 --- a/clients/gallery/rust/examples/loco/Cargo.toml +++ b/clients/gallery/rust/examples/loco/Cargo.toml @@ -11,7 +11,6 @@ publish = false [dependencies] loco-rs = { version = "1.4", default-features = false } async-trait = "0.1" -axum = "0.8" serde = { version = "1", features = ["derive"] } tokio = { version = "1", features = ["rt-multi-thread", "macros"] } # region: dependencies @@ -24,4 +23,5 @@ askama = "0.16" visualci-gallery = { path = "../.." } [dev-dependencies] +axum = "0.8" serde_json = "1" diff --git a/frontend/knip.jsonc b/frontend/knip.jsonc new file mode 100644 index 000000000..be644008e --- /dev/null +++ b/frontend/knip.jsonc @@ -0,0 +1,12 @@ +// Knip (unused files, dependencies and exports), run by CI's clients job after the frontend's install. Unused files and +// dependencies fail it; unused exports are reported only, for now. Ignore something here only with the reason beside it. +{ + "$schema": "https://unpkg.com/knip@6/schema.json", + // The build's and CI's scripts (package.json, ci.yml); Knip finds the app's own entries through Vite. + "entry": ["scripts/*.mjs"], + // Type declarations for the .mjs scripts, which TypeScript reads beside each script. + "ignore": ["scripts/*.d.mts"], + // scripts/og.mjs loads its fonts with require.resolve on a computed path, which Knip can't follow. + "ignoreDependencies": ["@fontsource/geist"], + "rules": { "exports": "warn", "types": "warn" } +} diff --git a/frontend/src/bindings/ApiError.ts b/frontend/src/bindings/ApiError.ts deleted file mode 100644 index b377fc70e..000000000 --- a/frontend/src/bindings/ApiError.ts +++ /dev/null @@ -1,3 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -export type ApiError = { code: string, message: string, details: unknown, }; diff --git a/frontend/src/bindings/Page.ts b/frontend/src/bindings/Page.ts deleted file mode 100644 index 2a6420185..000000000 --- a/frontend/src/bindings/Page.ts +++ /dev/null @@ -1,13 +0,0 @@ -// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually. - -/** - * A page of results: the items, plus the framework's pagination metadata - * flattened alongside them. - * - * The field names are exactly `PagerMeta`'s (`page`, `page_size`, - * `total_pages`, `total_items`), so an app has one pagination vocabulary - * whether a handler answers with this typed envelope or with the framework's - * own `Pager`. Build it with [`Page::from_query`] rather than by hand — that - * is what keeps the two in step. - */ -export type Page = { items: Array, page: number, page_size: number, total_pages: number, total_items: number, }; diff --git a/mise.toml b/mise.toml index ef41ef147..d02d13175 100644 --- a/mise.toml +++ b/mise.toml @@ -14,3 +14,4 @@ typos = "1.53.0" oxlint = "1.96.0" lychee = "0.24.2" "github:sbdchd/squawk" = "2.74.0" +"github:Boshen/cargo-shear" = "1.14.1" From 77ae12cf6bd22c69be0640dde3f4941ce5d2ce15 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Sat, 5 Dec 2026 06:09:19 +0000 Subject: [PATCH 2/2] Unused code review: Knip and the site build each get the CLI release token, Knip's entry is just site.mjs so an unused script fails, the empty seeders module is ignored by cargo-shear, and AGENTS.md says its file warnings don't fail --- .github/workflows/ci.yml | 7 +++++-- AGENTS.md | 5 +++-- app/Cargo.toml | 5 +++-- frontend/knip.jsonc | 5 +++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index da525479d..bca70e143 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -632,12 +632,15 @@ jobs: # The production site: with the Plausible snippets (analytics.ts) and, required, the WebAssembly. - run: pnpm install --frozen-lockfile && VISUALCI_ANALYTICS=1 VISUALCI_REQUIRE_WASM=1 pnpm build working-directory: frontend + env: + GITHUB_TOKEN: ${{ github.token }} # the docs' CLI release (scripts/cli-version.mjs) # Unused files and dependencies in the frontend (knip.jsonc; unused exports are reported, not failed). Pinned - # here rather than in package.json, so its dependency tree stays out of the frontend's lockfile. + # here rather than in package.json, so its dependency tree stays out of the frontend's lockfile. It loads + # vite.config.ts, which reads the CLI release too. - run: pnpm dlx knip@6.49.0 --no-progress working-directory: frontend env: - GITHUB_TOKEN: ${{ github.token }} # the docs' CLI release (scripts/cli-version.mjs) + GITHUB_TOKEN: ${{ github.token }} # visualci.com's static site: assembled from the build and checked (every docs page has its Markdown copy, and # llms.txt links each one), then deployed by the site job. - run: VISUALCI_ANALYTICS=1 node scripts/site.mjs diff --git a/AGENTS.md b/AGENTS.md index 845cc5d8e..49d70b972 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -27,8 +27,9 @@ design is in `docs/design.md`; read it before changing the architecture, and upd `@ts-expect-error`, `# noqa`, a zizmor ignore and the rest) is listed in `scripts/ci/suppressions.txt` with its reason, added in the change that adds it (`scripts/ci/check_suppressions.py`). Fix what a lint finds before you reach for a suppression. -- **Unused code fails CI:** cargo-shear finds unused Rust dependencies in the three workspaces (`lint` job), and Knip - unused files and dependencies in `frontend/` (`knip.jsonc`, `clients` job; unused exports are reported only, for now). +- **Unused code fails CI:** cargo-shear fails on unused Rust dependencies in the three workspaces (`lint` job; its + unlinked-file warnings don't fail), and Knip on unused files and dependencies in `frontend/` (`knip.jsonc`, + `clients` job; unused exports are reported only, for now). Delete what they find; ignore something only in their config, with the reason beside it. - **Links are checked** by lychee (`lychee.toml`): CI's `clients` job checks every page, file and `#anchor` the built site links to, offline, so a broken internal link fails the build that makes it. The Audit workflow checks every link diff --git a/app/Cargo.toml b/app/Cargo.toml index 69a91309e..c251a8a5d 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -106,6 +106,7 @@ tracing-subscriber = { version = "0.3", default-features = false, features = ["f # A GitHub App key made at test time, so no private key is committed rsa = { version = "0.9", features = ["pem"] } -# cargo-shear (CI's lint job): the migrations are compiled in by laravel::db::migrations!, not by `mod`. +# cargo-shear (CI's lint job): the migrations are compiled in by laravel::db::migrations!, not by `mod`, and the +# seeders module has no seeders yet (its only line is a doc comment, which cargo-shear calls empty). [package.metadata.cargo-shear] -ignored-paths = ["database/migrations/*.rs"] +ignored-paths = ["database/migrations/*.rs", "database/seeders/mod.rs"] diff --git a/frontend/knip.jsonc b/frontend/knip.jsonc index be644008e..ba81f0fbc 100644 --- a/frontend/knip.jsonc +++ b/frontend/knip.jsonc @@ -2,8 +2,9 @@ // dependencies fail it; unused exports are reported only, for now. Ignore something here only with the reason beside it. { "$schema": "https://unpkg.com/knip@6/schema.json", - // The build's and CI's scripts (package.json, ci.yml); Knip finds the app's own entries through Vite. - "entry": ["scripts/*.mjs"], + // CI runs scripts/site.mjs (ci.yml, which Knip can't see from here). Knip finds package.json's scripts and the app's + // own entries (through Vite) itself, so an unused script is reported. + "entry": ["scripts/site.mjs"], // Type declarations for the .mjs scripts, which TypeScript reads beside each script. "ignore": ["scripts/*.d.mts"], // scripts/og.mjs loads its fonts with require.resolve on a computed path, which Knip can't follow.