@@ -73,12 +73,14 @@ impl Analyzer {
7373 }
7474
7575 let effective_severity = config. effective_severity ( category, rule) ;
76- pattern_engine. add_rule ( rule, effective_severity) . map_err ( |e| {
77- GuardianError :: config ( format ! (
78- "Failed to add rule '{}' in category '{}': {}" ,
79- rule. id, category_name, e
80- ) )
81- } ) ?;
76+ pattern_engine
77+ . add_rule ( rule, effective_severity)
78+ . map_err ( |e| {
79+ GuardianError :: config ( format ! (
80+ "Failed to add rule '{}' in category '{}': {}" ,
81+ rule. id, category_name, e
82+ ) )
83+ } ) ?;
8284 }
8385 }
8486
@@ -92,7 +94,12 @@ impl Analyzer {
9294 let path_filter = PathFilter :: new ( config. paths . patterns . clone ( ) , ignore_file)
9395 . map_err ( |e| GuardianError :: config ( format ! ( "Failed to create path filter: {e}" ) ) ) ?;
9496
95- Ok ( Self { config, pattern_engine, path_filter, rust_analyzer : RustAnalyzer :: new ( ) } )
97+ Ok ( Self {
98+ config,
99+ pattern_engine,
100+ path_filter,
101+ rust_analyzer : RustAnalyzer :: new ( ) ,
102+ } )
96103 }
97104
98105 /// Create an analyzer with default configuration
@@ -120,23 +127,29 @@ impl Analyzer {
120127 let mut all_violations = Vec :: new ( ) ;
121128
122129 // Apply pattern matching
123- let matches = self . pattern_engine . analyze_file ( file_path, & content) . map_err ( |e| {
124- GuardianError :: analysis (
125- file_path. display ( ) . to_string ( ) ,
126- format ! ( "Pattern analysis failed: {e}" ) ,
127- )
128- } ) ?;
130+ let matches = self
131+ . pattern_engine
132+ . analyze_file ( file_path, & content)
133+ . map_err ( |e| {
134+ GuardianError :: analysis (
135+ file_path. display ( ) . to_string ( ) ,
136+ format ! ( "Pattern analysis failed: {e}" ) ,
137+ )
138+ } ) ?;
129139
130140 all_violations. extend ( self . pattern_engine . matches_to_violations ( matches) ) ;
131141
132142 // Apply Rust-specific analysis for .rs files
133143 if self . rust_analyzer . handles_file ( file_path) {
134- let rust_violations = self . rust_analyzer . analyze ( file_path, & content) . map_err ( |e| {
135- GuardianError :: analysis (
136- file_path. display ( ) . to_string ( ) ,
137- format ! ( "Rust analysis failed: {e}" ) ,
138- )
139- } ) ?;
144+ let rust_violations = self
145+ . rust_analyzer
146+ . analyze ( file_path, & content)
147+ . map_err ( |e| {
148+ GuardianError :: analysis (
149+ file_path. display ( ) . to_string ( ) ,
150+ format ! ( "Rust analysis failed: {e}" ) ,
151+ )
152+ } ) ?;
140153 all_violations. extend ( rust_violations) ;
141154 }
142155
@@ -238,18 +251,20 @@ impl Analyzer {
238251 let violations = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
239252 let errors = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
240253
241- files. par_iter ( ) . for_each ( |file_path| match self . analyze_file ( file_path) {
242- Ok ( file_violations) => {
243- if let Ok ( mut v) = violations. lock ( ) {
244- v. extend ( file_violations) ;
254+ files
255+ . par_iter ( )
256+ . for_each ( |file_path| match self . analyze_file ( file_path) {
257+ Ok ( file_violations) => {
258+ if let Ok ( mut v) = violations. lock ( ) {
259+ v. extend ( file_violations) ;
260+ }
245261 }
246- }
247- Err ( e ) => {
248- if let Ok ( mut errs ) = errors . lock ( ) {
249- errs . push ( ( file_path . clone ( ) , e ) ) ;
262+ Err ( e ) => {
263+ if let Ok ( mut errs ) = errors . lock ( ) {
264+ errs . push ( ( file_path . clone ( ) , e ) ) ;
265+ }
250266 }
251- }
252- } ) ;
267+ } ) ;
253268
254269 // Handle errors
255270 let errors = Arc :: try_unwrap ( errors)
@@ -548,14 +563,20 @@ impl Analyzer {
548563 } ) ?;
549564
550565 // Test max_files limitation
551- let options = AnalysisOptions { max_files : Some ( 1 ) , ..Default :: default ( ) } ;
566+ let options = AnalysisOptions {
567+ max_files : Some ( 1 ) ,
568+ ..Default :: default ( )
569+ } ;
552570
553571 let report = self . analyze_directory ( root, & options) ?;
554572
555573 if report. summary . total_files != 1 {
556574 return Err ( GuardianError :: analysis (
557575 "validation" . to_string ( ) ,
558- format ! ( "Expected 1 file with max_files=1, got {}" , report. summary. total_files) ,
576+ format ! (
577+ "Expected 1 file with max_files=1, got {}" ,
578+ report. summary. total_files
579+ ) ,
559580 ) ) ;
560581 }
561582
0 commit comments