Skip to content

feat: add keep-path-dependencies workspace setting#545

Draft
Boshen wants to merge 1 commit into
mainfrom
feat/keep-path-dependencies
Draft

feat: add keep-path-dependencies workspace setting#545
Boshen wants to merge 1 commit into
mainfrom
feat/keep-path-dependencies

Conversation

@Boshen

@Boshen Boshen commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Closes #533

Some workflows pre-declare a new crate in [workspace.dependencies] as a path dependency before any member inherits it, so later commits (which may get shuffled or backported) can depend on it. cargo-shear flagged such entries as unused workspace dependencies.

This adds an opt-in workspace setting:

[workspace.metadata.cargo-shear]
keep-path-dependencies = true

When enabled, a [workspace.dependencies] entry with path = "..." is treated as used as long as a crate exists at the declared path (<workspace-root>/<path>/Cargo.toml). A stale entry — one whose crate was deleted or moved — is still reported as unused; cargo metadata tolerates uninherited entries with nonexistent paths, so that case is reachable in practice. Default behavior is unchanged.

Notes on scope and interactions:

  • Workspace-root only: an unused path dependency in a member's [dependencies] still costs compile time, so those remain flagged. The setting parses but is inert under [package.metadata.cargo-shear].
  • The skip runs before the ignored check, so an explicit ignored entry made unnecessary by this setting is reported as a redundant ignore, consistent with existing behavior.
  • --fix keeps entries covered by the setting and still removes stale ones.

Some workflows pre-declare a new crate in `[workspace.dependencies]` as a
path dependency before any member inherits it, so later commits can depend
on it. cargo-shear flagged such entries as unused workspace dependencies.

With `keep-path-dependencies = true` under `[workspace.metadata.cargo-shear]`,
a `[workspace.dependencies]` entry with `path = "..."` is treated as used as
long as a crate exists at the declared path. A stale entry whose crate was
deleted or moved is still reported. Default behavior is unchanged.

Closes #533
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow leaving the path dependencies in the workspace root alone for existing crates

1 participant