Skip to main content

mlua_check/
config.rs

1use std::collections::HashMap;
2
3use crate::types::{RuleId, Severity};
4
5/// Controls whether lint errors block execution.
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum LintPolicy {
8    /// Lint errors block execution.
9    Strict,
10    /// Lint issues are reported but execution proceeds.
11    Warn,
12    /// Linting is disabled entirely.
13    Off,
14}
15
16impl LintPolicy {
17    /// Parse from a string (e.g. MCP parameter).  Returns `Warn` for
18    /// unrecognised values.
19    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/// Per-rule severity overrides and global policy.
29#[derive(Debug, Clone)]
30pub struct LintConfig {
31    pub policy: LintPolicy,
32    /// Override the default severity for individual rules.
33    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    /// Resolve the effective severity for a rule.  Falls back to the
52    /// provided default when no override is configured.
53    pub fn severity_for(&self, rule: RuleId, default: Severity) -> Severity {
54        self.rule_severity.get(&rule).copied().unwrap_or(default)
55    }
56}