Skip to content

Commit 0f4b80f

Browse files
style: cargo fmt + fix clippy never_loop in catalog-gen
- cargo fmt across files touched in this PR. - Replace the always-breaking while-let in strip_markdown with a straight if-let; same behavior, no clippy warning. cargo clippy --lib --bins is now clean (one expect_used warning, not denied). The remaining clippy errors live in pre-existing tests and examples this PR doesn't touch. Refs #14
1 parent 10f2ba1 commit 0f4b80f

9 files changed

Lines changed: 210 additions & 110 deletions

src/analysis.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -646,10 +646,7 @@ impl SchemaAnalyzer {
646646
// A document may legitimately have no `components.schemas` (e.g. a
647647
// webhooks-only or paths-only spec). Return an empty map in that case
648648
// and let downstream codegen handle "no types to emit" gracefully.
649-
let schemas = spec
650-
.components
651-
.as_ref()
652-
.and_then(|c| c.schemas.as_ref());
649+
let schemas = spec.components.as_ref().and_then(|c| c.schemas.as_ref());
653650
Ok(schemas
654651
.map(|m| {
655652
m.iter()
@@ -3470,10 +3467,11 @@ impl SchemaAnalyzer {
34703467
if no_properties {
34713468
// Check for constraints that would make this a structured type.
34723469
// After J5–J8, these are typed fields rather than `extra` lookups.
3473-
let has_structural_constraints =
3474-
details.required.as_ref()
3475-
.map(|req| req.iter().any(|r| r != "type"))
3476-
.unwrap_or(false)
3470+
let has_structural_constraints = details
3471+
.required
3472+
.as_ref()
3473+
.map(|req| req.iter().any(|r| r != "type"))
3474+
.unwrap_or(false)
34773475
|| details.pattern_properties.is_some()
34783476
|| details.property_names.is_some()
34793477
|| details.min_properties.is_some()
@@ -3701,10 +3699,7 @@ impl SchemaAnalyzer {
37013699
// signal so a `stream: true` parameter and an event-stream
37023700
// content type produce a streaming variant by default.
37033701
if let Some(content) = response.content.as_ref() {
3704-
if content
3705-
.keys()
3706-
.any(|ct| ct.starts_with("text/event-stream"))
3707-
{
3702+
if content.keys().any(|ct| ct.starts_with("text/event-stream")) {
37083703
op_info.supports_streaming = true;
37093704
}
37103705
}

src/bin/catalog-gen.rs

Lines changed: 93 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7878

7979
catalog.totals.object_count = catalog.objects.len();
8080
catalog.totals.field_count = catalog.objects.values().map(|o| o.fields.len()).sum();
81-
catalog.totals.patterned_field_count =
82-
catalog.objects.values().map(|o| o.patterned_fields.len()).sum();
81+
catalog.totals.patterned_field_count = catalog
82+
.objects
83+
.values()
84+
.map(|o| o.patterned_fields.len())
85+
.sum();
8386
catalog.totals.json_schema_keyword_count = catalog.json_schema_2020_12_keywords.len();
8487
catalog.totals.parameter_style_combo_count = catalog.parameter_style_matrix.len();
8588

@@ -301,17 +304,12 @@ fn strip_markdown(s: &str) -> String {
301304
}
302305
']' => {
303306
in_link_text = false;
304-
while let Some(&n) = chars.peek() {
305-
if n == '(' {
306-
chars.next();
307-
for inner in chars.by_ref() {
308-
if inner == ')' {
309-
break;
310-
}
307+
if let Some(&'(') = chars.peek() {
308+
chars.next();
309+
for inner in chars.by_ref() {
310+
if inner == ')' {
311+
break;
311312
}
312-
break;
313-
} else {
314-
break;
315313
}
316314
}
317315
}
@@ -332,27 +330,69 @@ fn strip_markdown(s: &str) -> String {
332330
fn json_schema_2020_12_keywords() -> Vec<String> {
333331
[
334332
// Core
335-
"$schema", "$vocabulary", "$id", "$ref", "$anchor", "$dynamicRef", "$dynamicAnchor",
336-
"$defs", "$comment",
333+
"$schema",
334+
"$vocabulary",
335+
"$id",
336+
"$ref",
337+
"$anchor",
338+
"$dynamicRef",
339+
"$dynamicAnchor",
340+
"$defs",
341+
"$comment",
337342
// Applicators
338-
"allOf", "anyOf", "oneOf", "not", "if", "then", "else", "dependentSchemas",
339-
"prefixItems", "items", "contains", "properties", "patternProperties",
340-
"additionalProperties", "propertyNames",
343+
"allOf",
344+
"anyOf",
345+
"oneOf",
346+
"not",
347+
"if",
348+
"then",
349+
"else",
350+
"dependentSchemas",
351+
"prefixItems",
352+
"items",
353+
"contains",
354+
"properties",
355+
"patternProperties",
356+
"additionalProperties",
357+
"propertyNames",
341358
// Validation
342-
"type", "enum", "const",
343-
"multipleOf", "maximum", "exclusiveMaximum", "minimum", "exclusiveMinimum",
344-
"maxLength", "minLength", "pattern",
345-
"maxItems", "minItems", "uniqueItems", "maxContains", "minContains",
346-
"maxProperties", "minProperties", "required", "dependentRequired",
359+
"type",
360+
"enum",
361+
"const",
362+
"multipleOf",
363+
"maximum",
364+
"exclusiveMaximum",
365+
"minimum",
366+
"exclusiveMinimum",
367+
"maxLength",
368+
"minLength",
369+
"pattern",
370+
"maxItems",
371+
"minItems",
372+
"uniqueItems",
373+
"maxContains",
374+
"minContains",
375+
"maxProperties",
376+
"minProperties",
377+
"required",
378+
"dependentRequired",
347379
// Meta-data
348-
"title", "description", "default", "deprecated", "readOnly", "writeOnly",
380+
"title",
381+
"description",
382+
"default",
383+
"deprecated",
384+
"readOnly",
385+
"writeOnly",
349386
"examples",
350387
// Format
351388
"format",
352389
// Content
353-
"contentEncoding", "contentMediaType", "contentSchema",
390+
"contentEncoding",
391+
"contentMediaType",
392+
"contentSchema",
354393
// Unevaluated
355-
"unevaluatedItems", "unevaluatedProperties",
394+
"unevaluatedItems",
395+
"unevaluatedProperties",
356396
]
357397
.iter()
358398
.map(|s| s.to_string())
@@ -409,12 +449,33 @@ fn parameter_style_matrix() -> Vec<StyleEntry> {
409449

410450
fn appendices() -> Vec<AppendixEntry> {
411451
vec![
412-
AppendixEntry { id: "A", title: "Revision History" },
413-
AppendixEntry { id: "B", title: "Data Type Conversion" },
414-
AppendixEntry { id: "C", title: "Using RFC6570-Based Serialization" },
415-
AppendixEntry { id: "D", title: "Serializing Headers and Cookies" },
416-
AppendixEntry { id: "E", title: "Percent-Encoding and Form Media Types" },
417-
AppendixEntry { id: "F", title: "Base URI Determination and Reference Resolution" },
418-
AppendixEntry { id: "G", title: "Parsing and Resolution Guidance" },
452+
AppendixEntry {
453+
id: "A",
454+
title: "Revision History",
455+
},
456+
AppendixEntry {
457+
id: "B",
458+
title: "Data Type Conversion",
459+
},
460+
AppendixEntry {
461+
id: "C",
462+
title: "Using RFC6570-Based Serialization",
463+
},
464+
AppendixEntry {
465+
id: "D",
466+
title: "Serializing Headers and Cookies",
467+
},
468+
AppendixEntry {
469+
id: "E",
470+
title: "Percent-Encoding and Form Media Types",
471+
},
472+
AppendixEntry {
473+
id: "F",
474+
title: "Base URI Determination and Reference Resolution",
475+
},
476+
AppendixEntry {
477+
id: "G",
478+
title: "Parsing and Resolution Guidance",
479+
},
419480
]
420481
}

src/bin/file-beads.rs

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
110110
if apply {
111111
create_label(&beads.repo, label)?;
112112
} else {
113-
println!(" + label {} ({}, {})", label.name, label.color, label.description);
113+
println!(
114+
" + label {} ({}, {})",
115+
label.name, label.color, label.description
116+
);
114117
}
115118
}
116119

@@ -176,9 +179,15 @@ fn phase_string(v: &serde_yaml::Value) -> String {
176179
}
177180

178181
fn phase_to_epic_map() -> BTreeMap<&'static str, &'static str> {
179-
[("0", "E0"), ("1", "E1"), ("2", "E2"), ("2b", "E2"), ("3", "E3")]
180-
.into_iter()
181-
.collect()
182+
[
183+
("0", "E0"),
184+
("1", "E1"),
185+
("2", "E2"),
186+
("2b", "E2"),
187+
("3", "E3"),
188+
]
189+
.into_iter()
190+
.collect()
182191
}
183192

184193
fn phase_to_label_map() -> BTreeMap<&'static str, &'static str> {
@@ -193,11 +202,7 @@ fn phase_to_label_map() -> BTreeMap<&'static str, &'static str> {
193202
.collect()
194203
}
195204

196-
fn bead_labels(
197-
bead: &Bead,
198-
phase_str: &str,
199-
phase_to_label: &BTreeMap<&str, &str>,
200-
) -> Vec<String> {
205+
fn bead_labels(bead: &Bead, phase_str: &str, phase_to_label: &BTreeMap<&str, &str>) -> Vec<String> {
201206
let mut labels = vec!["bead".to_string()];
202207
if let Some(p) = phase_to_label.get(phase_str) {
203208
labels.push((*p).to_string());
@@ -374,10 +379,8 @@ fn compose_parallel_plan(beads: &[Bead]) -> String {
374379
let parallel = max_parallel_groups(group);
375380
for (i, batch) in parallel.iter().enumerate() {
376381
let ids: Vec<String> = batch.iter().map(|b| b.id.clone()).collect();
377-
let files: BTreeSet<String> = batch
378-
.iter()
379-
.flat_map(|b| b.files.iter().cloned())
380-
.collect();
382+
let files: BTreeSet<String> =
383+
batch.iter().flat_map(|b| b.files.iter().cloned()).collect();
381384
s.push_str(&format!(
382385
"- Batch {}.{}: {} (touches {})\n",
383386
d,
@@ -394,11 +397,7 @@ fn compose_parallel_plan(beads: &[Bead]) -> String {
394397
fn compute_depths(beads: &[Bead]) -> BTreeMap<String, usize> {
395398
let by_id: BTreeMap<&str, &Bead> = beads.iter().map(|b| (b.id.as_str(), b)).collect();
396399
let mut depth = BTreeMap::new();
397-
fn dfs(
398-
id: &str,
399-
by_id: &BTreeMap<&str, &Bead>,
400-
depth: &mut BTreeMap<String, usize>,
401-
) -> usize {
400+
fn dfs(id: &str, by_id: &BTreeMap<&str, &Bead>, depth: &mut BTreeMap<String, usize>) -> usize {
402401
if let Some(d) = depth.get(id) {
403402
return *d;
404403
}
@@ -453,15 +452,23 @@ fn escape_md(s: &str) -> String {
453452
fn create_label(repo: &str, label: &Label) -> Result<(), Box<dyn std::error::Error>> {
454453
let status = Command::new("gh")
455454
.args([
456-
"label", "create", &label.name,
457-
"--repo", repo,
458-
"--color", &label.color,
459-
"--description", &label.description,
455+
"label",
456+
"create",
457+
&label.name,
458+
"--repo",
459+
repo,
460+
"--color",
461+
&label.color,
462+
"--description",
463+
&label.description,
460464
"--force",
461465
])
462466
.status()?;
463467
if !status.success() {
464-
eprintln!("warning: label create failed for {} (may already exist)", label.name);
468+
eprintln!(
469+
"warning: label create failed for {} (may already exist)",
470+
label.name
471+
);
465472
}
466473
Ok(())
467474
}
@@ -474,9 +481,23 @@ fn create_issue(
474481
) -> Result<u64, Box<dyn std::error::Error>> {
475482
// Dedup: skip if an open issue with the same title already exists.
476483
let existing = Command::new("gh")
477-
.args(["issue", "list", "--repo", repo, "--state", "all", "--search", title, "--json", "number,title", "--limit", "20"])
484+
.args([
485+
"issue",
486+
"list",
487+
"--repo",
488+
repo,
489+
"--state",
490+
"all",
491+
"--search",
492+
title,
493+
"--json",
494+
"number,title",
495+
"--limit",
496+
"20",
497+
])
478498
.output()?;
479-
let existing_json: serde_json::Value = serde_json::from_slice(&existing.stdout).unwrap_or(serde_json::Value::Array(vec![]));
499+
let existing_json: serde_json::Value =
500+
serde_json::from_slice(&existing.stdout).unwrap_or(serde_json::Value::Array(vec![]));
480501
if let Some(arr) = existing_json.as_array() {
481502
for v in arr {
482503
if v.get("title").and_then(|t| t.as_str()) == Some(title) {
@@ -490,9 +511,12 @@ fn create_issue(
490511
let mut args = vec![
491512
"issue".to_string(),
492513
"create".to_string(),
493-
"--repo".to_string(), repo.to_string(),
494-
"--title".to_string(), title.to_string(),
495-
"--body".to_string(), body.to_string(),
514+
"--repo".to_string(),
515+
repo.to_string(),
516+
"--title".to_string(),
517+
title.to_string(),
518+
"--body".to_string(),
519+
body.to_string(),
496520
];
497521
for l in labels {
498522
args.push("--label".to_string());
@@ -504,7 +528,11 @@ fn create_issue(
504528
return Err(format!("gh issue create failed: {}", stderr).into());
505529
}
506530
let url = String::from_utf8_lossy(&output.stdout).trim().to_string();
507-
let number = url.rsplit('/').next().and_then(|s| s.parse().ok()).unwrap_or(0);
531+
let number = url
532+
.rsplit('/')
533+
.next()
534+
.and_then(|s| s.parse().ok())
535+
.unwrap_or(0);
508536
println!(" + #{} {}", number, title);
509537
Ok(number)
510538
}

src/cli.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,10 @@ fn parse_oas_version(s: &str) -> Option<(u32, u32)> {
278278
let mut parts = s.split('.');
279279
let major = parts.next()?.parse().ok()?;
280280
let minor_raw = parts.next()?;
281-
let minor_digits: String = minor_raw.chars().take_while(|c| c.is_ascii_digit()).collect();
281+
let minor_digits: String = minor_raw
282+
.chars()
283+
.take_while(|c| c.is_ascii_digit())
284+
.collect();
282285
let minor = minor_digits.parse().ok()?;
283286
Some((major, minor))
284287
}

src/openapi.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,10 @@ impl Schema {
587587
pub fn schema_type(&self) -> Option<&SchemaType> {
588588
match self {
589589
Schema::Typed { schema_type, .. } => Some(schema_type),
590-
Schema::TypedMulti { schema_types, .. } => {
591-
schema_types
592-
.iter()
593-
.find(|t| **t != SchemaType::Null)
594-
.or_else(|| schema_types.first())
595-
}
590+
Schema::TypedMulti { schema_types, .. } => schema_types
591+
.iter()
592+
.find(|t| **t != SchemaType::Null)
593+
.or_else(|| schema_types.first()),
596594
_ => None,
597595
}
598596
}

src/registry_generator.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ impl CodeGenerator {
175175
"HEAD" => quote! { HttpMethod::Head },
176176
"OPTIONS" => quote! { HttpMethod::Options },
177177
"TRACE" => quote! { HttpMethod::Trace },
178-
other => panic!("unsupported HTTP method `{other}` for op `{}`", op.operation_id),
178+
other => panic!(
179+
"unsupported HTTP method `{other}` for op `{}`",
180+
op.operation_id
181+
),
179182
};
180183
let path = &op.path;
181184

0 commit comments

Comments
 (0)