use crate::validation::spec::validation_rule_statuses;
use sbol_core::validation::options::RuleOverrides;
pub use sbol_core::validation::options::{RuleOverride, UnknownRule, ValidationConfig};
use sbol_core::validation::report::Severity;
#[derive(Clone, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub struct ValidationOptions {
pub config: ValidationConfig,
pub(crate) rules: RuleOverrides,
}
impl ValidationOptions {
pub fn allow(self, rule: &str) -> Result<Self, UnknownRule> {
self.override_rule(rule, RuleOverride::Suppress)
}
pub fn deny(self, rule: &str) -> Result<Self, UnknownRule> {
self.override_rule(rule, RuleOverride::Severity(Severity::Error))
}
pub fn warn(self, rule: &str) -> Result<Self, UnknownRule> {
self.override_rule(rule, RuleOverride::Severity(Severity::Warning))
}
pub fn with_config(mut self, config: ValidationConfig) -> Self {
self.config = config;
self
}
pub fn complete(mut self, on: bool) -> Self {
self.config.complete = on;
self
}
pub fn compliant(mut self, on: bool) -> Self {
self.config.compliant = on;
self
}
pub fn best_practice(mut self, on: bool) -> Self {
self.config.best_practice = on;
self
}
pub fn overrides(&self) -> impl Iterator<Item = (&'static str, RuleOverride)> + '_ {
self.rules.iter()
}
pub fn severity_floor(&self) -> Option<Severity> {
self.rules.severity_floor()
}
pub fn severity_ceiling(&self) -> Option<Severity> {
self.rules.severity_ceiling()
}
fn override_rule(mut self, rule: &str, ovr: RuleOverride) -> Result<Self, UnknownRule> {
self.rules = self.rules.set(rule, ovr, validation_rule_statuses())?;
Ok(self)
}
pub(crate) fn resolved_severity(
&self,
rule: &'static str,
catalog_default: Severity,
) -> Option<Severity> {
self.rules.resolved_severity(rule, catalog_default)
}
}