Repository navigation
CI: fail on unused code, unused dependencies and broken doc links - #894
Merged
Merged
Conversation
Checks for what rustc, clippy and tsc do not report, which the cleanup before this one removed by hand: - `cargo xtask unused` (fmt job; xtask stays dependency-free) reads the workspace's manifests and sources as text and fails on a `pub` item whose name appears nowhere else, a dependency its crate never names (`name::…`, `use name`, `extern crate name`; `md-5` is `md5`), a dev-dependency that repeats a dependency without adding a feature, and a `[workspace.dependencies]` entry no member inherits. A dependency needed without being named goes under `[package.metadata.unused] ignore`. On `main` before the cleanup it reports the 44 items that were removed. - `pnpm run knip` (web job) with `web/knip.jsonc`: files, exports and packages nothing imports; an export only its own module uses is left alone. knip 6.43.0, the newest outside pnpm's 7-day cooldown. - `cargo xtask doc-check` (clippy job, after the sqlx drift guard): the crates' API docs with rustdoc's warnings denied, so a doc link to a renamed or removed item fails. It found 23 broken, ambiguous or redundant links, fixed here: most needed a path, but `super::OidcProvider`, `authz::can_read` and `MockOidc::set_next_id_token_with_retired_key` no longer exist, and `rotate_key`'s doc described a snapshot of the old signer the code does not take. DEVELOPMENT.md documents the three under "Unused code and stale doc links". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012e6DJZJ5VT9e32viHMCHoq
Brings in main through #890's branch. Conflict: DEVELOPMENT.md's helper command list keeps main's `migrate` and `prepare-check` next to `unused` and `doc-check`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012e6DJZJ5VT9e32viHMCHoq
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #890: merge that first; this one is then retargeted to
main(do not merge it into #890's branch).What changed
Three checks catch what rustc, clippy and
tsclet through. #890 removed this kind of code by hand; these checks fail CI when more appears.cargo xtask unused(newxtask/src/unused.rs, run by thefmtjob)Cargo.tomland.rsfiles as text. xtask stays dependency-free.pubitem (fn, struct, enum, union, trait, type, const, static) whose name appears nowhere else in the workspace's sources. Definitions inside comments, doc tests and string literals are ignored.name::…,use name,extern crate name), with-read as_or dropped (md-5ismd5).[workspace.dependencies]entry no member inherits.[package.metadata.unused] ignore = [...]in its crate's manifest. Nothing needs that today.mainbefore Remove unused code and dependencies #890, it reports exactly the 44 items Remove unused code and dependencies #890 removes (14pubitems, 5 dependencies, 25 dev-dependencies) and nothing else. On Remove unused code and dependencies #890's branch it passes.pnpm run knip(web job, config inweb/knip.jsonc)package.jsonpackage that nothing imports.src/routes.tsis an entry, because the router plugin loads it by path.@import 'tailwindcss'counts as a use and the config needs no ignore list.ignoreExportsUsedInFileis on, so an export that only its own module uses is left alone.minimumReleaseAge(6.44.1 is three days old). The lockfile adds knip and its dependencies; every existing package keeps its version, and Vite's entry only gainsyamlas a resolved peer.mainbefore Remove unused code and dependencies #890, it reports the 4 unused files, the 2 devtools packages and the 16 unused exports and types that Remove unused code and dependencies #890 removes. On Remove unused code and dependencies #890's branch it passes.cargo xtask doc-check(clippy job, last step)cargo doc --workspace --all-features --no-deps --document-private-itemswithRUSTDOCFLAGS="-D warnings -A rustdoc::private_intra_doc_links".--all-featuresbrings inforge-e2e, which is entirely behind its feature.super::OidcProvider(the server builds theClaimMappinginOidcRuntime::build), the free functionauthz::can_read(nowAuthz::can_read), andMockOidc::set_next_id_token_with_retired_key. The doc ofMockOidc::rotate_keyalso described keeping the old signer, which the code doesn't do; it is rewritten to match the code.format,evaluate,reference), now disambiguated.cargo sqlx prepare --check, which has already check-built every dependency with every feature.DEVELOPMENT.mdgets a section, "Unused code and stale doc links", covering all three and how to keep a dependency. The new commands are added tocargo xtask helpand to the helper-command list.Tests
Run locally on this branch:
cargo test -p xtask: 45 + 2 pass, including 9 new tests for the manifest reader, the source scan and each kind of finding.cargo xtask unused,cargo xtask doc-check,cargo xtask docs --checkandcargo xtask changelog --check.cargo fmt --all --check, andcargo clippy -p xtask --all-targets -- -D warnings.cd web && pnpm install --frozen-lockfile && pnpm run knip.CI does not run on a stacked pull request. It will run once this PR is retargeted to
mainand pushed again, or by hand withgh workflow run ci.yml --ref claude/unused-code-checks -f base=main.Changelog
No fragment. Nothing changes for the people who run Forge.
Notes
cargo-shear/cargo-macheteto keep the repository's checks self-contained and runnable without installing anything. If you would rather use cargo-shear,taiki-e/install-action(already pinned in CI) can install it, and the xtask check could then shrink to thepub-item and repeated dev-dependency parts.Generated by Claude Code