Skip to content
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

Add workspace ignore list #57

Merged
merged 4 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 267 additions & 0 deletions integration-tests/ignored-dep-workspace/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions integration-tests/ignored-dep-workspace/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[workspace]
members = ["./inner"]

[workspace.dependencies]
log = "0.4.14"
serde = "1"

[workspace.metadata.cargo-machete]
ignored = [
"lazy_static",
"serde",
"futures", # actually used but in workspace ignored, should NOT cause a warning
]
20 changes: 20 additions & 0 deletions integration-tests/ignored-dep-workspace/inner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "ignored-dep"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log-once = "0.3.1"
rand = "0.8.5"
rand_core = "0.6.3"
lazy_static = "1.4.0"
serde.workspace = true
futures = "0.3"

[package.metadata.cargo-machete]
ignored = [
"log",
"rand_core" # actually used, should cause a warning
]
9 changes: 9 additions & 0 deletions integration-tests/ignored-dep-workspace/inner/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#[allow(unused_imports)]
use rand_core::Error as _;

#[allow(unused_imports)]
use futures::Future as _;

fn main() {
log_once::warn_once!("Hello, world!");
}
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn collect_paths(path: &Path, skip_target_dir: bool) -> Vec<PathBuf> {
.filter_map(|entry| match entry {
Ok(entry) if entry.file_name() == "Cargo.toml" => Some(entry.into_path()),
Err(err) => {
eprintln!("error when walking over subdirectories: {}", err);
eprintln!("error when walking over subdirectories: {err}");
None
}
_ => None,
Expand Down Expand Up @@ -181,7 +181,7 @@ fn run_machete() -> anyhow::Result<bool> {
for (analysis, path) in results {
println!("{} -- {}:", analysis.package_name, path.to_string_lossy());
for dep in &analysis.unused {
println!("\t{}", dep);
println!("\t{dep}");
has_unused_dependencies = true; // any unused dependency is enough to set flag to true
}

Expand Down Expand Up @@ -214,7 +214,7 @@ fn remove_dependencies(manifest: &str, dependencies_list: &[String]) -> anyhow::
for k in dependencies_list {
dependencies
.remove(k)
.with_context(|| format!("Dependency {} not found", k))?;
.with_context(|| format!("Dependency {k} not found"))?;
}

let serialized = manifest.to_string();
Expand Down
Loading