From 53c65ff60f87ab799772c95442fa0a27c45551e4 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 20 Apr 2026 16:07:09 +0800 Subject: Add clippy scripts and apply clippy suggestions --- dev_tools/scripts/clippy-all.sh | 7 +++++++ dev_tools/scripts/clippy-fix-all.sh | 7 +++++++ dev_tools/src/bin/refresh-docs.rs | 26 +++++++++++++------------- mingling_cli/src/dispatcher_mgr.rs | 8 ++++---- mingling_core/Cargo.toml | 2 +- 5 files changed, 32 insertions(+), 18 deletions(-) create mode 100755 dev_tools/scripts/clippy-all.sh create mode 100755 dev_tools/scripts/clippy-fix-all.sh diff --git a/dev_tools/scripts/clippy-all.sh b/dev_tools/scripts/clippy-all.sh new file mode 100755 index 0000000..09b05ca --- /dev/null +++ b/dev_tools/scripts/clippy-all.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +find . -name "Cargo.toml" -type f | while read -r cargo_file; do + project_dir=$(dirname "$cargo_file") + echo "Run \`cargo clippy\` in \`$project_dir\` ..." + (cd "$project_dir" && cargo clippy) +done diff --git a/dev_tools/scripts/clippy-fix-all.sh b/dev_tools/scripts/clippy-fix-all.sh new file mode 100755 index 0000000..5de1ce8 --- /dev/null +++ b/dev_tools/scripts/clippy-fix-all.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +find . -name "Cargo.toml" -type f | while read -r cargo_file; do + project_dir=$(dirname "$cargo_file") + echo "Run \`cargo clippy\` in \`$project_dir\` ..." + (cd "$project_dir" && cargo clippy --fix --allow-dirty) +done diff --git a/dev_tools/src/bin/refresh-docs.rs b/dev_tools/src/bin/refresh-docs.rs index ae6753a..c94a948 100644 --- a/dev_tools/src/bin/refresh-docs.rs +++ b/dev_tools/src/bin/refresh-docs.rs @@ -1,4 +1,4 @@ -use std::path::PathBuf; +use std::path::Path; use just_fmt::snake_case; use just_template::{Template, tmpl}; @@ -29,12 +29,12 @@ fn gen_example_doc_module() { let mut examples = Vec::new(); if let Ok(entries) = std::fs::read_dir(&example_root) { for entry in entries.flatten() { - if let Ok(file_type) = entry.file_type() { - if file_type.is_dir() { - let example_name = entry.file_name().to_string_lossy().to_string(); - let example_content = ExampleContent::read(&example_name); - examples.push(example_content); - } + if let Ok(file_type) = entry.file_type() + && file_type.is_dir() + { + let example_name = entry.file_name().to_string_lossy().to_string(); + let example_content = ExampleContent::read(&example_name); + examples.push(example_content); } } } @@ -50,7 +50,7 @@ fn gen_example_doc_module() { ) } }); - println!(" Refresh: {}", example.name.to_string()); + println!(" Refresh: {}", example.name); } let template_str = template.to_string(); @@ -110,7 +110,7 @@ impl ExampleContent { } } - fn read_header_and_code(repo: &PathBuf, name: &str) -> (String, String) { + fn read_header_and_code(repo: &Path, name: &str) -> (String, String) { let file_path = repo .join(EXAMPLE_ROOT) .join(name) @@ -122,7 +122,7 @@ impl ExampleContent { let mut code = String::new(); // Collect header lines (starting with //!) - while let Some(line) = lines.next() { + for line in lines.by_ref() { if line.trim_start().starts_with("//!") { let trimmed = line.trim_start_matches("//!"); header.push_str(trimmed); @@ -144,10 +144,10 @@ impl ExampleContent { (header.trim().to_string(), code.trim().to_string()) } - fn read_cargo_toml(repo: &PathBuf, name: &str) -> String { + fn read_cargo_toml(repo: &Path, name: &str) -> String { let file_path = repo.join(EXAMPLE_ROOT).join(name).join("Cargo.toml"); - let content = std::fs::read_to_string(&file_path).unwrap_or_default(); - content + + std::fs::read_to_string(&file_path).unwrap_or_default() } } diff --git a/mingling_cli/src/dispatcher_mgr.rs b/mingling_cli/src/dispatcher_mgr.rs index 93abd23..e754e8c 100644 --- a/mingling_cli/src/dispatcher_mgr.rs +++ b/mingling_cli/src/dispatcher_mgr.rs @@ -14,16 +14,16 @@ dispatcher!("remove.dispatcher", RemoveDispatcherCommand => RemoveDispatcherEntr pub fn parse_add_dispatcher(args: AddDispatcherEntry) -> NextProcess { let picker: Picker = Picker::new(args.inner); let dispatcher_name = picker.pick::(()).unpack_directly().0; - let input = AddDispatcherInput::new(dispatcher_name); - input + + AddDispatcherInput::new(dispatcher_name) } #[chain] pub fn parse_remove_dispatcher(args: RemoveDispatcherEntry) -> NextProcess { let picker: Picker = Picker::new(args.inner); let dispatcher_name = picker.pick::(()).unpack_directly().0; - let input = AddDispatcherInput::new(dispatcher_name); - input + + AddDispatcherInput::new(dispatcher_name) } pack!(AddDispatcherInput = String); diff --git a/mingling_core/Cargo.toml b/mingling_core/Cargo.toml index 7567846..d4b26b8 100644 --- a/mingling_core/Cargo.toml +++ b/mingling_core/Cargo.toml @@ -34,7 +34,7 @@ serde = { version = "1.0", features = ["derive"], optional = true } ron = { version = "0.12.1", optional = true } serde_json = { version = "1", optional = true } serde_yaml = { version = "0.9", optional = true } -toml = { version = "1.1.2+spec-1.1.0", optional = true } +toml = { version = "1.1.2", optional = true } # debug log = { version = "0.4", optional = true } -- cgit