Skip to main content

mdlint/config/
types.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Deserialize, Serialize)]
5pub struct Config {
6    /// Rule configuration: rule name -> config
7    #[serde(default)]
8    pub rules: HashMap<String, RuleConfig>,
9
10    /// Enable all rules by default
11    #[serde(default = "default_default_enabled")]
12    pub default_enabled: bool,
13
14    /// Custom rule paths (for future extension)
15    #[serde(default)]
16    pub custom_rules: Vec<String>,
17
18    /// Respect .gitignore files when discovering files
19    #[serde(default = "default_gitignore")]
20    pub gitignore: bool,
21
22    /// Front matter pattern (YAML --- or TOML +++)
23    #[serde(default)]
24    pub front_matter: Option<String>,
25
26    /// Disable inline configuration comments
27    #[serde(default)]
28    pub no_inline_config: bool,
29
30    /// Paths and glob patterns to exclude from file discovery
31    #[serde(default)]
32    pub exclude: Vec<String>,
33
34    /// Apply auto-fixes automatically when running `mdlint check`
35    #[serde(default = "default_fix")]
36    pub fix: bool,
37}
38
39fn default_default_enabled() -> bool {
40    true
41}
42
43fn default_gitignore() -> bool {
44    true
45}
46
47fn default_fix() -> bool {
48    true
49}
50
51impl Default for Config {
52    fn default() -> Self {
53        Self {
54            rules: HashMap::new(),
55            default_enabled: true,
56            custom_rules: Vec::new(),
57            gitignore: default_gitignore(),
58            front_matter: None,
59            no_inline_config: false,
60            exclude: Vec::new(),
61            fix: true,
62        }
63    }
64}
65
66#[derive(Debug, Clone, Deserialize, Serialize)]
67#[serde(untagged)]
68pub enum RuleConfig {
69    Enabled(bool),
70    Config(HashMap<String, toml::Value>),
71}
72
73// Legacy field mappings for backward compatibility with old config structure
74impl Config {
75    /// Legacy accessor for config field (now called rules)
76    pub fn config(&self) -> &HashMap<String, RuleConfig> {
77        &self.rules
78    }
79}