Skip to content

Commit 4e3568e

Browse files
committed
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)
1 parent cdfc88f commit 4e3568e

9 files changed

Lines changed: 34 additions & 19 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ jobs:
5858
- run: cargo clippy --locked --workspace --all-targets -- -D warnings
5959
# snapshot-diff goes on crates.io: it builds without its schemars feature too.
6060
- run: cargo clippy --locked -p snapshot-diff --no-default-features --all-targets -- -D warnings
61+
# Unused dependencies, in each of the three Rust workspaces (cargo-shear; ignores in each Cargo.toml's
62+
# [package.metadata.cargo-shear], with the reason beside them).
63+
- uses: jdx/mise-action@924e7c586e33d7d4bae9c14e26c5d22e2beb6e78 # v5.3.0
64+
with:
65+
install_args: github:Boshen/cargo-shear
66+
- run: |
67+
cargo shear
68+
(cd clients/gallery/rust && cargo shear)
69+
(cd clients/gallery/rust/examples/loco && cargo shear)
6170
6271
# The app (app/, Laravel Rust, the root workspace's visualci-app). Its tests also render every customer email as HTML
6372
# 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:
623632
# The production site: with the Plausible snippets (analytics.ts) and, required, the WebAssembly.
624633
- run: pnpm install --frozen-lockfile && VISUALCI_ANALYTICS=1 VISUALCI_REQUIRE_WASM=1 pnpm build
625634
working-directory: frontend
635+
# Unused files and dependencies in the frontend (knip.jsonc; unused exports are reported, not failed). Pinned
636+
# here rather than in package.json, so its dependency tree stays out of the frontend's lockfile.
637+
- run: pnpm dlx knip@6.49.0 --no-progress
638+
working-directory: frontend
626639
env:
627640
GITHUB_TOKEN: ${{ github.token }} # the docs' CLI release (scripts/cli-version.mjs)
628641
# visualci.com's static site: assembled from the build and checked (every docs page has its Markdown copy, and

‎AGENTS.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ design is in `docs/design.md`; read it before changing the architecture, and upd
2727
`@ts-expect-error`, `# noqa`, a zizmor ignore and the rest) is listed in `scripts/ci/suppressions.txt` with its
2828
reason, added in the change that adds it (`scripts/ci/check_suppressions.py`). Fix what a lint finds before you
2929
reach for a suppression.
30+
- **Unused code fails CI:** cargo-shear finds unused Rust dependencies in the three workspaces (`lint` job), and Knip
31+
unused files and dependencies in `frontend/` (`knip.jsonc`, `clients` job; unused exports are reported only, for now).
32+
Delete what they find; ignore something only in their config, with the reason beside it.
3033
- **Links are checked** by lychee (`lychee.toml`): CI's `clients` job checks every page, file and `#anchor` the built
3134
site links to, offline, so a broken internal link fails the build that makes it. The Audit workflow checks every link
3235
on the live site, outside ones included, each night. Exclude a link in `lychee.toml` only with the reason beside it.

‎Cargo.lock‎

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/Cargo.toml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ envschema = { path = "../crates/envschema" }
9393
# VisualCI's own crates, shared with the CLI.
9494
visualci-core = { path = "../crates/visualci-core", features = ["bundle"] }
9595
tempfile.workspace = true
96-
snapshot-diff = { path = "../crates/snapshot-diff" }
9796

9897
[dev-dependencies]
9998
# Hand-made bundles in tests/bundle_uploads.rs: links, bad paths, a zstd bomb
@@ -106,3 +105,7 @@ regex = "1"
106105
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "std"] }
107106
# A GitHub App key made at test time, so no private key is committed
108107
rsa = { version = "0.9", features = ["pem"] }
108+
109+
# cargo-shear (CI's lint job): the migrations are compiled in by laravel::db::migrations!, not by `mod`.
110+
[package.metadata.cargo-shear]
111+
ignored-paths = ["database/migrations/*.rs"]

‎clients/gallery/rust/examples/loco/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ publish = false
1111
[dependencies]
1212
loco-rs = { version = "1.4", default-features = false }
1313
async-trait = "0.1"
14-
axum = "0.8"
1514
serde = { version = "1", features = ["derive"] }
1615
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
1716
# region: dependencies
@@ -24,4 +23,5 @@ askama = "0.16"
2423
visualci-gallery = { path = "../.." }
2524

2625
[dev-dependencies]
26+
axum = "0.8"
2727
serde_json = "1"

‎frontend/knip.jsonc‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Knip (unused files, dependencies and exports), run by CI's clients job after the frontend's install. Unused files and
2+
// dependencies fail it; unused exports are reported only, for now. Ignore something here only with the reason beside it.
3+
{
4+
"$schema": "https://unpkg.com/knip@6/schema.json",
5+
// The build's and CI's scripts (package.json, ci.yml); Knip finds the app's own entries through Vite.
6+
"entry": ["scripts/*.mjs"],
7+
// Type declarations for the .mjs scripts, which TypeScript reads beside each script.
8+
"ignore": ["scripts/*.d.mts"],
9+
// scripts/og.mjs loads its fonts with require.resolve on a computed path, which Knip can't follow.
10+
"ignoreDependencies": ["@fontsource/geist"],
11+
"rules": { "exports": "warn", "types": "warn" }
12+
}

‎frontend/src/bindings/ApiError.ts‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

‎frontend/src/bindings/Page.ts‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎mise.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ typos = "1.53.0"
1414
oxlint = "1.96.0"
1515
lychee = "0.24.2"
1616
"github:sbdchd/squawk" = "2.74.0"
17+
"github:Boshen/cargo-shear" = "1.14.1"

0 commit comments

Comments
 (0)