Skip to content

Commit

Permalink
Add workspace ignore list (#57)
Browse files Browse the repository at this point in the history
* include ignored list from workspace

* used but workspace ignored should NOT give a warning

* remove unused default impl

* fix clippy warnings

Co-authored-by: Benjamin Bouvier <public@benj.me>
  • Loading branch information
nanocryk and bnjbvr authored Dec 20, 2022
1 parent ef52ac7 commit d71068c
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 22 deletions.
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

0 comments on commit d71068c

Please sign in to comment.