Skip to content

Commit 2216fec

Browse files
committed
fix: clippy
1 parent 637d352 commit 2216fec

File tree

6 files changed

+31
-37
lines changed

6 files changed

+31
-37
lines changed

crates/postgresql-cst-parser/examples/sample.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212
.map(|node| node.text().to_string())
1313
.collect();
1414

15-
println!("Column references: {:?}", column_refs); // ["tbl.a", "tbl.b", "tbl.a"]
15+
println!("Column references: {column_refs:?}"); // ["tbl.a", "tbl.b", "tbl.a"]
1616

1717
// Example 2: Find the WHERE condition
1818
if let Some(where_clause) = root

crates/postgresql-cst-parser/examples/tree_sitter_like.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ select
1818
1919
"#;
2020

21-
let tree = tree_sitter::parse(&src).unwrap();
21+
let tree = tree_sitter::parse(src).unwrap();
2222
let root = tree.root_node();
2323
let mut cursor = root.walk();
2424

25-
visit(&mut cursor, 0, &src);
25+
visit(&mut cursor, 0);
2626
}
2727

2828
const UNIT: usize = 2;
29-
fn visit(cursor: &mut TreeCursor, depth: usize, src: &str) {
29+
fn visit(cursor: &mut TreeCursor, depth: usize) {
3030
(0..(depth * UNIT)).for_each(|_| print!("-"));
3131

3232
print!("{}", cursor.node().kind());
@@ -37,9 +37,9 @@ fn visit(cursor: &mut TreeCursor, depth: usize, src: &str) {
3737
println!(" {}", cursor.node().range());
3838

3939
if cursor.goto_first_child() {
40-
visit(cursor, depth + 1, src);
40+
visit(cursor, depth + 1);
4141
while cursor.goto_next_sibling() {
42-
visit(cursor, depth + 1, src);
42+
visit(cursor, depth + 1);
4343
}
4444
cursor.goto_parent();
4545
}

crates/postgresql-cst-parser/src/tree_sitter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ mod tests {
293293
tokens.push((cursor.node().text(), cursor.node().range()));
294294
}
295295

296-
if cursor.goto_first_child() {
297-
} else if cursor.goto_next_sibling() {
296+
if cursor.goto_first_child() || cursor.goto_next_sibling() {
298297
} else {
299298
loop {
300299
if !cursor.goto_parent() {

crates/postgresql-cst-parser/src/tree_sitter/assert_util.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ pub fn assert_exists(root: &ResolvedNode, kind: SyntaxKind) {
55
let exists = root.descendants().any(|node| node.kind() == kind);
66
assert!(
77
exists,
8-
"Expected at least one node of kind {:?}, but none was found.",
9-
kind
8+
"Expected at least one node of kind {kind:?}, but none was found."
109
)
1110
}
1211

@@ -15,8 +14,7 @@ pub fn assert_not_exists(root: &ResolvedNode, kind: SyntaxKind) {
1514
let exists = root.descendants().any(|node| node.kind() == kind);
1615
assert!(
1716
!exists,
18-
"Expected no nodes of kind {:?}, but at least one was found.",
19-
kind
17+
"Expected no nodes of kind {kind:?}, but at least one was found."
2018
)
2119
}
2220

@@ -28,8 +26,7 @@ pub fn assert_node_count(root: &ResolvedNode, kind: SyntaxKind, expected_count:
2826
.count();
2927
assert_eq!(
3028
actual_count, expected_count,
31-
"Expected {} nodes of kind {:?}, but found {}.",
32-
expected_count, kind, actual_count
29+
"Expected {expected_count} nodes of kind {kind:?}, but found {actual_count}."
3330
)
3431
}
3532

@@ -42,9 +39,7 @@ pub fn assert_no_direct_nested_kind(root: &ResolvedNode, kind: SyntaxKind) {
4239
if let Some(parent) = node.parent() {
4340
assert!(
4441
!(node.kind() == kind && parent.kind() == kind),
45-
"Found a `{:?}` node that directly contains another {:?} node as a child.",
46-
parent,
47-
kind
42+
"Found a `{parent:?}` node that directly contains another {kind:?} node as a child."
4843
)
4944
}
5045
}

crates/postgresql-cst-parser/src/tree_sitter/convert.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ FROM
261261
A
262262
, B"#;
263263

264-
let root = cst::parse(&original).unwrap();
265-
let (new_root, _) = get_ts_tree_and_range_map(&original, &root);
264+
let root = cst::parse(original).unwrap();
265+
let (new_root, _) = get_ts_tree_and_range_map(original, &root);
266266

267267
let whitespace_removed: String = original.split_whitespace().collect();
268268
// Lossless property of the CST is broken.
@@ -355,7 +355,7 @@ FROM
355355
fn no_nested_from_list() {
356356
let input = "select * from t1, t2;";
357357
let root = cst::parse(input).unwrap();
358-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
358+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
359359

360360
assert_no_direct_nested_kind(&new_root, SyntaxKind::from_list);
361361
}
@@ -365,7 +365,7 @@ FROM
365365
let input =
366366
"select t.a, t.b.c, t1.*, a[1], a[4][5], a[2:5], a[3].b, a[3][4].b, a[3:5].b;";
367367
let root = cst::parse(input).unwrap();
368-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
368+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
369369

370370
assert_no_direct_nested_kind(&new_root, SyntaxKind::indirection);
371371
}
@@ -374,7 +374,7 @@ FROM
374374
fn no_nested_expr_list() {
375375
let input = "select a from t where a in (1,2,3);";
376376
let root = cst::parse(input).unwrap();
377-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
377+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
378378

379379
assert_no_direct_nested_kind(&new_root, SyntaxKind::expr_list);
380380
}
@@ -383,7 +383,7 @@ FROM
383383
fn no_nested_func_arg_list() {
384384
let input = "select func(1, 2, func2(3, 4), 5);";
385385
let root = cst::parse(input).unwrap();
386-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
386+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
387387

388388
assert_no_direct_nested_kind(&new_root, SyntaxKind::func_arg_list);
389389
}
@@ -392,7 +392,7 @@ FROM
392392
fn no_nested_when_clause_list() {
393393
let input = "select case when a then b when c then d when e then f else g end;";
394394
let root = cst::parse(input).unwrap();
395-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
395+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
396396

397397
assert_no_direct_nested_kind(&new_root, SyntaxKind::when_clause_list);
398398
}
@@ -401,7 +401,7 @@ FROM
401401
fn no_nested_sortby_list() {
402402
let input = "select * from t order by a, b, c;";
403403
let root = cst::parse(input).unwrap();
404-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
404+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
405405

406406
assert_no_direct_nested_kind(&new_root, SyntaxKind::sortby_list);
407407
}
@@ -410,7 +410,7 @@ FROM
410410
fn no_nested_groupby_list() {
411411
let input = "select a, b, c from t group by a, b, c;";
412412
let root = cst::parse(input).unwrap();
413-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
413+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
414414

415415
assert_no_direct_nested_kind(&new_root, SyntaxKind::group_by_list);
416416
}
@@ -419,7 +419,7 @@ FROM
419419
fn no_nested_for_locking_items() {
420420
let input = "select * from t1, t2 for update of t1 for update of t2;";
421421
let root = cst::parse(input).unwrap();
422-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
422+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
423423

424424
assert_no_direct_nested_kind(&new_root, SyntaxKind::for_locking_items);
425425
}
@@ -428,7 +428,7 @@ FROM
428428
fn no_nested_qualified_name_list() {
429429
let input = "select a from t for update of t.a, t.b;";
430430
let root = cst::parse(input).unwrap();
431-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
431+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
432432

433433
assert_no_direct_nested_kind(&new_root, SyntaxKind::qualified_name_list);
434434
}
@@ -437,7 +437,7 @@ FROM
437437
fn no_nested_cte_list() {
438438
let input = "with a as (select 1), b as (select 2) select * from a, b;";
439439
let root = cst::parse(input).unwrap();
440-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
440+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
441441

442442
assert_no_direct_nested_kind(&new_root, SyntaxKind::cte_list);
443443
}
@@ -446,7 +446,7 @@ FROM
446446
fn no_nested_name_list() {
447447
let input = "with t (a, b) as (select 1) select * from t;";
448448
let root = cst::parse(input).unwrap();
449-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
449+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
450450

451451
assert_no_direct_nested_kind(&new_root, SyntaxKind::name_list);
452452
}
@@ -455,7 +455,7 @@ FROM
455455
fn no_nested_set_clause_list() {
456456
let input = "update t set a = 1, b = 2, c = 3;";
457457
let root = cst::parse(input).unwrap();
458-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
458+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
459459

460460
assert_no_direct_nested_kind(&new_root, SyntaxKind::set_clause_list);
461461
}
@@ -464,7 +464,7 @@ FROM
464464
fn no_nested_set_target_list() {
465465
let input = "update t set (a, b, c) = (1, 2, 3) where id = 1;";
466466
let root = cst::parse(input).unwrap();
467-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
467+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
468468

469469
assert_no_direct_nested_kind(&new_root, SyntaxKind::set_target_list);
470470
}
@@ -473,7 +473,7 @@ FROM
473473
fn no_nested_insert_column_list() {
474474
let input = "insert into t (a, b, c) values (1, 2, 3);";
475475
let root = cst::parse(input).unwrap();
476-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
476+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
477477

478478
assert_no_direct_nested_kind(&new_root, SyntaxKind::insert_column_list);
479479
}
@@ -482,7 +482,7 @@ FROM
482482
fn no_nested_index_params() {
483483
let input = "insert into t (a, b, c) values (1, 2, 3) on conflict (a, b) do nothing;";
484484
let root = cst::parse(input).unwrap();
485-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
485+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
486486

487487
assert_no_direct_nested_kind(&new_root, SyntaxKind::index_params);
488488
}
@@ -491,7 +491,7 @@ FROM
491491
fn no_nested_values_clause() {
492492
let input = "values (1,2,3), (4,5,6), (7,8,9);";
493493
let root = cst::parse(input).unwrap();
494-
let (new_root, _) = get_ts_tree_and_range_map(&input, &root);
494+
let (new_root, _) = get_ts_tree_and_range_map(input, &root);
495495

496496
assert_no_direct_nested_kind(&new_root, SyntaxKind::values_clause);
497497
}

crates/postgresql-cst-parser/tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ fn test_all() -> Result<(), std::io::Error> {
1717
.parent()
1818
.unwrap()
1919
.join("dst")
20-
.join(format!("{}.txt", file_stem));
20+
.join(format!("{file_stem}.txt"));
2121

2222
let content = std::fs::read_to_string(path)?;
2323
let tree = parse_2way(&content).unwrap();
24-
std::fs::write(dst_path, format!("{:#?}", tree))?;
24+
std::fs::write(dst_path, format!("{tree:#?}"))?;
2525
}
2626
}
2727

0 commit comments

Comments
 (0)