Skip to content

Commit 64f8447

Browse files
committed
fix CI formatter check
1 parent a4fbff1 commit 64f8447

File tree

5 files changed

+81
-46
lines changed

5 files changed

+81
-46
lines changed

crates/diff-engine/src/changes.rs

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ impl ChangeClassifier {
882882
1 + ast
883883
.children
884884
.iter()
885-
.map(|child| Self::count_ast_nodes(child))
885+
.map(Self::count_ast_nodes)
886886
.sum::<usize>()
887887
}
888888

@@ -894,7 +894,7 @@ impl ChangeClassifier {
894894
1 + ast
895895
.children
896896
.iter()
897-
.map(|child| Self::calculate_ast_depth(child))
897+
.map(Self::calculate_ast_depth)
898898
.max()
899899
.unwrap_or(0)
900900
}
@@ -1240,33 +1240,42 @@ impl ChangeClassifier {
12401240
#[cfg(test)]
12411241
mod tests {
12421242
use super::*;
1243-
use smart_diff_parser::NodeMetadata;
1243+
use smart_diff_parser::{ElementType, NodeMetadata};
12441244
use smart_diff_semantic::{
1245-
ComplexityMetrics, EnhancedFunctionSignature, FunctionType, ParameterInfo, TypeSignature,
1245+
EnhancedFunctionSignature, FunctionComplexityMetrics, FunctionType, TypeSignature,
12461246
Visibility,
12471247
};
12481248
use std::collections::HashMap;
12491249

12501250
fn create_test_code_element(name: &str, file_path: &str, start_line: usize) -> CodeElement {
12511251
CodeElement {
1252+
id: format!("test_{}", name),
12521253
name: name.to_string(),
12531254
file_path: file_path.to_string(),
12541255
start_line,
12551256
end_line: start_line + 10,
1256-
element_type: "function".to_string(),
1257+
element_type: ElementType::Function,
1258+
signature: Some(format!("fn {}()", name)),
1259+
hash: format!("hash_{}", name),
12571260
}
12581261
}
12591262

12601263
fn create_test_ast_node(
12611264
node_type: smart_diff_parser::NodeType,
12621265
children: Vec<ASTNode>,
12631266
) -> ASTNode {
1267+
use std::sync::atomic::{AtomicUsize, Ordering};
1268+
static COUNTER: AtomicUsize = AtomicUsize::new(0);
1269+
let id = COUNTER.fetch_add(1, Ordering::SeqCst);
1270+
12641271
ASTNode {
1272+
id: format!("test_node_{}", id),
12651273
node_type,
12661274
children,
12671275
metadata: NodeMetadata {
12681276
line: 1,
12691277
column: 1,
1278+
original_text: String::new(),
12701279
attributes: HashMap::new(),
12711280
},
12721281
}
@@ -1275,25 +1284,31 @@ mod tests {
12751284
fn create_test_signature(name: &str, complexity: u32) -> EnhancedFunctionSignature {
12761285
EnhancedFunctionSignature {
12771286
name: name.to_string(),
1287+
qualified_name: name.to_string(),
12781288
parameters: Vec::new(),
1279-
return_type: TypeSignature::Simple("void".to_string()),
1289+
return_type: TypeSignature::new("void".to_string()),
12801290
visibility: Visibility::Public,
1281-
function_type: FunctionType::Regular,
1282-
is_async: false,
1283-
is_static: false,
1284-
is_abstract: false,
1291+
function_type: FunctionType::Function,
1292+
modifiers: Vec::new(),
12851293
generic_parameters: Vec::new(),
1286-
throws: Vec::new(),
12871294
annotations: Vec::new(),
1288-
complexity_metrics: ComplexityMetrics {
1289-
cyclomatic_complexity: complexity,
1290-
cognitive_complexity: complexity,
1295+
file_path: String::new(),
1296+
line: 0,
1297+
column: 0,
1298+
end_line: 0,
1299+
complexity_metrics: Some(FunctionComplexityMetrics {
1300+
cyclomatic_complexity: complexity as usize,
1301+
cognitive_complexity: complexity as usize,
12911302
nesting_depth: 2,
12921303
parameter_count: 0,
1293-
return_points: 1,
12941304
lines_of_code: 10,
1295-
},
1305+
branch_count: 1,
1306+
loop_count: 0,
1307+
call_count: 0,
1308+
}),
12961309
dependencies: Vec::new(),
1310+
signature_hash: String::new(),
1311+
normalized_hash: String::new(),
12971312
}
12981313
}
12991314

@@ -1485,7 +1500,7 @@ mod tests {
14851500
smart_diff_parser::NodeType::Block,
14861501
vec![
14871502
create_test_ast_node(smart_diff_parser::NodeType::IfStatement, Vec::new()),
1488-
create_test_ast_node(smart_diff_parser::NodeType::WhileStatement, Vec::new()),
1503+
create_test_ast_node(smart_diff_parser::NodeType::WhileLoop, Vec::new()),
14891504
],
14901505
)],
14911506
);

crates/diff-engine/src/cross_file_tracker.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ impl CrossFileTracker {
282282
Ok(result)
283283
}
284284
#[allow(clippy::type_complexity)]
285-
286285
/// Identify functions that are unmatched within their original files
287286
fn identify_unmatched_functions(
288287
&mut self,
@@ -1025,6 +1024,7 @@ mod tests {
10251024
use smart_diff_semantic::{FunctionType, TypeSignature, Visibility};
10261025
use std::collections::HashMap;
10271026

1027+
#[allow(dead_code)]
10281028
fn create_test_function_signature(name: &str, file_path: &str) -> EnhancedFunctionSignature {
10291029
EnhancedFunctionSignature {
10301030
name: name.to_string(),
@@ -1047,13 +1047,20 @@ mod tests {
10471047
}
10481048
}
10491049

1050+
#[allow(dead_code)]
10501051
fn create_test_ast_node() -> ASTNode {
1052+
use std::sync::atomic::{AtomicUsize, Ordering};
1053+
static COUNTER: AtomicUsize = AtomicUsize::new(0);
1054+
let id = COUNTER.fetch_add(1, Ordering::SeqCst);
1055+
10511056
ASTNode {
1057+
id: format!("test_node_{}", id),
10521058
node_type: smart_diff_parser::NodeType::Function,
10531059
children: Vec::new(),
10541060
metadata: NodeMetadata {
10551061
line: 1,
10561062
column: 1,
1063+
original_text: String::new(),
10571064
attributes: HashMap::new(),
10581065
},
10591066
}

crates/diff-engine/src/refactoring.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ impl RefactoringDetector {
575575

576576
let mut matrix = vec![vec![0; len2 + 1]; len1 + 1];
577577

578-
for i in 0..=len1 {
579-
matrix[i][0] = i;
578+
for (i, row) in matrix.iter_mut().enumerate().take(len1 + 1) {
579+
row[0] = i;
580580
}
581581
for j in 0..=len2 {
582582
matrix[0][j] = j;
@@ -994,7 +994,7 @@ impl RefactoringDetector {
994994
.filter(|c| c.change_type == ChangeType::Modify)
995995
.collect();
996996

997-
if additions.len() >= 2 && modifications.len() >= 1 {
997+
if additions.len() >= 2 && !modifications.is_empty() {
998998
// Check if additions are in the same new file
999999
if let Some(first_addition) = additions.first() {
10001000
if let Some(target) = &first_addition.target {
@@ -1052,7 +1052,7 @@ impl RefactoringDetector {
10521052
.filter(|c| c.change_type == ChangeType::Modify)
10531053
.collect();
10541054

1055-
if deletions.len() >= 2 && modifications.len() >= 1 {
1055+
if deletions.len() >= 2 && !modifications.is_empty() {
10561056
// Check if deletions are from the same file
10571057
if let Some(first_deletion) = deletions.first() {
10581058
if let Some(source) = &first_deletion.source {
@@ -1764,13 +1764,11 @@ impl RefactoringDetector {
17641764
deleted: &Change,
17651765
modified: &Change,
17661766
) -> RefactoringAnalysis {
1767-
let mut characteristics = Vec::new();
1768-
1769-
characteristics.push(RefactoringCharacteristic {
1767+
let characteristics = vec![RefactoringCharacteristic {
17701768
characteristic_type: RefactoringCharacteristicType::CodeInlining,
17711769
value: "Method inlined into calling function".to_string(),
17721770
confidence: 0.8,
1773-
});
1771+
}];
17741772

17751773
RefactoringAnalysis {
17761774
characteristics,
@@ -2445,16 +2443,19 @@ impl RefactoringDetector {
24452443
#[cfg(test)]
24462444
mod tests {
24472445
use super::*;
2448-
use smart_diff_parser::{ChangeDetail, CodeElement};
2446+
use smart_diff_parser::{ChangeDetail, CodeElement, ElementType};
24492447
use std::collections::HashMap;
24502448

24512449
fn create_test_code_element(name: &str, file_path: &str, start_line: usize) -> CodeElement {
24522450
CodeElement {
2451+
id: format!("test_{}", name),
24532452
name: name.to_string(),
24542453
file_path: file_path.to_string(),
24552454
start_line,
24562455
end_line: start_line + 10,
2457-
element_type: "function".to_string(),
2456+
element_type: ElementType::Function,
2457+
signature: Some(format!("fn {}()", name)),
2458+
hash: format!("hash_{}", name),
24582459
}
24592460
}
24602461

@@ -2785,8 +2786,10 @@ mod tests {
27852786

27862787
#[test]
27872788
fn test_confidence_threshold_filtering() {
2788-
let mut config = RefactoringDetectionConfig::default();
2789-
config.min_confidence_threshold = 0.8;
2789+
let config = RefactoringDetectionConfig {
2790+
min_confidence_threshold: 0.8,
2791+
..Default::default()
2792+
};
27902793

27912794
let detector = RefactoringDetector::with_config(Language::Java, config);
27922795

crates/diff-engine/src/smart_matcher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ impl SmartMatcher {
260260
1 + node
261261
.children
262262
.iter()
263-
.map(|child| Self::count_ast_nodes(child))
263+
.map(Self::count_ast_nodes)
264264
.sum::<usize>()
265265
}
266266

@@ -308,7 +308,7 @@ impl SmartMatcher {
308308
1 + node
309309
.children
310310
.iter()
311-
.map(|child| Self::calculate_ast_depth(child))
311+
.map(Self::calculate_ast_depth)
312312
.max()
313313
.unwrap_or(0)
314314
}

crates/diff-engine/src/tree_edit.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ impl TreeEditDistance {
320320
}
321321

322322
/// Perform postorder traversal and calculate leftmost leaves
323+
#[allow(clippy::only_used_in_recursion)]
323324
fn postorder_traversal(
324325
&self,
325326
tree: &ASTNode,
@@ -415,6 +416,7 @@ impl TreeEditDistance {
415416
}
416417

417418
/// Compute forest distance for Zhang-Shasha algorithm
419+
#[allow(clippy::too_many_arguments)]
418420
fn compute_forest_distance(
419421
&self,
420422
i: usize,
@@ -541,17 +543,17 @@ impl TreeEditDistance {
541543

542544
if n > m {
543545
// More deletions
544-
for i in m..n {
546+
for (i, node) in postorder1.iter().enumerate().take(n).skip(m) {
545547
operations.push(EditOperation::Delete {
546-
node: format!("{:?}", postorder1[i]),
548+
node: format!("{:?}", node),
547549
position: i,
548550
});
549551
}
550552
} else if m > n {
551553
// More insertions
552-
for i in n..m {
554+
for (i, node) in postorder2.iter().enumerate().take(m).skip(n) {
553555
operations.push(EditOperation::Insert {
554-
node: format!("{:?}", postorder2[i]),
556+
node: format!("{:?}", node),
555557
position: i,
556558
});
557559
}
@@ -652,12 +654,18 @@ mod tests {
652654
use std::collections::HashMap;
653655

654656
fn create_test_node(node_type: NodeType, children: Vec<ASTNode>) -> ASTNode {
657+
use std::sync::atomic::{AtomicUsize, Ordering};
658+
static COUNTER: AtomicUsize = AtomicUsize::new(0);
659+
let id = COUNTER.fetch_add(1, Ordering::SeqCst);
660+
655661
ASTNode {
662+
id: format!("test_node_{}", id),
656663
node_type,
657664
children,
658665
metadata: NodeMetadata {
659666
line: 1,
660667
column: 1,
668+
original_text: String::new(),
661669
attributes: HashMap::new(),
662670
},
663671
}
@@ -799,7 +807,7 @@ mod tests {
799807
let ted = TreeEditDistance::with_defaults();
800808

801809
let tree1 = create_leaf_node(NodeType::IfStatement);
802-
let tree2 = create_leaf_node(NodeType::WhileStatement);
810+
let tree2 = create_leaf_node(NodeType::WhileLoop);
803811

804812
let distance = ted.calculate_distance(&tree1, &tree2);
805813
assert_eq!(distance, 0.5); // Reduced cost for similar statement types
@@ -844,7 +852,7 @@ mod tests {
844852
create_test_node(
845853
NodeType::Block,
846854
vec![create_test_node(
847-
NodeType::WhileStatement,
855+
NodeType::WhileLoop,
848856
vec![
849857
create_leaf_node(NodeType::BinaryExpression),
850858
create_leaf_node(NodeType::Block),
@@ -885,9 +893,11 @@ mod tests {
885893

886894
#[test]
887895
fn test_pruning_heuristics() {
888-
let mut config = ZhangShashaConfig::default();
889-
config.max_nodes = 2; // Very small limit to trigger pruning
890-
config.enable_pruning = true;
896+
let config = ZhangShashaConfig {
897+
max_nodes: 2, // Very small limit to trigger pruning
898+
enable_pruning: true,
899+
..Default::default()
900+
};
891901

892902
let ted = TreeEditDistance::new(config);
893903

@@ -897,7 +907,7 @@ mod tests {
897907
vec![
898908
create_leaf_node(NodeType::Identifier),
899909
create_leaf_node(NodeType::Block),
900-
create_leaf_node(NodeType::Statement),
910+
create_leaf_node(NodeType::ReturnStatement),
901911
],
902912
);
903913

@@ -925,8 +935,8 @@ mod tests {
925935
create_test_node(
926936
NodeType::Block,
927937
vec![
928-
create_leaf_node(NodeType::Statement),
929-
create_leaf_node(NodeType::Statement),
938+
create_leaf_node(NodeType::ReturnStatement),
939+
create_leaf_node(NodeType::ExpressionStatement),
930940
],
931941
),
932942
],
@@ -946,13 +956,13 @@ mod tests {
946956
NodeType::Block,
947957
vec![create_test_node(
948958
NodeType::IfStatement,
949-
vec![create_leaf_node(NodeType::Expression)],
959+
vec![create_leaf_node(NodeType::BinaryExpression)],
950960
)],
951961
)],
952962
);
953963

954964
let depth = ted.calculate_depth(&tree);
955-
assert_eq!(depth, 4); // Function -> Block -> IfStatement -> Expression
965+
assert_eq!(depth, 4); // Function -> Block -> IfStatement -> BinaryExpression
956966
}
957967

958968
#[test]

0 commit comments

Comments
 (0)