Skip to content

Commit 70d49f6

Browse files
committed
no-mistakes(lint): apply rustfmt and clippy fixes across workspace
1 parent 95e2605 commit 70d49f6

30 files changed

Lines changed: 197 additions & 172 deletions

File tree

crates/codegraph-cpp/src/visitor.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use codegraph_parser_api::{
77
truncate_body_prefix, CallRelation, ClassEntity, ComplexityBuilder, ComplexityMetrics,
88
FunctionEntity, ImplementationRelation, ImportRelation, InheritanceRelation, Parameter,
9-
TraitEntity, BODY_PREFIX_MAX_CHARS,
9+
TraitEntity,
1010
};
1111
use tree_sitter::Node;
1212

@@ -165,7 +165,7 @@ impl<'a> CppVisitor<'a> {
165165
.child_by_field_name("body")
166166
.and_then(|b| b.utf8_text(self.source).ok())
167167
.filter(|t| !t.is_empty())
168-
.map(|t| truncate_body_prefix(t))
168+
.map(truncate_body_prefix)
169169
.map(|t| t.to_string());
170170

171171
let class_entity = ClassEntity {
@@ -323,7 +323,7 @@ impl<'a> CppVisitor<'a> {
323323
.child_by_field_name("body")
324324
.and_then(|b| b.utf8_text(self.source).ok())
325325
.filter(|t| !t.is_empty())
326-
.map(|t| truncate_body_prefix(t))
326+
.map(truncate_body_prefix)
327327
.map(|t| t.to_string());
328328

329329
if is_virtual {
@@ -385,7 +385,7 @@ impl<'a> CppVisitor<'a> {
385385
.child_by_field_name("body")
386386
.and_then(|b| b.utf8_text(self.source).ok())
387387
.filter(|t| !t.is_empty())
388-
.map(|t| truncate_body_prefix(t))
388+
.map(truncate_body_prefix)
389389
.map(|t| t.to_string());
390390

391391
if is_virtual {
@@ -509,7 +509,7 @@ impl<'a> CppVisitor<'a> {
509509
.child_by_field_name("body")
510510
.and_then(|b| b.utf8_text(self.source).ok())
511511
.filter(|t| !t.is_empty())
512-
.map(|t| truncate_body_prefix(t))
512+
.map(truncate_body_prefix)
513513
.map(|t| t.to_string());
514514

515515
let enum_entity = ClassEntity {
@@ -1017,6 +1017,7 @@ impl<'a> CppVisitor<'a> {
10171017
#[cfg(test)]
10181018
mod tests {
10191019
use super::*;
1020+
use codegraph_parser_api::BODY_PREFIX_MAX_CHARS;
10201021
use tree_sitter::Parser;
10211022

10221023
fn parse_and_visit(source: &[u8]) -> CppVisitor<'_> {

crates/codegraph-erlang/src/mapper.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ mod tests {
257257
}
258258
}
259259

260-
fn prop<'a>(graph: &'a CodeGraph, id: NodeId, key: &str) -> Option<PropertyValue> {
260+
fn prop(graph: &CodeGraph, id: NodeId, key: &str) -> Option<PropertyValue> {
261261
graph.get_node(id).unwrap().properties.get(key).cloned()
262262
}
263263

crates/codegraph-harness/src/bless.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ use std::path::Path;
2727
/// YAML are preserved structurally — keys keep their order best-
2828
/// effort, but comments are lost.
2929
pub fn rewrite_expect_data(path: &Path, new_data: &Json) -> Result<()> {
30-
let raw = std::fs::read_to_string(path)
31-
.with_context(|| format!("read {}", path.display()))?;
32-
let mut doc: Yaml = serde_yaml::from_str(&raw)
33-
.with_context(|| format!("parse {} as YAML", path.display()))?;
30+
let raw = std::fs::read_to_string(path).with_context(|| format!("read {}", path.display()))?;
31+
let mut doc: Yaml =
32+
serde_yaml::from_str(&raw).with_context(|| format!("parse {} as YAML", path.display()))?;
3433

3534
let expect = doc
3635
.as_mapping_mut()
@@ -43,8 +42,7 @@ pub fn rewrite_expect_data(path: &Path, new_data: &Json) -> Result<()> {
4342

4443
let serialised = serde_yaml::to_string(&doc)
4544
.with_context(|| format!("serialise {} after rewrite", path.display()))?;
46-
std::fs::write(path, serialised)
47-
.with_context(|| format!("write {}", path.display()))?;
45+
std::fs::write(path, serialised).with_context(|| format!("write {}", path.display()))?;
4846
Ok(())
4947
}
5048

@@ -98,15 +96,8 @@ mod tests {
9896
// Round-trip the file through serde_yaml so we can assert on
9997
// the structured content rather than literal text formatting.
10098
let parsed: serde_yaml::Value = serde_yaml::from_str(&after).unwrap();
101-
let data = parsed
102-
.get("expect")
103-
.unwrap()
104-
.get("data")
105-
.unwrap();
106-
let expected_yaml: Yaml = serde_yaml::from_str(
107-
"results:\n - name: a\n",
108-
)
109-
.unwrap();
99+
let data = parsed.get("expect").unwrap().get("data").unwrap();
100+
let expected_yaml: Yaml = serde_yaml::from_str("results:\n - name: a\n").unwrap();
110101
assert_eq!(*data, expected_yaml);
111102
}
112103

crates/codegraph-harness/src/compare.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,26 @@ pub fn compare(actual: &Value, expected: &Value, mode: MatchMode) -> Result<Comp
6363
let mut errors = Vec::new();
6464
walk(&mut path, actual, expected, mode, &mut errors);
6565
if errors.is_empty() {
66-
Ok(Comparison { passed: true, diff: String::new() })
66+
Ok(Comparison {
67+
passed: true,
68+
diff: String::new(),
69+
})
6770
} else {
6871
let diff = format_diff(&errors, actual, expected, mode);
69-
Ok(Comparison { passed: false, diff })
72+
Ok(Comparison {
73+
passed: false,
74+
diff,
75+
})
7076
}
7177
}
7278

73-
fn walk(path: &mut String, actual: &Value, expected: &Value, mode: MatchMode, errors: &mut Vec<String>) {
79+
fn walk(
80+
path: &mut String,
81+
actual: &Value,
82+
expected: &Value,
83+
mode: MatchMode,
84+
errors: &mut Vec<String>,
85+
) {
7486
// Tolerance sentinel: `expected` is `{ "__tol__": { value, tol } }`.
7587
// Recognised at every depth, every match mode.
7688
if let Some(band) = parse_tol(expected) {
@@ -99,13 +111,7 @@ fn walk(path: &mut String, actual: &Value, expected: &Value, mode: MatchMode, er
99111
path.push_str(k);
100112
match a.get(k) {
101113
None => errors.push(format!("{}: missing key", path)),
102-
Some(av) => {
103-
if mode == MatchMode::CountOnly {
104-
walk(path, av, ev, mode, errors);
105-
} else {
106-
walk(path, av, ev, mode, errors);
107-
}
108-
}
114+
Some(av) => walk(path, av, ev, mode, errors),
109115
}
110116
path.truncate(len);
111117
}
@@ -121,12 +127,7 @@ fn walk(path: &mut String, actual: &Value, expected: &Value, mode: MatchMode, er
121127
(Value::Array(a), Value::Array(e)) => match mode {
122128
MatchMode::Exact | MatchMode::Structural | MatchMode::CountOnly => {
123129
if a.len() != e.len() {
124-
errors.push(format!(
125-
"{}: array length {} != {}",
126-
path,
127-
a.len(),
128-
e.len()
129-
));
130+
errors.push(format!("{}: array length {} != {}", path, a.len(), e.len()));
130131
return;
131132
}
132133
if mode == MatchMode::CountOnly {
@@ -242,7 +243,10 @@ fn format_diff(errors: &[String], actual: &Value, expected: &Value, mode: MatchM
242243
}
243244

244245
fn prefix_lines(s: &str, prefix: &str) -> String {
245-
s.lines().map(|l| format!("{}{}", prefix, l)).collect::<Vec<_>>().join("\n")
246+
s.lines()
247+
.map(|l| format!("{}{}", prefix, l))
248+
.collect::<Vec<_>>()
249+
.join("\n")
246250
}
247251

248252
#[cfg(test)]
@@ -258,12 +262,7 @@ mod tests {
258262

259263
#[test]
260264
fn exact_flags_extra_actual_key() {
261-
let r = compare(
262-
&json!({"a": 1, "b": 2}),
263-
&json!({"a": 1}),
264-
MatchMode::Exact,
265-
)
266-
.unwrap();
265+
let r = compare(&json!({"a": 1, "b": 2}), &json!({"a": 1}), MatchMode::Exact).unwrap();
267266
assert!(!r.passed);
268267
assert!(r.diff.contains("unexpected key"));
269268
}
@@ -413,7 +412,9 @@ mod tests {
413412
assert!(parse_tol(&json!("x")).is_none());
414413
// Object but not a single key.
415414
assert!(parse_tol(&json!({})).is_none());
416-
assert!(parse_tol(&json!({TOL_SENTINEL: {"value": 1.0, "tol": 0.1}, "extra": 1})).is_none());
415+
assert!(
416+
parse_tol(&json!({TOL_SENTINEL: {"value": 1.0, "tol": 0.1}, "extra": 1})).is_none()
417+
);
417418
}
418419

419420
#[test]

crates/codegraph-harness/src/jsonrpc.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,20 @@ impl McpClient {
3535
.stdout(Stdio::piped())
3636
.stderr(Stdio::null());
3737
let mut child = cmd.spawn().with_context(|| {
38-
format!("spawn {} --mcp --workspace {}", binary.display(), workspace.display())
38+
format!(
39+
"spawn {} --mcp --workspace {}",
40+
binary.display(),
41+
workspace.display()
42+
)
3943
})?;
4044
let stdin = child.stdin.take().ok_or_else(|| anyhow!("no stdin"))?;
4145
let stdout = BufReader::new(child.stdout.take().ok_or_else(|| anyhow!("no stdout"))?);
42-
let mut client = McpClient { child, stdin, stdout, next_id: 1 };
46+
let mut client = McpClient {
47+
child,
48+
stdin,
49+
stdout,
50+
next_id: 1,
51+
};
4352
client.handshake()?;
4453
Ok(client)
4554
}

crates/codegraph-harness/src/main.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ fn main() -> Result<()> {
7373
let args = Args::parse();
7474
let crate_root = Path::new(env!("CARGO_MANIFEST_DIR"));
7575
let binary = resolve_binary(args.binary.as_deref(), crate_root)?;
76-
let cases_dir = args
77-
.cases_dir
78-
.unwrap_or_else(|| crate_root.join("cases"));
76+
let cases_dir = args.cases_dir.unwrap_or_else(|| crate_root.join("cases"));
7977
let fixtures_dir = args
8078
.fixtures_dir
8179
.unwrap_or_else(|| crate_root.join("fixtures"));
@@ -179,7 +177,10 @@ fn main() -> Result<()> {
179177
match report.drift_against(&coverage_path) {
180178
Ok(d) => d,
181179
Err(e) => {
182-
eprintln!("warning: could not read previous coverage snapshot: {:#}", e);
180+
eprintln!(
181+
"warning: could not read previous coverage snapshot: {:#}",
182+
e
183+
);
183184
None
184185
}
185186
}
@@ -214,7 +215,12 @@ fn discover_cases(cases_dir: &Path, filter: Option<&str>) -> Result<Vec<case::Te
214215
));
215216
}
216217
let patterns: Vec<&str> = filter
217-
.map(|f| f.split(',').map(str::trim).filter(|s| !s.is_empty()).collect())
218+
.map(|f| {
219+
f.split(',')
220+
.map(str::trim)
221+
.filter(|s| !s.is_empty())
222+
.collect()
223+
})
218224
.unwrap_or_default();
219225
for entry in walkdir::WalkDir::new(cases_dir) {
220226
let entry = entry?;

crates/codegraph-harness/src/normalize.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn strip_volatile(value: &Value, extra: &[String], keep: &[String]) -> Value {
109109
Value::Object(map) => {
110110
let mut new_map = serde_json::Map::with_capacity(map.len());
111111
for (k, v) in map {
112-
let is_global = VOLATILE_FIELDS.iter().any(|f| *f == k.as_str());
112+
let is_global = VOLATILE_FIELDS.contains(&k.as_str());
113113
let is_extra = extra.iter().any(|f| f == k);
114114
let is_kept = keep.iter().any(|f| f == k);
115115
if (is_global || is_extra) && !is_kept {
@@ -119,11 +119,9 @@ fn strip_volatile(value: &Value, extra: &[String], keep: &[String]) -> Value {
119119
}
120120
Value::Object(new_map)
121121
}
122-
Value::Array(arr) => Value::Array(
123-
arr.iter()
124-
.map(|v| strip_volatile(v, extra, keep))
125-
.collect(),
126-
),
122+
Value::Array(arr) => {
123+
Value::Array(arr.iter().map(|v| strip_volatile(v, extra, keep)).collect())
124+
}
127125
other => other.clone(),
128126
}
129127
}
@@ -302,11 +300,7 @@ mod tests {
302300
#[test]
303301
fn strip_volatile_keep_overrides_extra() {
304302
let input = json!({"name": "foo", "trace_id": "abc"});
305-
let out = strip_volatile(
306-
&input,
307-
&["trace_id".to_string()],
308-
&["trace_id".to_string()],
309-
);
303+
let out = strip_volatile(&input, &["trace_id".to_string()], &["trace_id".to_string()]);
310304
assert_eq!(out, json!({"name": "foo", "trace_id": "abc"}));
311305
}
312306

@@ -346,10 +340,13 @@ mod tests {
346340
]);
347341
let out = canonical_sort(&input);
348342
// Sorted by JSON string — `{"id":1,"name":"a"}` < `{"id":2,"name":"b"}`.
349-
assert_eq!(out, json!([
350-
{"name": "a", "id": 1},
351-
{"name": "b", "id": 2}
352-
]));
343+
assert_eq!(
344+
out,
345+
json!([
346+
{"name": "a", "id": 1},
347+
{"name": "b", "id": 2}
348+
])
349+
);
353350
}
354351

355352
#[test]
@@ -387,10 +384,7 @@ mod tests {
387384
});
388385
let patterns = vec![json!({"kind": "y"})];
389386
let out = drop_array_elements_matching(&input, &patterns);
390-
assert_eq!(
391-
out,
392-
json!({"outer": [{"inner": [{"kind": "x"}]}]})
393-
);
387+
assert_eq!(out, json!({"outer": [{"inner": [{"kind": "x"}]}]}));
394388
}
395389

396390
#[test]
@@ -450,12 +444,15 @@ mod tests {
450444
drop_where: vec![],
451445
};
452446
let out = normalize(&input, "", "", &opts);
453-
assert_eq!(out, json!({
454-
"results": [
455-
{"name": "a", "weight": 0.91},
456-
{"name": "b", "weight": 0.78}
457-
]
458-
}));
447+
assert_eq!(
448+
out,
449+
json!({
450+
"results": [
451+
{"name": "a", "weight": 0.91},
452+
{"name": "b", "weight": 0.78}
453+
]
454+
})
455+
);
459456
}
460457

461458
#[test]

crates/codegraph-harness/src/report.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ pub fn record_from_result(case: &crate::case::TestCase, result: &CaseResult) ->
306306
/// - `languages/<lang>/<file>` — single-file fixtures
307307
/// - `multifile/<lang>_<scenario>/...` — multi-file fixtures, where
308308
/// `<lang>` is everything before the first `_` of the directory name
309+
///
309310
/// Falls back to `unknown` for off-convention paths.
310311
fn language_from_fixture(fixture: &str) -> String {
311312
let parts: Vec<&str> = fixture.split('/').collect();

0 commit comments

Comments
 (0)