lint: introduce LintError; count diagnostic errors

This commit is contained in:
raf 2025-06-02 14:00:48 +03:00
commit 8d7fcd6ef4
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -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(())