Skip to content

Commit

Permalink
Renaming check-unnecessary-dependencies to check-unused-dependencies
Browse files Browse the repository at this point in the history
Co-authored-by: Ashley Willard <[email protected]>
Co-authored-by: Teal Stannard <[email protected]>
  • Loading branch information
3 people committed Aug 21, 2024
1 parent 9c3204a commit 427d70f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[package]
name = "pks"
version = "0.2.20"
version = "0.2.21"
edition = "2021"
description = "Welcome! Please see https://github.com/rubyatscale/pks for more information!"
license = "MIT"
Expand Down
5 changes: 3 additions & 2 deletions src/packs/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,13 +381,14 @@ pub(crate) fn check_unnecessary_dependencies(
"Found 1 unnecessary dependency".to_string()
} else {
format!(
"Found {} unnecessary dependencies",
"Found {} unused dependencies",
unnecessary_dependencies.len()
)
};
bail!(
"{}. Run command with `--auto-correct` to remove them.",
"{}. Run `{} check-unused-dependencies --auto-correct` to remove them.",
found_message,
bin_locater::packs_bin_name(),
);
}
}
Expand Down
9 changes: 5 additions & 4 deletions src/packs/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ enum Command {
},

#[clap(
about = "Check for dependencies that when removed produce no violations."
about = "Check for dependencies that when removed produce no violations.",
alias = "check-unnecessary-dependencies"
)]
CheckUnnecessaryDependencies {
#[arg(long)]
CheckUnusedDependencies {
#[arg(short, long)]
auto_correct: bool,
},

Expand Down Expand Up @@ -263,7 +264,7 @@ pub fn run() -> anyhow::Result<()> {
packs::validate(&configuration)
// Err("💡 Please use `packs check` to detect dependency cycles and run other configuration validations".into())
}
Command::CheckUnnecessaryDependencies { auto_correct } => {
Command::CheckUnusedDependencies { auto_correct } => {
packs::check_unnecessary_dependencies(&configuration, auto_correct)
}
Command::UpdateDependenciesForConstant { constant } => Ok(
Expand Down
18 changes: 16 additions & 2 deletions tests/check_unnecessary_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ fn assert_check_unused_dependencies(cmd: &str) -> Result<(), Box<dyn Error>> {
"packs/foo depends on packs/bar but does not use it",
))
.stderr(predicate::str::contains(
format!("Error: Found 3 unnecessary dependencies. Run `packs {}| --auto-correct` to remove them.", &cmd),
));
"Error: Found 3 unused dependencies. Run `packs check-unused-dependencies --auto-correct` to remove them.")
);
Ok(())
}

Expand All @@ -35,6 +35,20 @@ fn test_check_unused_dependencies() -> Result<(), Box<dyn Error>> {


fn assert_auto_correct_unused_dependencies(cmd: &str, flag: &str) -> Result<(), Box<dyn Error>> {
common::set_up_fixtures();

let expected_before_autocorrect = [
"enforce_dependencies: true",
"enforce_privacy: true",
"layer: technical_services",
"dependencies:",
"- packs/bar",
"- packs/baz\n",
]
.join("\n");
let foo_package_yml = fs::read_to_string("tests/fixtures/app_with_unnecessary_dependencies/packs/foo/package.yml").unwrap();
assert_eq!(foo_package_yml, expected_before_autocorrect);

Command::cargo_bin("pks")?
.arg("--project-root")
.arg("tests/fixtures/app_with_unnecessary_dependencies")
Expand Down

0 comments on commit 427d70f

Please sign in to comment.