xbp_analysis/domain/
rule.rs1use super::capabilities::CapabilitySet;
4use super::model::LanguageModel;
5use super::types::{Finding, Severity};
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
10pub struct RuleMeta {
11 pub id: String,
12 pub name: String,
13 pub description: String,
14 pub default_severity: Severity,
15 pub required_capabilities: CapabilitySet,
17 pub autofix_safe: bool,
19}
20
21pub trait Rule: Send + Sync {
23 fn meta(&self) -> &RuleMeta;
24 fn evaluate(&self, model: &LanguageModel) -> Vec<Finding>;
25}
26
27#[derive(Debug, Clone, Default, Serialize, Deserialize)]
29pub struct RuleSelection {
30 pub enabled: Vec<String>,
31 pub disabled: Vec<String>,
32 pub min_severity: Option<Severity>,
33}
34
35impl RuleSelection {
36 pub fn allows(&self, rule_id: &str) -> bool {
37 if self.disabled.iter().any(|d| d == rule_id || d == "*") {
38 return false;
39 }
40 if self.enabled.is_empty() {
41 return true;
42 }
43 self.enabled.iter().any(|e| e == rule_id || e == "*")
44 }
45}