From 5affaaa7b82504ce837815532ddd01c7c69faba2 Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Thu, 14 Mar 2024 19:26:13 +0000 Subject: [PATCH 01/13] feat: remove features when removing dependencies --- src/main.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.rs b/src/main.rs index 39791f7..78f9858 100644 --- a/src/main.rs +++ b/src/main.rs @@ -266,6 +266,26 @@ fn remove_dependencies(manifest: &str, dependencies_list: &[String]) -> anyhow:: .with_context(|| format!("Dependency {k} not found"))?; } + let features = manifest + .iter_mut() + .find_map(|(k, v)| (v.is_table_like() && k == "features").then_some(Some(v))) + .flatten() + .and_then(|v| v.as_table_mut()); + + if let Some(features) = features { + for (_, deps) in features.iter_mut() { + if let Some(deps) = deps.as_array_mut() { + deps.retain(|dep| { + if let Some(dep) = dep.as_str() { + !dependencies_list.iter().any(|d| dep.contains(d)) + } else { + true + } + }); + } + } + } + let serialized = manifest.to_string(); Ok(serialized) } From a311af2faf04696b79c770d26a38fb97c93d7bfe Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:28:09 +0000 Subject: [PATCH 02/13] added CLI test --- .github/workflows/main.yml | 21 +++++++++++++++++-- .../autofix-with-feature/actual/Cargo.toml | 9 ++++++++ .../autofix-with-feature/actual/src/main.rs | 3 +++ .../autofix-with-feature/expected/Cargo.toml | 13 ++++++++++++ .../autofix-with-feature/expected/src/main.rs | 3 +++ 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 integration-tests/autofix-with-feature/actual/Cargo.toml create mode 100644 integration-tests/autofix-with-feature/actual/src/main.rs create mode 100644 integration-tests/autofix-with-feature/expected/Cargo.toml create mode 100644 integration-tests/autofix-with-feature/expected/src/main.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 664c869..b28f9e3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -7,12 +7,12 @@ on: tags: - "*" pull_request: - branches: [ main ] + branches: [main] jobs: ci: env: - RUST_BACKTRACE: 1 + RUST_BACKTRACE: 1 runs-on: ubuntu-latest strategy: matrix: @@ -36,6 +36,23 @@ jobs: - run: cargo test --workspace --verbose + autofix: + name: Autofix Tests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: clippy, rustfmt + # Build the binary, install it as cargo machete using cargo install --path . and then run it on integration-tests/autofix-with-feature/actual + # Then compare actual with expected, if no difference, test passes + - run: cargo build --release + - run: cargo install --path . + - run: cd integration-tests/autofix-with-feature/actual + - run: cargo machete --fix + - run: cd .. & diff -r expected actual + # Code mutably borrowed from https://github.com/EmbarkStudios/cargo-deny/, thanks Embark! release: name: Release diff --git a/integration-tests/autofix-with-feature/actual/Cargo.toml b/integration-tests/autofix-with-feature/actual/Cargo.toml new file mode 100644 index 0000000..490012f --- /dev/null +++ b/integration-tests/autofix-with-feature/actual/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "just-unused" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +log = "0.4.14" diff --git a/integration-tests/autofix-with-feature/actual/src/main.rs b/integration-tests/autofix-with-feature/actual/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/integration-tests/autofix-with-feature/actual/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/integration-tests/autofix-with-feature/expected/Cargo.toml b/integration-tests/autofix-with-feature/expected/Cargo.toml new file mode 100644 index 0000000..f02faf0 --- /dev/null +++ b/integration-tests/autofix-with-feature/expected/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "just-unused" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] + +[features] +default = ["std"] +std = [ "other"] +other = [] diff --git a/integration-tests/autofix-with-feature/expected/src/main.rs b/integration-tests/autofix-with-feature/expected/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/integration-tests/autofix-with-feature/expected/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} From 86a12838e75c1e454595f866018ef2ad7f0e9a75 Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:32:15 +0000 Subject: [PATCH 03/13] fail-fast: false on cli --- .github/workflows/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b28f9e3..bf117be 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -39,6 +39,8 @@ jobs: autofix: name: Autofix Tests runs-on: ubuntu-latest + strategy: + fail-fast: false steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master From 17155ba3bbd1fd69aeaa5d6f6b2b4b6ecf41dc5e Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:37:34 +0000 Subject: [PATCH 04/13] || true after fix --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bf117be..31b7b03 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,7 +52,7 @@ jobs: - run: cargo build --release - run: cargo install --path . - run: cd integration-tests/autofix-with-feature/actual - - run: cargo machete --fix + - run: cargo machete --fix || true - run: cd .. & diff -r expected actual # Code mutably borrowed from https://github.com/EmbarkStudios/cargo-deny/, thanks Embark! From 43dc72c8ff4a4d151c587b7e1ab14e66e8cc2a63 Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:41:27 +0000 Subject: [PATCH 05/13] check pwd --- .github/workflows/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 31b7b03..ade5120 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,7 +53,9 @@ jobs: - run: cargo install --path . - run: cd integration-tests/autofix-with-feature/actual - run: cargo machete --fix || true - - run: cd .. & diff -r expected actual + - run: pwd + - run: cd .. + - run: diff -r expected actual # Code mutably borrowed from https://github.com/EmbarkStudios/cargo-deny/, thanks Embark! release: From 5c232a6c632acd59bab3fb2592ef1266e350fbe3 Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:44:26 +0000 Subject: [PATCH 06/13] add more pwd --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ade5120..25aa1f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,6 +52,7 @@ jobs: - run: cargo build --release - run: cargo install --path . - run: cd integration-tests/autofix-with-feature/actual + - run: pwd - run: cargo machete --fix || true - run: pwd - run: cd .. From 57fc31fce757000ab3d5565d67cde204e98e403e Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 11:58:17 +0000 Subject: [PATCH 07/13] add ls --- .github/workflows/main.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 25aa1f5..6ffa6c1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -51,6 +51,7 @@ jobs: # Then compare actual with expected, if no difference, test passes - run: cargo build --release - run: cargo install --path . + - run: ls - run: cd integration-tests/autofix-with-feature/actual - run: pwd - run: cargo machete --fix || true From 6c37640baeb6fdeef88f7cbfcaf9dc2f81449c83 Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:02:39 +0000 Subject: [PATCH 08/13] cd then command --- .github/workflows/main.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6ffa6c1..5f8dd5a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -52,12 +52,8 @@ jobs: - run: cargo build --release - run: cargo install --path . - run: ls - - run: cd integration-tests/autofix-with-feature/actual - - run: pwd - - run: cargo machete --fix || true - - run: pwd - - run: cd .. - - run: diff -r expected actual + - run: cd integration-tests/autofix-with-feature/actual && cargo machete --fix || true + - run: cd integration-tests/autofix-with-feature && diff -r expected actual # Code mutably borrowed from https://github.com/EmbarkStudios/cargo-deny/, thanks Embark! release: From f40109410534b5f8701cff38f9b3bdf3b7d97013 Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:04:07 +0000 Subject: [PATCH 09/13] fast fail --- .github/workflows/main.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5f8dd5a..7048ade 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -49,10 +49,11 @@ jobs: components: clippy, rustfmt # Build the binary, install it as cargo machete using cargo install --path . and then run it on integration-tests/autofix-with-feature/actual # Then compare actual with expected, if no difference, test passes - - run: cargo build --release - - run: cargo install --path . + # - run: cargo build --release + # - run: cargo install --path . - run: ls - - run: cd integration-tests/autofix-with-feature/actual && cargo machete --fix || true + # - run: cd integration-tests/autofix-with-feature/actual && cargo machete --fix || true + - run: cd integration-tests/autofix-with-feature/actual && pwd - run: cd integration-tests/autofix-with-feature && diff -r expected actual # Code mutably borrowed from https://github.com/EmbarkStudios/cargo-deny/, thanks Embark! From 58ab1de98cc3c59e27553b82e2c8175f67ac013f Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:06:49 +0000 Subject: [PATCH 10/13] autofix ci test --- .github/workflows/main.yml | 9 +++------ integration-tests/autofix-with-feature/actual/Cargo.toml | 5 +++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7048ade..3208173 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -47,13 +47,10 @@ jobs: with: toolchain: stable components: clippy, rustfmt - # Build the binary, install it as cargo machete using cargo install --path . and then run it on integration-tests/autofix-with-feature/actual - # Then compare actual with expected, if no difference, test passes - # - run: cargo build --release - # - run: cargo install --path . + - run: cargo build --release + - run: cargo install --path . - run: ls - # - run: cd integration-tests/autofix-with-feature/actual && cargo machete --fix || true - - run: cd integration-tests/autofix-with-feature/actual && pwd + - run: cd integration-tests/autofix-with-feature/actual && cargo machete --fix || true - run: cd integration-tests/autofix-with-feature && diff -r expected actual # Code mutably borrowed from https://github.com/EmbarkStudios/cargo-deny/, thanks Embark! diff --git a/integration-tests/autofix-with-feature/actual/Cargo.toml b/integration-tests/autofix-with-feature/actual/Cargo.toml index 490012f..2178fd6 100644 --- a/integration-tests/autofix-with-feature/actual/Cargo.toml +++ b/integration-tests/autofix-with-feature/actual/Cargo.toml @@ -7,3 +7,8 @@ edition = "2021" [dependencies] log = "0.4.14" + +[features] +default = ["std"] +std = ["log/std", "other"] +other = [] From b2549ca3b9348a40c06ea71dc50cfce86a1db1f2 Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:12:36 +0000 Subject: [PATCH 11/13] dynamically find cli-tests --- .github/workflows/main.yml | 17 +++++++++++++++-- .../actual/autofix-with-feature}/Cargo.toml | 0 .../actual/autofix-with-feature}/src/main.rs | 0 .../expected/autofix-with-feature}/Cargo.toml | 0 .../expected/autofix-with-feature}/src/main.rs | 0 5 files changed, 15 insertions(+), 2 deletions(-) rename {integration-tests/autofix-with-feature/actual => cli-tests/actual/autofix-with-feature}/Cargo.toml (100%) rename {integration-tests/autofix-with-feature/actual => cli-tests/actual/autofix-with-feature}/src/main.rs (100%) rename {integration-tests/autofix-with-feature/expected => cli-tests/expected/autofix-with-feature}/Cargo.toml (100%) rename {integration-tests/autofix-with-feature/expected => cli-tests/expected/autofix-with-feature}/src/main.rs (100%) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3208173..55f3691 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -50,8 +50,21 @@ jobs: - run: cargo build --release - run: cargo install --path . - run: ls - - run: cd integration-tests/autofix-with-feature/actual && cargo machete --fix || true - - run: cd integration-tests/autofix-with-feature && diff -r expected actual + # The below works, but we need it to instead run with a different structure + # There is now a cli-tests directory, with actual and expected subdirectories + # In each of those is a number of tests we dont know hte names of in advance + # We want to dynamically run the below for each of those, and well as any added in actual + # And then diff the whole directory + # - run: cd integration-tests/autofix-with-feature/actual && cargo machete --fix || true + # - run: cd integration-tests/autofix-with-feature && diff -r expected actual + # Get all directoriies in cli-tests/actual, and for each run cargo-machete --fix, + - run: | + for dir in cli-tests/actual/*; do + if [ -d "$dir" ]; then + cd "$dir" && cargo machete --fix || true + fi + done + - run: cd cli-tests && diff -r expected actual # Code mutably borrowed from https://github.com/EmbarkStudios/cargo-deny/, thanks Embark! release: diff --git a/integration-tests/autofix-with-feature/actual/Cargo.toml b/cli-tests/actual/autofix-with-feature/Cargo.toml similarity index 100% rename from integration-tests/autofix-with-feature/actual/Cargo.toml rename to cli-tests/actual/autofix-with-feature/Cargo.toml diff --git a/integration-tests/autofix-with-feature/actual/src/main.rs b/cli-tests/actual/autofix-with-feature/src/main.rs similarity index 100% rename from integration-tests/autofix-with-feature/actual/src/main.rs rename to cli-tests/actual/autofix-with-feature/src/main.rs diff --git a/integration-tests/autofix-with-feature/expected/Cargo.toml b/cli-tests/expected/autofix-with-feature/Cargo.toml similarity index 100% rename from integration-tests/autofix-with-feature/expected/Cargo.toml rename to cli-tests/expected/autofix-with-feature/Cargo.toml diff --git a/integration-tests/autofix-with-feature/expected/src/main.rs b/cli-tests/expected/autofix-with-feature/src/main.rs similarity index 100% rename from integration-tests/autofix-with-feature/expected/src/main.rs rename to cli-tests/expected/autofix-with-feature/src/main.rs From 3cc1675dfd21e5c3b45381a26d681dfc27317f68 Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Mon, 18 Mar 2024 12:14:10 +0000 Subject: [PATCH 12/13] fixed indentation --- .github/workflows/main.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 55f3691..bf26426 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -59,11 +59,11 @@ jobs: # - run: cd integration-tests/autofix-with-feature && diff -r expected actual # Get all directoriies in cli-tests/actual, and for each run cargo-machete --fix, - run: | - for dir in cli-tests/actual/*; do - if [ -d "$dir" ]; then - cd "$dir" && cargo machete --fix || true - fi - done + for dir in cli-tests/actual/*; do + if [ -d "$dir" ]; then + cd "$dir" && cargo machete --fix || true + fi + done - run: cd cli-tests && diff -r expected actual # Code mutably borrowed from https://github.com/EmbarkStudios/cargo-deny/, thanks Embark! From 2df4a58c8d82127aa28262cdfdd324dbeda28156 Mon Sep 17 00:00:00 2001 From: Noah Jelich <12912633+njelich@users.noreply.github.com> Date: Wed, 27 Mar 2024 11:25:38 +0000 Subject: [PATCH 13/13] fixed minor bug --- .github/workflows/main.yml | 10 +--------- .../actual/feature-named-like-dep-2/Cargo.toml | 16 ++++++++++++++++ .../actual/feature-named-like-dep-2/src/main.rs | 3 +++ .../actual/feature-named-like-dep/Cargo.toml | 14 ++++++++++++++ .../actual/feature-named-like-dep/src/main.rs | 3 +++ .../expected/feature-named-like-dep-2/Cargo.toml | 16 ++++++++++++++++ .../feature-named-like-dep-2/src/main.rs | 3 +++ .../expected/feature-named-like-dep/Cargo.toml | 14 ++++++++++++++ .../expected/feature-named-like-dep/src/main.rs | 3 +++ src/main.rs | 5 ++++- 10 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 cli-tests/actual/feature-named-like-dep-2/Cargo.toml create mode 100644 cli-tests/actual/feature-named-like-dep-2/src/main.rs create mode 100644 cli-tests/actual/feature-named-like-dep/Cargo.toml create mode 100644 cli-tests/actual/feature-named-like-dep/src/main.rs create mode 100644 cli-tests/expected/feature-named-like-dep-2/Cargo.toml create mode 100644 cli-tests/expected/feature-named-like-dep-2/src/main.rs create mode 100644 cli-tests/expected/feature-named-like-dep/Cargo.toml create mode 100644 cli-tests/expected/feature-named-like-dep/src/main.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bf26426..29d9c6b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -11,6 +11,7 @@ on: jobs: ci: + name: CI env: RUST_BACKTRACE: 1 runs-on: ubuntu-latest @@ -49,15 +50,6 @@ jobs: components: clippy, rustfmt - run: cargo build --release - run: cargo install --path . - - run: ls - # The below works, but we need it to instead run with a different structure - # There is now a cli-tests directory, with actual and expected subdirectories - # In each of those is a number of tests we dont know hte names of in advance - # We want to dynamically run the below for each of those, and well as any added in actual - # And then diff the whole directory - # - run: cd integration-tests/autofix-with-feature/actual && cargo machete --fix || true - # - run: cd integration-tests/autofix-with-feature && diff -r expected actual - # Get all directoriies in cli-tests/actual, and for each run cargo-machete --fix, - run: | for dir in cli-tests/actual/*; do if [ -d "$dir" ]; then diff --git a/cli-tests/actual/feature-named-like-dep-2/Cargo.toml b/cli-tests/actual/feature-named-like-dep-2/Cargo.toml new file mode 100644 index 0000000..27e1088 --- /dev/null +++ b/cli-tests/actual/feature-named-like-dep-2/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "just-unused" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +log = "0.4.14" + +[features] +default = ["std"] +std = ["log/std", "other"] +dontlog = [] +log = [] +other = ["log", "dontlog"] diff --git a/cli-tests/actual/feature-named-like-dep-2/src/main.rs b/cli-tests/actual/feature-named-like-dep-2/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/cli-tests/actual/feature-named-like-dep-2/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/cli-tests/actual/feature-named-like-dep/Cargo.toml b/cli-tests/actual/feature-named-like-dep/Cargo.toml new file mode 100644 index 0000000..f722449 --- /dev/null +++ b/cli-tests/actual/feature-named-like-dep/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "just-unused" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +log = "0.4.14" + +[features] +default = ["std"] +std = ["log/std", "log"] +log = [] diff --git a/cli-tests/actual/feature-named-like-dep/src/main.rs b/cli-tests/actual/feature-named-like-dep/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/cli-tests/actual/feature-named-like-dep/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/cli-tests/expected/feature-named-like-dep-2/Cargo.toml b/cli-tests/expected/feature-named-like-dep-2/Cargo.toml new file mode 100644 index 0000000..27e1088 --- /dev/null +++ b/cli-tests/expected/feature-named-like-dep-2/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "just-unused" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +log = "0.4.14" + +[features] +default = ["std"] +std = ["log/std", "other"] +dontlog = [] +log = [] +other = ["log", "dontlog"] diff --git a/cli-tests/expected/feature-named-like-dep-2/src/main.rs b/cli-tests/expected/feature-named-like-dep-2/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/cli-tests/expected/feature-named-like-dep-2/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/cli-tests/expected/feature-named-like-dep/Cargo.toml b/cli-tests/expected/feature-named-like-dep/Cargo.toml new file mode 100644 index 0000000..f722449 --- /dev/null +++ b/cli-tests/expected/feature-named-like-dep/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "just-unused" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +log = "0.4.14" + +[features] +default = ["std"] +std = ["log/std", "log"] +log = [] diff --git a/cli-tests/expected/feature-named-like-dep/src/main.rs b/cli-tests/expected/feature-named-like-dep/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/cli-tests/expected/feature-named-like-dep/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/src/main.rs b/src/main.rs index 78f9858..4a4551f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -277,7 +277,10 @@ fn remove_dependencies(manifest: &str, dependencies_list: &[String]) -> anyhow:: if let Some(deps) = deps.as_array_mut() { deps.retain(|dep| { if let Some(dep) = dep.as_str() { - !dependencies_list.iter().any(|d| dep.contains(d)) + !dependencies_list.iter().any(|d| { + let prefix = d.to_string() + "/"; + dep.contains(&prefix) + }) } else { true }