aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart/src
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-05-08 23:45:50 +0900
committernsfisis <nsfisis@gmail.com>2026-05-08 23:45:50 +0900
commit059d528b76914aaefebc42705984586ebb1c607a (patch)
treece8f196570273621c2dab859e1c763fa41d54fb0 /crates/mozart/src
parent18d5a78fee75e0a466355e6edfb634d8f7a7565a (diff)
downloadphp-mozart-059d528b76914aaefebc42705984586ebb1c607a.tar.gz
php-mozart-059d528b76914aaefebc42705984586ebb1c607a.tar.zst
php-mozart-059d528b76914aaefebc42705984586ebb1c607a.zip
refactor(advisory): fix clippy warnings
Implement std::str::FromStr for AuditFormat and AbandonedHandling instead of ad-hoc from_str methods (resolves should_implement_trait). Group Auditor::audit() parameters into AuditOptions to resolve too_many_arguments.
Diffstat (limited to 'crates/mozart/src')
-rw-r--r--crates/mozart/src/commands/audit.rs38
-rw-r--r--crates/mozart/src/commands/require.rs67
2 files changed, 55 insertions, 50 deletions
diff --git a/crates/mozart/src/commands/audit.rs b/crates/mozart/src/commands/audit.rs
index 74cb536..df0e5a9 100644
--- a/crates/mozart/src/commands/audit.rs
+++ b/crates/mozart/src/commands/audit.rs
@@ -4,7 +4,7 @@ use clap::Args;
use indexmap::IndexMap;
use mozart_core::advisory::{AbandonedHandling, AuditConfig, AuditFormat};
use mozart_core::composer::Composer;
-use mozart_registry::advisory::{Auditor, PackageInfo};
+use mozart_registry::advisory::{AuditOptions, Auditor, PackageInfo};
use mozart_registry::cache::{Cache, build_cache_config};
use mozart_registry::repository::RepositorySet;
@@ -50,9 +50,9 @@ pub async fn execute(
// Resolve format: CLI arg > config default (table)
let format = match args.format.as_deref() {
- Some(f) => match AuditFormat::from_str(f) {
- Some(fmt) => fmt,
- None => anyhow::bail!(
+ Some(f) => match f.parse::<AuditFormat>() {
+ Ok(fmt) => fmt,
+ Err(_) => anyhow::bail!(
"Invalid format \"{f}\". Supported formats: table, plain, json, summary"
),
},
@@ -61,9 +61,9 @@ pub async fn execute(
// Resolve --abandoned: CLI > config
let abandoned = match args.abandoned.as_deref() {
- Some(s) => match AbandonedHandling::from_str(s) {
- Some(h) => h,
- None => anyhow::bail!(
+ Some(s) => match s.parse::<AbandonedHandling>() {
+ Ok(h) => h,
+ Err(_) => anyhow::bail!(
"Invalid abandoned value \"{s}\". Supported values: ignore, report, fail"
),
},
@@ -98,13 +98,15 @@ pub async fn execute(
console,
&repo_set,
&packages,
- format,
- false,
- &audit_config.ignore_list_for_audit,
- abandoned,
- &ignore_severities,
- ignore_unreachable,
- &audit_config.ignore_abandoned_for_audit,
+ &AuditOptions {
+ format,
+ warning_only: false,
+ ignore_list: &audit_config.ignore_list_for_audit,
+ abandoned,
+ ignored_severities: &ignore_severities,
+ ignore_unreachable,
+ ignore_abandoned: &audit_config.ignore_abandoned_for_audit,
+ },
)
.await?;
@@ -460,14 +462,14 @@ mod tests {
#[test]
fn test_invalid_format() {
let format = "xml";
- assert!(AuditFormat::from_str(format).is_none());
+ assert!(format.parse::<AuditFormat>().is_err());
}
#[test]
fn test_valid_formats() {
for fmt in &["table", "plain", "json", "summary"] {
assert!(
- AuditFormat::from_str(fmt).is_some(),
+ fmt.parse::<AuditFormat>().is_ok(),
"format {fmt} should be valid"
);
}
@@ -475,14 +477,14 @@ mod tests {
#[test]
fn test_invalid_abandoned_value() {
- assert!(AbandonedHandling::from_str("maybe").is_none());
+ assert!("maybe".parse::<AbandonedHandling>().is_err());
}
#[test]
fn test_valid_abandoned_values() {
for value in &["ignore", "report", "fail"] {
assert!(
- AbandonedHandling::from_str(value).is_some(),
+ value.parse::<AbandonedHandling>().is_ok(),
"abandoned value {value} should be valid"
);
}
diff --git a/crates/mozart/src/commands/require.rs b/crates/mozart/src/commands/require.rs
index 2b57a6d..39b055f 100644
--- a/crates/mozart/src/commands/require.rs
+++ b/crates/mozart/src/commands/require.rs
@@ -158,12 +158,13 @@ fn revert_composer_file(state: &CommandState, console: &mozart_core::console::Co
}
// Also remove any lock file that was created during this (failed) run
if state.lock_path.exists()
- && let Err(e) = std::fs::remove_file(&state.lock_path) {
- console.write_error(&format!(
- "Warning: Failed to delete {}: {e}",
- state.lock_path.display()
- ));
- }
+ && let Err(e) = std::fs::remove_file(&state.lock_path)
+ {
+ console.write_error(&format!(
+ "Warning: Failed to delete {}: {e}",
+ state.lock_path.display()
+ ));
+ }
} else {
let msg = if state.lock_backup.is_some() {
format!(" and {} to their", state.lock_path.display())
@@ -181,12 +182,13 @@ fn revert_composer_file(state: &CommandState, console: &mozart_core::console::Co
));
}
if let Some(ref lock_content) = state.lock_backup
- && let Err(e) = std::fs::write(&state.lock_path, lock_content) {
- console.write_error(&format!(
- "Warning: Failed to revert {}: {e}",
- state.lock_path.display()
- ));
- }
+ && let Err(e) = std::fs::write(&state.lock_path, lock_content)
+ {
+ console.write_error(&format!(
+ "Warning: Failed to revert {}: {e}",
+ state.lock_path.display()
+ ));
+ }
}
}
@@ -408,26 +410,27 @@ async fn do_update(
// if (!$this->firstRequire && $composer->getLocker()->isLocked())
// $install->setUpdateAllowList(array_keys($requirements));
if !state.first_require
- && let Some(ref lock) = old_lock {
- let with_deps = args.with_dependencies || args.update_with_dependencies;
- let with_all_deps = args.with_all_dependencies || args.update_with_all_dependencies;
- let newly_required: Vec<String> =
- additions.iter().map(|(name, _, _)| name.clone()).collect();
- let repo_requires = super::update::collect_repo_requires(&raw.repositories);
- let allow_list = if with_all_deps {
- super::update::expand_with_all_dependencies(newly_required, lock, &repo_requires)
- } else if with_deps {
- super::update::expand_with_direct_dependencies(
- newly_required,
- lock,
- &IndexSet::new(),
- &repo_requires,
- )
- } else {
- additions.iter().map(|(name, _, _)| name.clone()).collect()
- };
- resolved = super::update::apply_partial_update(resolved, lock, &allow_list);
- }
+ && let Some(ref lock) = old_lock
+ {
+ let with_deps = args.with_dependencies || args.update_with_dependencies;
+ let with_all_deps = args.with_all_dependencies || args.update_with_all_dependencies;
+ let newly_required: Vec<String> =
+ additions.iter().map(|(name, _, _)| name.clone()).collect();
+ let repo_requires = super::update::collect_repo_requires(&raw.repositories);
+ let allow_list = if with_all_deps {
+ super::update::expand_with_all_dependencies(newly_required, lock, &repo_requires)
+ } else if with_deps {
+ super::update::expand_with_direct_dependencies(
+ newly_required,
+ lock,
+ &IndexSet::new(),
+ &repo_requires,
+ )
+ } else {
+ additions.iter().map(|(name, _, _)| name.clone()).collect()
+ };
+ resolved = super::update::apply_partial_update(resolved, lock, &allow_list);
+ }
let composer_json_content = if args.dry_run {
package::to_json_pretty(raw)?