use super::{base_caps, concepts_of, finding_from_concept};
use crate::domain::concepts::ConceptKind;
use crate::domain::model::LanguageModel;
use crate::domain::rule::{Rule, RuleMeta};
use crate::domain::types::{Confidence, Finding, Severity};
use std::sync::OnceLock;
#[derive(Default)]
pub struct PlaceholderHandlerRule;
impl Rule for PlaceholderHandlerRule {
fn meta(&self) -> &RuleMeta {
static META: OnceLock<RuleMeta> = OnceLock::new();
META.get_or_init(|| RuleMeta {
id: "placeholder-handler".into(),
name: "Placeholder in critical path".into(),
description: "TODO/FIXME/todo!/unimplemented! on an error path.".into(),
default_severity: Severity::High,
required_capabilities: base_caps(),
autofix_safe: false,
})
}
fn evaluate(&self, model: &LanguageModel) -> Vec<Finding> {
concepts_of(model, ConceptKind::Placeholder)
.map(|(lang, c)| {
let sev = if c.critical_path {
Severity::Critical
} else {
Severity::High
};
finding_from_concept(
&self.meta().id,
lang,
c,
sev,
Confidence::High,
"Placeholder remains on a failure path.",
"Production hits unfinished error handling and aborts or no-ops.",
"Implement the handler or fail closed with a structured error.",
)
})
.collect()
}
}