Skip to main content

mkdlint/types/
options.rs

1//! Options for configuring lint operations
2
3use crate::config::Config;
4use crate::types::BoxedRule;
5use std::collections::HashMap;
6
7/// Options for linting markdown content
8#[derive(Default)]
9pub struct LintOptions {
10    /// Files to lint (paths)
11    pub files: Vec<String>,
12
13    /// Strings to lint (keyed by identifier)
14    pub strings: HashMap<String, String>,
15
16    /// Configuration object
17    pub config: Option<Config>,
18
19    /// Path to configuration file
20    pub config_file: Option<String>,
21
22    /// Custom rules to use
23    pub custom_rules: Vec<BoxedRule>,
24
25    /// Front matter pattern (regex)
26    pub front_matter: Option<String>,
27
28    /// Whether to ignore inline configuration
29    pub no_inline_config: bool,
30
31    /// Result version for backward compatibility
32    pub result_version: u32,
33
34    /// Handle errors during rule execution
35    pub handle_rule_failures: bool,
36}
37
38impl LintOptions {
39    /// Create a new LintOptions with default values
40    pub fn new() -> Self {
41        Self::default()
42    }
43
44    /// Add a file to lint
45    pub fn with_file(mut self, file: impl Into<String>) -> Self {
46        self.files.push(file.into());
47        self
48    }
49
50    /// Add multiple files to lint
51    pub fn with_files(mut self, files: impl IntoIterator<Item = impl Into<String>>) -> Self {
52        self.files.extend(files.into_iter().map(Into::into));
53        self
54    }
55
56    /// Add a string to lint
57    pub fn with_string(mut self, name: impl Into<String>, content: impl Into<String>) -> Self {
58        self.strings.insert(name.into(), content.into());
59        self
60    }
61
62    /// Set the configuration
63    pub fn with_config(mut self, config: Config) -> Self {
64        self.config = Some(config);
65        self
66    }
67
68    /// Set the configuration file path
69    pub fn with_config_file(mut self, path: impl Into<String>) -> Self {
70        self.config_file = Some(path.into());
71        self
72    }
73
74    /// Add a custom rule
75    pub fn with_custom_rule(mut self, rule: BoxedRule) -> Self {
76        self.custom_rules.push(rule);
77        self
78    }
79
80    /// Set the front matter pattern
81    pub fn with_front_matter(mut self, pattern: impl Into<String>) -> Self {
82        self.front_matter = Some(pattern.into());
83        self
84    }
85
86    /// Disable inline configuration
87    pub fn no_inline_config(mut self) -> Self {
88        self.no_inline_config = true;
89        self
90    }
91}