WIP: allow using nff as a diagnostics source #1
					 1 changed files with 13 additions and 5 deletions
				
			
		lint: introduce LintError; count diagnostic errors
		
	
				commit
				
					
					
						8d7fcd6ef4
					
				
			
		
							
								
								
									
										18
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								src/main.rs
									
										
									
									
									
								
							|  | @ -38,6 +38,12 @@ enum FormatterError { | ||||||
|     Io(#[from] io::Error), |     Io(#[from] io::Error), | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | #[derive(Error, Debug)] | ||||||
|  | enum LintError { | ||||||
|  |     #[error("Lint errors found in {file_count} file(s)")] | ||||||
|  |     DiagnosticErrors { file_count: usize }, | ||||||
|  | } | ||||||
|  | 
 | ||||||
| #[derive(Parser, Debug, Clone)] | #[derive(Parser, Debug, Clone)] | ||||||
| #[command(
 | #[command(
 | ||||||
|     name = "nff", |     name = "nff", | ||||||
|  | @ -337,7 +343,7 @@ fn process_lint_command( | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     let is_multiple_files = files.len() > 1; |     let is_multiple_files = files.len() > 1; | ||||||
|     let mut has_errors = false; |     let mut error_file_count = 0; | ||||||
| 
 | 
 | ||||||
|     for file_path in files { |     for file_path in files { | ||||||
|         if let Err(e) = process_single_file_lint( |         if let Err(e) = process_single_file_lint( | ||||||
|  | @ -352,16 +358,18 @@ fn process_lint_command( | ||||||
|             is_multiple_files, |             is_multiple_files, | ||||||
|         ) { |         ) { | ||||||
|             eprintln!("Error processing {}: {}", file_path, e); |             eprintln!("Error processing {}: {}", file_path, e); | ||||||
|             has_errors = true; |             error_file_count += 1; | ||||||
|             if !is_multiple_files { |             if !is_multiple_files { | ||||||
|                 return Err(e); |                 return Err(e); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Exit with non-zero code if any file had errors
 |     if error_file_count > 0 { | ||||||
|     if has_errors { |         return Err(LintError::DiagnosticErrors { | ||||||
|         std::process::exit(1); |             file_count: error_file_count, | ||||||
|  |         } | ||||||
|  |         .into()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     Ok(()) |     Ok(()) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue