aboutsummaryrefslogtreecommitdiff
path: root/dev_tools
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-20 16:07:09 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-20 16:07:09 +0800
commit53c65ff60f87ab799772c95442fa0a27c45551e4 (patch)
treedb40b7fa905d9948ec1fcaf14b7dc8b078d3f620 /dev_tools
parente7fcf19b135e515658aea8c8f4ebce17686318d5 (diff)
Add clippy scripts and apply clippy suggestions
Diffstat (limited to 'dev_tools')
-rwxr-xr-xdev_tools/scripts/clippy-all.sh7
-rwxr-xr-xdev_tools/scripts/clippy-fix-all.sh7
-rw-r--r--dev_tools/src/bin/refresh-docs.rs26
3 files changed, 27 insertions, 13 deletions
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()
}
}