Skip to content

Commit 6f52cf6

Browse files
committed
fix uninlined format args
1 parent e8a60a7 commit 6f52cf6

File tree

2 files changed

+24
-31
lines changed

2 files changed

+24
-31
lines changed

contrib/tools/config-docs-generator/src/extract_docs.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn main() -> Result<()> {
134134
// Write the extracted docs to file
135135
fs::write(output_file, serde_json::to_string_pretty(&config_docs)?)?;
136136

137-
println!("Successfully extracted documentation to {}", output_file);
137+
println!("Successfully extracted documentation to {output_file}");
138138
println!(
139139
"Found {} structs with documentation",
140140
config_docs.structs.len()
@@ -184,8 +184,7 @@ fn generate_rustdoc_json(package: &str) -> Result<serde_json::Value> {
184184
// Generate rustdoc for additional crates that might contain referenced constants
185185
for additional_crate in &additional_crates {
186186
let error_msg = format!(
187-
"Failed to run cargo rustdoc command for {}",
188-
additional_crate
187+
"Failed to run cargo rustdoc command for {additional_crate}"
189188
);
190189
let output = StdCommand::new("cargo")
191190
.args([
@@ -209,8 +208,7 @@ fn generate_rustdoc_json(package: &str) -> Result<serde_json::Value> {
209208
if !output.status.success() {
210209
let stderr = String::from_utf8_lossy(&output.stderr);
211210
eprintln!(
212-
"Warning: Failed to generate rustdoc for {}: {}",
213-
additional_crate, stderr
211+
"Warning: Failed to generate rustdoc for {additional_crate}: {stderr}"
214212
);
215213
}
216214
}
@@ -225,7 +223,7 @@ fn generate_rustdoc_json(package: &str) -> Result<serde_json::Value> {
225223
};
226224

227225
// Read the generated JSON file - rustdoc generates it based on library name
228-
let json_file_path = format!("{}/doc/{}.json", rustdoc_target_dir, lib_name);
226+
let json_file_path = format!("{rustdoc_target_dir}/doc/{lib_name}.json");
229227
let json_content = std::fs::read_to_string(json_file_path)
230228
.context("Failed to read generated rustdoc JSON file")?;
231229

@@ -464,8 +462,7 @@ fn parse_field_documentation(
464462
"" => false, // Empty string defaults to false
465463
text => text.parse::<bool>().unwrap_or_else(|_| {
466464
eprintln!(
467-
"Warning: Invalid @required value '{}' for field '{}', defaulting to false",
468-
text, field_name
465+
"Warning: Invalid @required value '{text}' for field '{field_name}', defaulting to false"
469466
);
470467
false
471468
}),
@@ -632,14 +629,14 @@ fn parse_folded_block_scalar(lines: &[&str], _base_indent: usize) -> String {
632629
// Remove trailing empty lines but preserve a single trailing newline if content exists
633630
let trimmed = result.trim_end_matches('\n');
634631
if !trimmed.is_empty() && result.ends_with('\n') {
635-
format!("{}\n", trimmed)
632+
format!("{trimmed}\n")
636633
} else {
637634
trimmed.to_string()
638635
}
639636
}
640637

641638
fn extract_annotation(metadata_section: &str, annotation_name: &str) -> Option<String> {
642-
let annotation_pattern = format!("@{}:", annotation_name);
639+
let annotation_pattern = format!("@{annotation_name}:");
643640

644641
if let Some(_start_pos) = metadata_section.find(&annotation_pattern) {
645642
// Split the metadata section into lines for processing
@@ -820,7 +817,7 @@ fn resolve_constant_reference(
820817
let additional_crate_libs = ["stacks_common"]; // Library names for additional crates
821818

822819
for lib_name in &additional_crate_libs {
823-
let json_file_path = format!("target/rustdoc-json/doc/{}.json", lib_name);
820+
let json_file_path = format!("target/rustdoc-json/doc/{lib_name}.json");
824821
if let Ok(json_content) = std::fs::read_to_string(&json_file_path) {
825822
if let Ok(rustdoc_json) = serde_json::from_str::<serde_json::Value>(&json_content) {
826823
if let Some(index) = get_json_object(&rustdoc_json, &["index"]) {

contrib/tools/config-docs-generator/src/generate_markdown.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn main() -> Result<()> {
103103
let mappings_path = matches.get_one::<String>("mappings").unwrap();
104104

105105
let input_content = fs::read_to_string(input_path)
106-
.with_context(|| format!("Failed to read input JSON file: {}", input_path))?;
106+
.with_context(|| format!("Failed to read input JSON file: {input_path}"))?;
107107

108108
let config_docs: ConfigDocs =
109109
serde_json::from_str(&input_content).with_context(|| "Failed to parse input JSON")?;
@@ -113,27 +113,24 @@ fn main() -> Result<()> {
113113
let markdown = generate_markdown(&config_docs, template_path, &custom_mappings)?;
114114

115115
fs::write(output_path, markdown)
116-
.with_context(|| format!("Failed to write output file: {}", output_path))?;
116+
.with_context(|| format!("Failed to write output file: {output_path}"))?;
117117

118118
println!(
119-
"Successfully generated Markdown documentation at {}",
120-
output_path
119+
"Successfully generated Markdown documentation at {output_path}"
121120
);
122121
Ok(())
123122
}
124123

125124
fn load_section_name_mappings(mappings_file: &str) -> Result<HashMap<String, String>> {
126125
let content = fs::read_to_string(mappings_file).with_context(|| {
127126
format!(
128-
"Failed to read section name mappings file: {}",
129-
mappings_file
127+
"Failed to read section name mappings file: {mappings_file}"
130128
)
131129
})?;
132130

133131
let mappings: HashMap<String, String> = serde_json::from_str(&content).with_context(|| {
134132
format!(
135-
"Failed to parse section name mappings JSON: {}",
136-
mappings_file
133+
"Failed to parse section name mappings JSON: {mappings_file}"
137134
)
138135
})?;
139136

@@ -142,14 +139,14 @@ fn load_section_name_mappings(mappings_file: &str) -> Result<HashMap<String, Str
142139

143140
fn load_template(template_path: &str) -> Result<String> {
144141
fs::read_to_string(template_path)
145-
.with_context(|| format!("Failed to read template file: {}", template_path))
142+
.with_context(|| format!("Failed to read template file: {template_path}"))
146143
}
147144

148145
fn render_template(template: &str, variables: HashMap<String, String>) -> String {
149146
let mut result = template.to_string();
150147

151148
for (key, value) in variables {
152-
let placeholder = format!("{{{{{}}}}}", key);
149+
let placeholder = format!("{{{{{key}}}}}");
153150
result = result.replace(&placeholder, &value);
154151
}
155152

@@ -245,7 +242,7 @@ fn generate_struct_section(
245242
custom_mappings: &HashMap<String, String>,
246243
) -> Result<()> {
247244
let section_name = struct_to_section_name(&struct_doc.name, custom_mappings);
248-
output.push_str(&format!("## {}\n\n", section_name));
245+
output.push_str(&format!("## {section_name}\n\n"));
249246

250247
// Add struct description if available
251248
if let Some(description) = &struct_doc.description {
@@ -365,7 +362,7 @@ fn generate_field_row(
365362

366363
// Add deprecation warning if present
367364
if let Some(deprecated) = &field.deprecated {
368-
description_parts.push(format!("<br><br>**⚠️ DEPRECATED:** {}", deprecated));
365+
description_parts.push(format!("<br><br>**⚠️ DEPRECATED:** {deprecated}"));
369366
}
370367

371368
// Add TOML example if present
@@ -385,16 +382,15 @@ fn generate_field_row(
385382
.replace('\n', "&#10;"); // Use HTML entity for newline to avoid <br> conversion
386383

387384
let example_section = format!(
388-
"<br><br>**Example:**<br><pre><code>{}</code></pre>",
389-
escaped_example // HTML entities will be rendered as newlines by <pre>
385+
"<br><br>**Example:**<br><pre><code>{escaped_example}</code></pre>" // HTML entities will be rendered as newlines by <pre>
390386
);
391387
description_parts.push(example_section);
392388
}
393389

394390
// Add units information if present
395391
if let Some(units) = &field.units {
396392
let units_text = process_intralinks_with_context(units, global_context, struct_name);
397-
description_parts.push(format!("<br><br>**Units:** {}", units_text));
393+
description_parts.push(format!("<br><br>**Units:** {units_text}"));
398394
}
399395

400396
let description = if description_parts.is_empty() {
@@ -513,11 +509,11 @@ fn process_reference(
513509
// Check if it's the same struct or different struct
514510
if ref_struct_name == current_struct_name {
515511
// Same struct: just show field name
516-
return format!("[{}](#{}) ", field_name, anchor_id);
512+
return format!("[{field_name}](#{anchor_id}) ");
517513
} else {
518514
// Different struct: show [config_section].field_name as a link
519515
let config_section = section_name.trim_start_matches('[').trim_end_matches(']');
520-
return format!("[[{}].{}](#{}) ", config_section, field_name, anchor_id);
516+
return format!("[[{config_section}].{field_name}](#{anchor_id}) ");
521517
}
522518
}
523519
}
@@ -540,11 +536,11 @@ fn process_reference(
540536
// Check if it's the same struct or different struct
541537
if field_struct_name == current_struct_name {
542538
// Same struct: just show field name
543-
return format!("[{}](#{}) ", reference, anchor_id);
539+
return format!("[{reference}](#{anchor_id}) ");
544540
} else {
545541
// Different struct: show [config_section].field_name as a link
546542
let config_section = section_name.trim_start_matches('[').trim_end_matches(']');
547-
return format!("[[{}].{}](#{}) ", config_section, reference, anchor_id);
543+
return format!("[[{config_section}].{reference}](#{anchor_id}) ");
548544
}
549545
}
550546
}
@@ -577,7 +573,7 @@ fn process_hierarchical_lists(
577573
let processed_content =
578574
process_intralinks_with_context(content, global_context, struct_name);
579575

580-
result.push(format!("{}{}", indent_html, processed_content));
576+
result.push(format!("{indent_html}{processed_content}"));
581577
} else {
582578
// Process intra-links in non-bullet lines too
583579
let processed_line = process_intralinks_with_context(line, global_context, struct_name);

0 commit comments

Comments
 (0)