1use std::collections::HashMap;
2
3use crate::types::{RuleId, Severity};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum LintPolicy {
8 Strict,
10 Warn,
12 Off,
14}
15
16impl LintPolicy {
17 pub fn from_str_lossy(s: &str) -> Self {
20 match s.to_ascii_lowercase().as_str() {
21 "strict" => Self::Strict,
22 "off" | "none" | "disable" => Self::Off,
23 _ => Self::Warn,
24 }
25 }
26}
27
28#[derive(Debug, Clone)]
30pub struct LintConfig {
31 pub policy: LintPolicy,
32 pub rule_severity: HashMap<RuleId, Severity>,
34}
35
36impl Default for LintConfig {
37 fn default() -> Self {
38 Self {
39 policy: LintPolicy::Warn,
40 rule_severity: HashMap::new(),
41 }
42 }
43}
44
45impl LintConfig {
46 pub fn with_policy(mut self, policy: LintPolicy) -> Self {
47 self.policy = policy;
48 self
49 }
50
51 pub fn severity_for(&self, rule: RuleId, default: Severity) -> Severity {
54 self.rule_severity.get(&rule).copied().unwrap_or(default)
55 }
56}