Skip to content

Commit b9b38ee

Browse files
committed
[*.rs] clippy
1 parent 3365229 commit b9b38ee

File tree

6 files changed

+18
-23
lines changed

6 files changed

+18
-23
lines changed

cli/src/sync.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ fn process_models_for_openapi(model_dir: &Path) -> AppResult<()> {
108108

109109
// Only process Rust files, skip mod.rs if we want (orphans usually valid, but typically we target struct files)
110110
// dsync generates mod.rs and table files.
111-
if path.extension().map_or(false, |ext| ext == "rs")
112-
&& path.file_name().unwrap() != "mod.rs"
111+
if path.extension().is_some_and(|ext| ext == "rs") && path.file_name().unwrap() != "mod.rs"
113112
{
114113
process_file(path)?;
115114
}

core/src/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn generate_dtos(dtos: &[ParsedStruct]) -> String {
9797
imports.insert("use utoipa::ToSchema;".to_string());
9898

9999
for dto in dtos {
100-
collect_imports(&dto, &mut imports);
100+
collect_imports(dto, &mut imports);
101101
}
102102

103103
// 2. Write Imports
@@ -122,7 +122,7 @@ pub fn generate_dtos(dtos: &[ParsedStruct]) -> String {
122122
///
123123
/// Useful for generating individual snippets or single-struct files.
124124
pub fn generate_dto(dto: &ParsedStruct) -> String {
125-
generate_dtos(&[dto.clone()])
125+
generate_dtos(std::slice::from_ref(dto))
126126
}
127127

128128
/// Helper to generate the body of a single struct (without file-level imports).

core/src/oas.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ fn map_schema_to_rust_type(schema: &RefOr<Schema>, is_required: bool) -> AppResu
248248
let type_str = match schema {
249249
RefOr::Ref(r) => {
250250
let path = &r.ref_location;
251-
path.split('/').last().unwrap_or("Unknown").to_string()
251+
path.split('/').next_back().unwrap_or("Unknown").to_string()
252252
}
253253
RefOr::T(s) => match s {
254254
Schema::Object(obj) => match obj.schema_type {
@@ -310,7 +310,7 @@ fn to_snake_case(s: &str) -> String {
310310

311311
fn derive_handler_name(method: &str, path: &str) -> String {
312312
// GET /users/{id} -> get_users_id
313-
let clean_path = path.replace('{', "").replace('}', "").replace('/', "_");
313+
let clean_path = path.replace(['{', '}'], "").replace('/', "_");
314314
format!(
315315
"{}_{}",
316316
method.to_lowercase(),

core/src/parser.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub fn extract_struct(code: &str, struct_name: &str) -> AppResult<ParsedStruct>
101101
.syntax()
102102
.descendants()
103103
.find_map(|node| {
104-
ast::Struct::cast(node).filter(|s| s.name().map_or(false, |n| n.text() == struct_name))
104+
ast::Struct::cast(node).filter(|s| s.name().is_some_and(|n| n.text() == struct_name))
105105
})
106106
.ok_or_else(|| AppError::General(format!("Struct '{}' not found", struct_name)))?;
107107

@@ -161,14 +161,12 @@ fn extract_doc_comment(node: &SyntaxNode) -> Option<String> {
161161
for child in node.children_with_tokens() {
162162
if child.kind() == SyntaxKind::COMMENT {
163163
let text = child.to_string();
164-
if text.starts_with("///") {
165-
let content = &text[3..];
166-
let content = if content.starts_with(' ') {
167-
&content[1..]
164+
if let Some(content) = text.strip_prefix("///") {
165+
lines.push(if let Some(stripped) = text.strip_prefix(' ') {
166+
stripped.to_owned()
168167
} else {
169-
content
170-
};
171-
lines.push(content.to_string());
168+
content.to_owned()
169+
});
172170
}
173171
}
174172
}

core/src/patcher.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@ pub fn add_struct_field(
5858
insert_pos = prev.text_range().start().into();
5959
}
6060
}
61-
} else {
62-
if let Some(prev) = r_curly.prev_token() {
63-
if prev.kind() == SyntaxKind::WHITESPACE && prev.text().ends_with('\n') {
64-
prefix_newline = false;
65-
}
61+
} else if let Some(prev) = r_curly.prev_token() {
62+
if prev.kind() == SyntaxKind::WHITESPACE && prev.text().ends_with('\n') {
63+
prefix_newline = false;
6664
}
6765
}
6866

@@ -111,7 +109,7 @@ pub fn modify_struct_field_type(
111109

112110
let field = field_list
113111
.fields()
114-
.find(|f| f.name().map_or(false, |n| n.text() == field_name))
112+
.find(|f| f.name().is_some_and(|n| n.text() == field_name))
115113
.ok_or_else(|| {
116114
AppError::General(format!(
117115
"Field '{}' not found in struct '{}'",
@@ -169,7 +167,7 @@ pub fn add_derive(source: &str, struct_name: &str, derive_trait: &str) -> AppRes
169167
let patch = if needs_comma {
170168
format!(", {}", derive_trait)
171169
} else {
172-
format!("{}", derive_trait)
170+
derive_trait.to_string()
173171
};
174172

175173
new_source.insert_str(insert_pos, &patch);
@@ -294,7 +292,7 @@ fn find_struct(file: &SourceFile, name: &str) -> AppResult<ast::Struct> {
294292
file.syntax()
295293
.descendants()
296294
.filter_map(ast::Struct::cast)
297-
.find(|s| s.name().map_or(false, |n| n.text() == name))
295+
.find(|s| s.name().is_some_and(|n| n.text() == name))
298296
.ok_or_else(|| AppError::General(format!("Struct '{}' not found in source file", name)))
299297
}
300298

core/src/route_generator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub fn register_routes(
5656
.syntax()
5757
.descendants()
5858
.find_map(ast::Fn::cast)
59-
.filter(|f| f.name().map_or(false, |n| n.text() == "config"));
59+
.filter(|f| f.name().is_some_and(|n| n.text() == "config"));
6060

6161
if let Some(func) = config_fn {
6262
let body = func

0 commit comments

Comments
 (0)