use std::path::{Path, PathBuf};
use harn_lint::LintSeverity;
use super::outcome::{print_lint_diagnostics, CommandOutcome};
pub(crate) fn collect_lint_targets(targets: &[&str]) -> (Vec<PathBuf>, Vec<PathBuf>) {
let files = super::super::collect_source_targets(targets, true, true);
(files.harn, files.prompts)
}
pub(crate) fn lint_prompt_file_inner(
path: &Path,
branch_threshold: Option<usize>,
disabled_rules: &[String],
) -> CommandOutcome {
let path_str = path.to_string_lossy().into_owned();
let source = match std::fs::read_to_string(path) {
Ok(s) => s,
Err(error) => {
eprintln!("error: failed to read {path_str}: {error}");
return CommandOutcome {
has_error: true,
has_warning: false,
};
}
};
let diagnostics = harn_lint::lint_prompt_template(&source, branch_threshold, disabled_rules);
if diagnostics.is_empty() {
println!("{path_str}: no issues found");
return CommandOutcome::default();
}
let has_warning = diagnostics
.iter()
.any(|d| d.severity == LintSeverity::Warning);
let has_error = print_lint_diagnostics(&path_str, &source, &diagnostics);
CommandOutcome {
has_error,
has_warning,
}
}