-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add cargo-ensure-no-unused-workspace-deps #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martin-kolinek
wants to merge
12
commits into
main
Choose a base branch
from
cargo-workspace-deps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
0cab26f
docs: design for cargo-ensure-no-unused-workspace-deps
martin-kolinek 51b999d
fix: exclude the design-only crate directory from the workspace
martin-kolinek d240f35
feat: add the cargo-ensure-no-unused-workspace-deps crate skeleton
martin-kolinek 4d7b097
feat: implement cargo-ensure-no-unused-workspace-deps
martin-kolinek c132cf5
test: assert where a carried comment lands, not that it exists
martin-kolinek db97acb
fix: harden --fix and close the review gaps
martin-kolinek f704af9
fix: exclude the write-guard unit tests from miri
martin-kolinek d4a95e2
fix: preserve manifest identity on --fix and report carries honestly
martin-kolinek 2f8c34e
fix: read and write carried comments through the same decor slot
martin-kolinek 1e6a057
Merge remote-tracking branch 'origin/main' into cargo-workspace-deps
martin-kolinek 5656b50
docs: keep dotted survivors in the trailing-drop description
martin-kolinek b573896
docs: record the stale allow-list report at the empty-catalog boundary
martin-kolinek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -521,3 +521,6 @@ deprecations | |
| parallelization | ||
| remediate | ||
| recency | ||
| symlink | ||
| symlinked | ||
| symlinks | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Changelog | ||
|
martin-kolinek marked this conversation as resolved.
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| [package] | ||
| name = "cargo-ensure-no-unused-workspace-deps" | ||
|
martin-kolinek marked this conversation as resolved.
|
||
| description = "A cargo subcommand that ensures every [workspace.dependencies] entry is inherited by a workspace member" | ||
| version = "0.1.0" | ||
| readme = "README.md" | ||
| keywords = ["oxidizer", "cargo", "subcommand", "dependencies", "ci"] | ||
| categories = ["command-line-utilities", "development-tools::cargo-plugins"] | ||
|
|
||
| edition.workspace = true | ||
| rust-version.workspace = true | ||
| authors.workspace = true | ||
| license.workspace = true | ||
| homepage.workspace = true | ||
| repository = "https://github.com/microsoft/ox-tools/tree/main/crates/cargo-ensure-no-unused-workspace-deps" | ||
|
|
||
| [package.metadata.docs.rs] | ||
| all-features = true | ||
|
|
||
| [package.metadata.cargo_check_external_types] | ||
| # `anyhow::Error` leaks through the `run` entry point that `main` calls. Mirrors the | ||
| # allowlist entry in `cargo-ensure-no-default-features`, which has the same shape. | ||
| allowed_external_types = ["anyhow::Result"] | ||
|
|
||
| [[bin]] | ||
| name = "cargo-ensure-no-unused-workspace-deps" | ||
| path = "src/main.rs" | ||
|
|
||
| [dependencies] | ||
| anyhow = { workspace = true, features = ["std"] } | ||
| cargo_metadata = { workspace = true } | ||
| clap = { workspace = true, features = ["std", "derive", "color", "help", "error-context", "usage"] } | ||
| tempfile = { workspace = true } | ||
| toml_edit = { workspace = true } | ||
|
|
||
| # >>> anvil-managed: anvil-lints | ||
| [lints] | ||
| workspace = true | ||
| # <<< anvil-managed: anvil-lints | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| <div align="center"> | ||
| <img src="./logo.png" alt="Cargo-Ensure-No-Unused-Workspace-Deps Logo" width="96"> | ||
|
|
||
| # Cargo-Ensure-No-Unused-Workspace-Deps | ||
|
|
||
| [](https://crates.io/crates/cargo-ensure-no-unused-workspace-deps) | ||
| [](https://docs.rs/cargo-ensure-no-unused-workspace-deps) | ||
| [](https://crates.io/crates/cargo-ensure-no-unused-workspace-deps) | ||
| [](https://github.com/microsoft/ox-tools/actions/workflows/main.yml) | ||
| [](https://codecov.io/gh/microsoft/ox-tools) | ||
| [](../../LICENSE) | ||
| <a href="../.."><img src="../../logo.svg" alt="This crate was developed as part of the Oxidizer project" width="20"></a> | ||
|
|
||
| </div> | ||
|
|
||
| A cargo sub-command that ensures every `[workspace.dependencies]` entry is | ||
| inherited by at least one workspace member. | ||
|
|
||
| A workspace root declares a dependency catalog that members draw from with | ||
| `dep = { workspace = true }`. Nothing requires an entry to be drawn from, so | ||
| an entry nobody inherits stays in the manifest forever: it never enters the | ||
| dependency graph, and no build fails because of it. It still carries a | ||
| version requirement, so it keeps attracting dependency-bump traffic and keeps | ||
| misleading readers about what the workspace depends on. | ||
|
|
||
| Unused-dependency tools resolve the crate graph and ask which *declared* | ||
| dependencies go unused, so an entry that no member declares is invisible to | ||
| them. This tool answers the prior question – is the entry inherited at all? | ||
| – from the manifests alone, which makes it free of false positives and cheap | ||
| enough to run on every pull request. | ||
|
|
||
| ## Usage | ||
|
|
||
| Run in a cargo workspace: | ||
|
|
||
| ```bash | ||
| cargo ensure-no-unused-workspace-deps | ||
| ``` | ||
|
|
||
| Remove what it finds: | ||
|
|
||
| ```bash | ||
| cargo ensure-no-unused-workspace-deps --fix | ||
| ``` | ||
|
|
||
| `--manifest-path` points at an explicit workspace root, defaulting to the | ||
| `Cargo.toml` in the current directory. A manifest with no `[workspace]` table | ||
| declares no catalog and passes with a note; `--require-workspace` turns that | ||
| into an error for callers that know they are pointing at a workspace root. | ||
|
|
||
| ## Configuration | ||
|
|
||
| An entry kept on purpose is exempted in the workspace manifest: | ||
|
|
||
| ```toml | ||
| [workspace.metadata.ensure-no-unused-workspace-deps] | ||
| allowed = ["kept-on-purpose"] | ||
| ``` | ||
|
|
||
| An `allowed` name that suppresses nothing is reported as stale, on stderr, | ||
| without failing the run. | ||
|
|
||
| ## Fixing | ||
|
|
||
| `--fix` replaces the manifest atomically – a temporary file in the same | ||
| directory, renamed over the original, carrying the permissions of the | ||
| manifest it replaces and following a symlinked manifest to its target – and | ||
| refuses to write at all if the file changed after it was read, so a | ||
| concurrent edit is never clobbered. | ||
|
|
||
| Comments on a removed entry are carried to the next surviving entry, which | ||
| keeps a group header attached to the group it introduces. A note about one | ||
| specific dependency is indistinguishable from such a header, so every move | ||
| is reported on stderr: check that carried text still describes the entry it | ||
| landed on. Comments that cannot be placed – the removal emptied the table, | ||
| or left a trailing survivor with nothing to append to – are reported as | ||
| dropped. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| cargo install cargo-ensure-no-unused-workspace-deps | ||
| ``` | ||
|
|
||
| ## Example output | ||
|
|
||
| ```text | ||
| Found 2 unused workspace dependencies in Cargo.toml: | ||
|
|
||
| - once_cell | ||
| - smallvec | ||
|
|
||
| Re-run with --fix to remove them. | ||
| ``` | ||
|
|
||
|
|
||
| <hr/> | ||
| <sub> | ||
| This crate was developed as part of <a href="../..">The Oxidizer Project</a>. Browse this crate's <a href="https://github.com/microsoft/ox-tools/tree/main/crates/cargo-ensure-no-unused-workspace-deps">source code</a>. | ||
| </sub> | ||
|
|
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.