diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3921d2a0..bca70e14 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). @@ -625,6 +634,13 @@ jobs: 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. 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 }} # 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 b23b8868..49d70b97 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -27,6 +27,10 @@ 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 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 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 78b1636d..40f13920 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 4234ee1f..c251a8a5 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,8 @@ 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`, 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", "database/seeders/mod.rs"] diff --git a/clients/gallery/rust/examples/loco/Cargo.toml b/clients/gallery/rust/examples/loco/Cargo.toml index da2920c9..340386cc 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 00000000..ba81f0fb --- /dev/null +++ b/frontend/knip.jsonc @@ -0,0 +1,13 @@ +// 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", + // 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. + "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 b377fc70..00000000 --- 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 2a642018..00000000 --- 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 ef41ef14..d02d1317 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"