diff --git a/src/main.rs b/src/main.rs index e7fa847..4d32351 100755 --- a/src/main.rs +++ b/src/main.rs @@ -38,6 +38,12 @@ enum FormatterError { 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)] #[command( name = "nff", @@ -337,7 +343,7 @@ fn process_lint_command( }; let is_multiple_files = files.len() > 1; - let mut has_errors = false; + let mut error_file_count = 0; for file_path in files { if let Err(e) = process_single_file_lint( @@ -352,16 +358,18 @@ fn process_lint_command( is_multiple_files, ) { eprintln!("Error processing {}: {}", file_path, e); - has_errors = true; + error_file_count += 1; if !is_multiple_files { return Err(e); } } } - // Exit with non-zero code if any file had errors - if has_errors { - std::process::exit(1); + if error_file_count > 0 { + return Err(LintError::DiagnosticErrors { + file_count: error_file_count, + } + .into()); } Ok(())