nff: handle errors and exit appropriately in linter

This commit is contained in:
raf 2025-06-02 09:48:23 +03:00
commit 0ed74c6a51
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -351,6 +351,8 @@ fn process_lint_command(
}; };
let is_multiple_files = files.len() > 1; let is_multiple_files = files.len() > 1;
let mut has_errors = false;
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(
&file_path, &file_path,
@ -364,12 +366,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;
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 has_errors {
std::process::exit(1);
}
Ok(()) Ok(())
} }
@ -459,9 +467,9 @@ fn process_single_file_lint(
println!("{}", diagnostics.to_human_readable()); println!("{}", diagnostics.to_human_readable());
} }
// Exit with non-zero code if there are errors // Return error if there are diagnostics errors
if diagnostics.has_errors() { if diagnostics.has_errors() {
std::process::exit(1); return Err(anyhow::anyhow!("Diagnostics found errors in file"));
} }
Ok(()) Ok(())