use std::collections::HashMap;
use crate::types::{RuleId, Severity};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LintPolicy {
Strict,
Warn,
Off,
}
impl LintPolicy {
pub fn from_str_lossy(s: &str) -> Self {
match s.to_ascii_lowercase().as_str() {
"strict" => Self::Strict,
"off" | "none" | "disable" => Self::Off,
_ => Self::Warn,
}
}
}
#[derive(Debug, Clone)]
pub struct LintConfig {
pub policy: LintPolicy,
pub rule_severity: HashMap<RuleId, Severity>,
}
impl Default for LintConfig {
fn default() -> Self {
Self {
policy: LintPolicy::Warn,
rule_severity: HashMap::new(),
}
}
}
impl LintConfig {
pub fn with_policy(mut self, policy: LintPolicy) -> Self {
self.policy = policy;
self
}
pub fn severity_for(&self, rule: RuleId, default: Severity) -> Severity {
self.rule_severity.get(&rule).copied().unwrap_or(default)
}
}