use crate::rule_config_serde::RuleConfig;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
#[serde(rename_all = "kebab-case")]
pub struct MD018Config {
#[serde(default)]
pub magiclink: bool,
}
impl RuleConfig for MD018Config {
const RULE_NAME: &'static str = "MD018";
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_magiclink_disabled() {
let config = MD018Config::default();
assert!(!config.magiclink, "magiclink should default to false");
}
#[test]
fn test_magiclink_enabled() {
let toml_str = r#"
magiclink = true
"#;
let config: MD018Config = toml::from_str(toml_str).unwrap();
assert!(config.magiclink);
}
#[test]
fn test_magiclink_disabled_explicit() {
let toml_str = r#"
magiclink = false
"#;
let config: MD018Config = toml::from_str(toml_str).unwrap();
assert!(!config.magiclink);
}
#[test]
fn test_empty_config() {
let toml_str = "";
let config: MD018Config = toml::from_str(toml_str).unwrap();
assert!(!config.magiclink);
}
#[test]
fn test_from_config_loads_magiclink() {
use crate::config::Config;
use crate::rule::Rule;
let toml_str = r#"
[MD018]
magiclink = true
"#;
let config: Config = toml::from_str(toml_str).unwrap();
let rule = super::super::MD018NoMissingSpaceAtx::from_config(&config);
let content = "#10 is an issue ref\n#Summary";
let ctx = crate::lint_context::LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
let result = rule.check(&ctx).unwrap();
assert_eq!(result.len(), 1, "Should only flag #Summary, not #10");
assert!(
result[0].message.contains("Summary") || result[0].line == 2,
"Should flag line 2 (#Summary)"
);
}
}