@@ -27,12 +27,18 @@ pub struct RustAnalyzer {
2727impl RustAnalyzer {
2828 /// Create a new Rust analyzer with default settings
2929 pub fn new ( ) -> Self {
30- Self { analyze_tests : false , check_quality_headers : true }
30+ Self {
31+ analyze_tests : false ,
32+ check_quality_headers : true ,
33+ }
3134 }
3235
3336 /// Create a Rust analyzer that also analyzes test files
3437 pub fn with_tests ( ) -> Self {
35- Self { analyze_tests : true , check_quality_headers : true }
38+ Self {
39+ analyze_tests : true ,
40+ check_quality_headers : true ,
41+ }
3642 }
3743
3844 /// Find all unimplemented macros in the file
@@ -157,7 +163,11 @@ impl FileAnalyzer for RustAnalyzer {
157163 }
158164
159165 fn handles_file ( & self , file_path : & Path ) -> bool {
160- file_path. extension ( ) . and_then ( |ext| ext. to_str ( ) ) . map ( |ext| ext == "rs" ) . unwrap_or ( false )
166+ file_path
167+ . extension ( )
168+ . and_then ( |ext| ext. to_str ( ) )
169+ . map ( |ext| ext == "rs" )
170+ . unwrap_or ( false )
161171 }
162172}
163173
@@ -276,18 +286,24 @@ impl EmptyOkReturnVisitor {
276286
277287 fn is_result_type ( & self , ty : & syn:: Type ) -> bool {
278288 match ty {
279- syn:: Type :: Path ( type_path) => {
280- type_path. path . segments . last ( ) . map ( |seg| seg. ident == "Result" ) . unwrap_or ( false )
281- }
289+ syn:: Type :: Path ( type_path) => type_path
290+ . path
291+ . segments
292+ . last ( )
293+ . map ( |seg| seg. ident == "Result" )
294+ . unwrap_or ( false ) ,
282295 _ => false ,
283296 }
284297 }
285298
286299 fn is_option_type ( & self , ty : & syn:: Type ) -> bool {
287300 match ty {
288- syn:: Type :: Path ( type_path) => {
289- type_path. path . segments . last ( ) . map ( |seg| seg. ident == "Option" ) . unwrap_or ( false )
290- }
301+ syn:: Type :: Path ( type_path) => type_path
302+ . path
303+ . segments
304+ . last ( )
305+ . map ( |seg| seg. ident == "Option" )
306+ . unwrap_or ( false ) ,
291307 _ => false ,
292308 }
293309 }
@@ -309,7 +325,13 @@ impl EmptyOkReturnVisitor {
309325 if let syn:: Expr :: Call ( call) = expr {
310326 // Check if it's Ok(...) with trivial arguments
311327 if let syn:: Expr :: Path ( path) = & * call. func {
312- if path. path . segments . last ( ) . map ( |seg| seg. ident == "Ok" ) . unwrap_or ( false ) {
328+ if path
329+ . path
330+ . segments
331+ . last ( )
332+ . map ( |seg| seg. ident == "Ok" )
333+ . unwrap_or ( false )
334+ {
313335 // Ok() with no args is trivial
314336 if call. args . is_empty ( ) {
315337 return true ;
@@ -338,7 +360,13 @@ impl EmptyOkReturnVisitor {
338360 if let syn:: Expr :: Call ( call) = expr {
339361 // Check if it's Some(...) with trivial arguments
340362 if let syn:: Expr :: Path ( path) = & * call. func {
341- if path. path . segments . last ( ) . map ( |seg| seg. ident == "Some" ) . unwrap_or ( false ) {
363+ if path
364+ . path
365+ . segments
366+ . last ( )
367+ . map ( |seg| seg. ident == "Some" )
368+ . unwrap_or ( false )
369+ {
342370 // Some(()) with unit type is trivial
343371 if call. args . len ( ) == 1 {
344372 if let syn:: Expr :: Tuple ( tuple) = & call. args [ 0 ] {
@@ -408,8 +436,10 @@ fn another_function() {
408436
409437 let violations = self . analyze ( Path :: new ( "test.rs" ) , content) ?;
410438
411- let unimplemented_violations: Vec < _ > =
412- violations. iter ( ) . filter ( |v| v. rule_id . contains ( "unimplemented" ) ) . collect ( ) ;
439+ let unimplemented_violations: Vec < _ > = violations
440+ . iter ( )
441+ . filter ( |v| v. rule_id . contains ( "unimplemented" ) )
442+ . collect ( ) ;
413443
414444 if unimplemented_violations. is_empty ( ) {
415445 return Err ( GuardianError :: analysis (
@@ -446,8 +476,10 @@ fn perform_operation() -> i32 {
446476
447477 let violations = self . analyze ( Path :: new ( "test.rs" ) , content) ?;
448478
449- let empty_violations: Vec < _ > =
450- violations. iter ( ) . filter ( |v| v. rule_id == "empty_ok_return" ) . collect ( ) ;
479+ let empty_violations: Vec < _ > = violations
480+ . iter ( )
481+ . filter ( |v| v. rule_id == "empty_ok_return" )
482+ . collect ( ) ;
451483
452484 if empty_violations. is_empty ( ) {
453485 return Err ( GuardianError :: analysis (
@@ -457,8 +489,9 @@ fn perform_operation() -> i32 {
457489 }
458490
459491 // Verify it caught the empty function
460- let has_empty_function =
461- empty_violations. iter ( ) . any ( |v| v. message . contains ( "empty_function" ) ) ;
492+ let has_empty_function = empty_violations
493+ . iter ( )
494+ . any ( |v| v. message . contains ( "empty_function" ) ) ;
462495
463496 if !has_empty_function {
464497 return Err ( GuardianError :: analysis (
@@ -502,8 +535,10 @@ mod tests {
502535
503536 let violations = self . analyze ( Path :: new ( "test.rs" ) , content) ?;
504537
505- let unimplemented_violations: Vec < _ > =
506- violations. iter ( ) . filter ( |v| v. rule_id . contains ( "unimplemented" ) ) . collect ( ) ;
538+ let unimplemented_violations: Vec < _ > = violations
539+ . iter ( )
540+ . filter ( |v| v. rule_id . contains ( "unimplemented" ) )
541+ . collect ( ) ;
507542
508543 // Should find exactly one violation (from regular_function)
509544 if unimplemented_violations. len ( ) != 1 {
@@ -534,8 +569,10 @@ fn main() {
534569"# ;
535570
536571 let violations = self . analyze ( Path :: new ( "src/main.rs" ) , content_without_header) ?;
537- let missing_header_violations: Vec < _ > =
538- violations. iter ( ) . filter ( |v| v. rule_id == "quality_header_missing" ) . collect ( ) ;
572+ let missing_header_violations: Vec < _ > = violations
573+ . iter ( )
574+ . filter ( |v| v. rule_id == "quality_header_missing" )
575+ . collect ( ) ;
539576
540577 if missing_header_violations. is_empty ( ) {
541578 return Err ( GuardianError :: analysis (
@@ -559,8 +596,10 @@ fn main() {
559596"# ;
560597
561598 let violations = self . analyze ( Path :: new ( "src/main.rs" ) , content_with_header) ?;
562- let header_violations: Vec < _ > =
563- violations. iter ( ) . filter ( |v| v. rule_id == "quality_header_missing" ) . collect ( ) ;
599+ let header_violations: Vec < _ > = violations
600+ . iter ( )
601+ . filter ( |v| v. rule_id == "quality_header_missing" )
602+ . collect ( ) ;
564603
565604 if !header_violations. is_empty ( ) {
566605 return Err ( GuardianError :: analysis (
@@ -583,7 +622,10 @@ fn main() {
583622 // This is acceptable behavior - the file would fail to compile anyway
584623 if !violations. is_empty ( ) {
585624 // Log this as interesting but don't fail - pattern matching might still work
586- tracing:: debug!( "Found {} violations in invalid syntax file" , violations. len( ) ) ;
625+ tracing:: debug!(
626+ "Found {} violations in invalid syntax file" ,
627+ violations. len( )
628+ ) ;
587629 }
588630
589631 Ok ( ( ) )
0 commit comments