From 62f2fc1e5167c991746b767a073c1b2bea2fb5a3 Mon Sep 17 00:00:00 2001 From: Loong <40141251+wangl-cc@users.noreply.github.com> Date: Sun, 1 Sep 2024 15:46:01 +0100 Subject: [PATCH] chore: fix clippy warnings --- maa-cli/src/config/task/mod.rs | 17 +++++------------ maa-cli/src/run/preset/copilot.rs | 12 +++++------- maa-cli/src/run/preset/fight.rs | 2 +- maa-cli/src/run/preset/mod.rs | 8 ++++---- maa-cli/src/run/preset/reclamation.rs | 2 +- maa-cli/src/run/preset/roguelike.rs | 2 +- maa-cli/src/value/mod.rs | 14 -------------- 7 files changed, 17 insertions(+), 40 deletions(-) diff --git a/maa-cli/src/config/task/mod.rs b/maa-cli/src/config/task/mod.rs index 9558c94e..7434ecc1 100644 --- a/maa-cli/src/config/task/mod.rs +++ b/maa-cli/src/config/task/mod.rs @@ -76,33 +76,32 @@ impl Task { pub fn new(task_type: TaskType, params: MAAValue) -> Self { Self { name: None, - task_type: task_type.into(), + task_type, strategy: Strategy::default(), params, variants: Vec::new(), } } + #[cfg(test)] pub fn with_name(mut self, name: String) -> Self { self.name = Some(name); self } - pub fn with_params(mut self, params: MAAValue) -> Self { - self.params = params; - self - } - + #[cfg(test)] pub fn with_strategy(mut self, strategy: Strategy) -> Self { self.strategy = strategy; self } + #[cfg(test)] pub fn with_variants(mut self, variants: Vec) -> Self { self.variants = variants; self } + #[cfg(test)] pub fn push_variant(&mut self, variants: TaskVariant) -> &mut Self { self.variants.push(variants); self @@ -345,12 +344,6 @@ mod tests { use crate::object; - impl TaskConfig { - pub fn tasks(&self) -> &[Task] { - &self.tasks - } - } - mod task { use super::*; diff --git a/maa-cli/src/run/preset/copilot.rs b/maa-cli/src/run/preset/copilot.rs index 8584f33e..d15686be 100644 --- a/maa-cli/src/run/preset/copilot.rs +++ b/maa-cli/src/run/preset/copilot.rs @@ -60,7 +60,7 @@ impl super::IntoTaskConfig for CopilotParams { let mut copilot_files = Vec::new(); for uri in &self.uri_list { - let copilot_file = CopilotFile::from_uri(&uri)?; + let copilot_file = CopilotFile::from_uri(uri)?; copilot_file.push_path_to(&mut copilot_files, copilot_dir)?; } @@ -217,12 +217,10 @@ impl<'a> CopilotFile<'a> { n if n > 20000 => Ok(CopilotFile::RemoteSet(n)), n => bail!("Invalid code {n}"), } + } else if let Some(code) = trimmed.strip_prefix("file://") { + Ok(CopilotFile::Local(Path::new(code))) } else { - if let Some(code) = trimmed.strip_prefix("file://") { - Ok(CopilotFile::Local(Path::new(code))) - } else { - Ok(CopilotFile::Local(Path::new(trimmed))) - } + Ok(CopilotFile::Local(Path::new(trimmed))) } } @@ -624,7 +622,7 @@ mod tests { let ids = [40051, 40052, 40053, 40055, 40056, 40057, 40058, 40059]; ids.iter() - .map(|id| test_root.join(format!("{}.json", id)).into()) + .map(|id| test_root.join(format!("{}.json", id))) .collect::>() } ); diff --git a/maa-cli/src/run/preset/fight.rs b/maa-cli/src/run/preset/fight.rs index fc8c3942..caf74177 100644 --- a/maa-cli/src/run/preset/fight.rs +++ b/maa-cli/src/run/preset/fight.rs @@ -119,7 +119,7 @@ impl TryFrom for MAAValue { params.insert("DrGrandet", args.dr_grandet); - return Ok(params); + Ok(params) } } diff --git a/maa-cli/src/run/preset/mod.rs b/maa-cli/src/run/preset/mod.rs index 62fe9e45..518c12ce 100644 --- a/maa-cli/src/run/preset/mod.rs +++ b/maa-cli/src/run/preset/mod.rs @@ -64,7 +64,7 @@ impl From for MAAValue { value.maybe_insert("account_name", args.account_name); - return value; + value } } @@ -84,7 +84,7 @@ impl From for MAAValue { fn from(args: CloseDownParams) -> Self { let mut value = MAAValue::new(); value.insert("client_type", args.client.to_str()); - return value; + value } } @@ -129,7 +129,7 @@ mod tests { { let command = parse_from(args).command; match command { - Command::StartUp { params, .. } => params.try_into().unwrap(), + Command::StartUp { params, .. } => params.into(), _ => panic!("Not a StartUp command"), } } @@ -163,7 +163,7 @@ mod tests { { let cmd = parse_from(args).command; match cmd { - Command::CloseDown { params, .. } => params.try_into().unwrap(), + Command::CloseDown { params, .. } => params.into(), _ => panic!("Not a CloseDown command"), } } diff --git a/maa-cli/src/run/preset/reclamation.rs b/maa-cli/src/run/preset/reclamation.rs index 06d192d2..7a6a6e8a 100644 --- a/maa-cli/src/run/preset/reclamation.rs +++ b/maa-cli/src/run/preset/reclamation.rs @@ -46,7 +46,7 @@ impl From for MAAValue { value.insert("theme", params.theme.to_str()); value.insert("mode", params.mode); value.maybe_insert("tool_to_craft", params.tool_to_craft); - return value; + value } } diff --git a/maa-cli/src/run/preset/roguelike.rs b/maa-cli/src/run/preset/roguelike.rs index 1e263510..bb92ec17 100644 --- a/maa-cli/src/run/preset/roguelike.rs +++ b/maa-cli/src/run/preset/roguelike.rs @@ -234,7 +234,7 @@ impl TryFrom for MAAValue { _ => {} } - return Ok(value); + Ok(value) } } diff --git a/maa-cli/src/value/mod.rs b/maa-cli/src/value/mod.rs index 83c7fb9f..edf78f9c 100644 --- a/maa-cli/src/value/mod.rs +++ b/maa-cli/src/value/mod.rs @@ -267,20 +267,6 @@ impl MAAValue { } } - /// Set the given key to true if the value is true - pub fn insert_true(&mut self, key: impl Into, value: bool) { - if value { - self.insert(key, value); - } - } - - /// Set the given key to false if the value is false - pub fn insert_false(&mut self, key: impl Into, value: bool) { - if !value { - self.insert(key, value); - } - } - pub fn maybe_insert(&mut self, key: impl Into, value: Option>) { if let Some(value) = value { self.insert(key, value);