From 7acb82b29fe25144c5082c009256bfb0e51e0abd Mon Sep 17 00:00:00 2001 From: Trim21 Date: Fri, 27 Dec 2024 09:06:22 +0800 Subject: [PATCH] fix lint warning --- dev/src/generate/binding_python.rs | 23 +++++++++-------------- dev/src/generate/parser.rs | 14 ++++++-------- 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/dev/src/generate/binding_python.rs b/dev/src/generate/binding_python.rs index 4660d4f572c3..a95609b8e772 100644 --- a/dev/src/generate/binding_python.rs +++ b/dev/src/generate/binding_python.rs @@ -19,9 +19,9 @@ use crate::generate::parser::Services; use anyhow::Result; use askama::Template; use itertools::Itertools; +use std::fs; use std::path::PathBuf; use std::process::Command; -use std::{fs, iter}; // bring trait in scope use super::parser::{ConfigType, Service}; @@ -49,7 +49,7 @@ pub fn generate(project_root: PathBuf, services: &Services) -> Result<()> { .filter(|x| enabled_service(x.0.as_str())), ); - for mut srv in &mut v { + for srv in &mut v { srv.1.config = srv .1 .config @@ -63,12 +63,6 @@ pub fn generate(project_root: PathBuf, services: &Services) -> Result<()> { let tmpl = PythonTemplate { services: v }; - // for (srv, config) in services.clone().into_iter() { - // for f in config.config { -// f.deprecated.is_some() - // } - // } - let t = tmpl.render().expect("should render template"); let output_file: String = project_root @@ -82,7 +76,8 @@ pub fn generate(project_root: PathBuf, services: &Services) -> Result<()> { Command::new("ruff") .arg("format") .arg(output_file) - .output()?; + .output() + .expect("failed to run ruff"); Ok(()) } @@ -91,23 +86,23 @@ impl ConfigType { pub fn python_type(&self) -> String { match self { ConfigType::Bool => { - return "_bool".into(); + "_bool".into() } ConfigType::Duration => { - return "_duration".into(); + "_duration".into() } ConfigType::I64 | ConfigType::Usize | ConfigType::U64 | ConfigType::U32 | ConfigType::U16 => { - return "_int".into(); + "_int".into() } ConfigType::Vec => { - return "_strings".into(); + "_strings".into() } ConfigType::String => { - return "str".into(); + "str".into() } } } diff --git a/dev/src/generate/parser.rs b/dev/src/generate/parser.rs index 6a265f2f2c14..2f721d88e196 100644 --- a/dev/src/generate/parser.rs +++ b/dev/src/generate/parser.rs @@ -183,7 +183,7 @@ impl ServiceParser { let mut config = Vec::with_capacity(config_struct.fields.len()); for field in config_struct.fields { - let field = self.parse_field(field)?; + let field = Self::parse_field(field)?; config.push(field); } @@ -192,13 +192,13 @@ impl ServiceParser { } /// TODO: Add comment parse support. - fn parse_field(&self, field: Field) -> Result { + fn parse_field(field: Field) -> Result { let name = field .ident .clone() .ok_or_else(|| anyhow!("field name is missing for {:?}", &field))?; - let deprecated = self.deprecated_note(&field); + let deprecated = Self::deprecated_note(&field); let (cfg_type, optional) = match &field.ty { Type::Path(TypePath { path, .. }) => { @@ -246,7 +246,7 @@ impl ServiceParser { }) } - fn deprecated_note(&self, field: &Field) -> Option { + fn deprecated_note(field: &Field) -> Option { for attr in &field.attrs { if !attr.path().is_ident("deprecated") { continue; @@ -261,9 +261,7 @@ impl ServiceParser { for (index, token) in tokens.iter().enumerate() { let ident = match token { proc_macro2::TokenTree::Ident(ident) => ident, - _ => { - continue; - } + _ => continue, }; if ident == "note" { @@ -277,7 +275,7 @@ impl ServiceParser { } } - return None; + None } }