1pub mod code_fence_utils;
2pub mod emphasis_style;
3pub mod front_matter_utils;
4pub mod heading_utils;
5pub mod strong_style;
6
7mod md001_heading_increment;
8mod md003_heading_style;
9pub mod md004_unordered_list_style;
10mod md005_list_indent;
11pub mod md007_ul_indent;
12mod md009_trailing_spaces;
13pub mod md010_no_hard_tabs;
14mod md011_no_reversed_links;
15pub mod md013_line_length;
16mod md014_commands_show_output;
17mod md024_no_duplicate_heading;
18mod md025_single_title;
19mod md026_no_trailing_punctuation;
20mod md027_multiple_spaces_blockquote;
21mod md028_no_blanks_blockquote;
22mod md029_ordered_list_prefix;
23pub mod md030_list_marker_space;
24mod md031_blanks_around_fences;
25mod md032_blanks_around_lists;
26mod md033_no_inline_html;
27mod md034_no_bare_urls;
28mod md035_hr_style;
29pub mod md036_no_emphasis_only_first;
30mod md037_spaces_around_emphasis;
31mod md038_no_space_in_code;
32mod md039_no_space_in_links;
33pub mod md040_fenced_code_language;
34mod md041_first_line_heading;
35mod md042_no_empty_links;
36mod md043_required_headings;
37mod md044_proper_names;
38mod md045_no_alt_text;
39mod md046_code_block_style;
40mod md047_single_trailing_newline;
41mod md048_code_fence_style;
42mod md049_emphasis_style;
43mod md050_strong_style;
44pub mod md051_link_fragments;
45mod md052_reference_links_images;
46mod md053_link_image_reference_definitions;
47mod md054_link_image_style;
48mod md055_table_pipe_style;
49mod md056_table_column_count;
50mod md058_blanks_around_tables;
51mod md059_link_text;
52mod md060_table_format;
53mod md061_forbidden_terms;
54mod md062_link_destination_whitespace;
55mod md063_heading_capitalization;
56mod md064_no_multiple_consecutive_spaces;
57mod md065_blanks_around_horizontal_rules;
58mod md066_footnote_validation;
59mod md067_footnote_definition_order;
60mod md068_empty_footnote_definition;
61mod md069_no_duplicate_list_markers;
62mod md070_nested_code_fence;
63mod md071_blank_line_after_frontmatter;
64mod md072_frontmatter_key_sort;
65mod md073_toc_validation;
66mod md074_mkdocs_nav;
67mod md075_orphaned_table_rows;
68mod md076_list_item_spacing;
69mod md077_list_continuation_indent;
70mod md078_missing_chunk_labels;
71mod md079_chunk_label_spaces;
72mod md080_heading_anchor_collision;
73mod md081_no_excessive_emphasis;
74mod md082_no_empty_sections;
75
76pub use code_fence_utils::CodeFenceStyle;
77pub use md001_heading_increment::MD001HeadingIncrement;
78pub use md003_heading_style::MD003HeadingStyle;
79pub use md004_unordered_list_style::MD004UnorderedListStyle;
80pub use md004_unordered_list_style::UnorderedListStyle;
81pub use md005_list_indent::MD005ListIndent;
82pub use md007_ul_indent::MD007ULIndent;
83pub use md009_trailing_spaces::MD009TrailingSpaces;
84pub use md010_no_hard_tabs::{MD010Config, MD010NoHardTabs};
85pub use md011_no_reversed_links::MD011NoReversedLinks;
86pub use md013_line_length::MD013Config;
87pub use md013_line_length::MD013LineLength;
88pub use md014_commands_show_output::MD014CommandsShowOutput;
89pub use md024_no_duplicate_heading::MD024NoDuplicateHeading;
90pub use md025_single_title::MD025SingleTitle;
91pub use md026_no_trailing_punctuation::MD026NoTrailingPunctuation;
92pub use md027_multiple_spaces_blockquote::MD027MultipleSpacesBlockquote;
93pub use md028_no_blanks_blockquote::MD028NoBlanksBlockquote;
94pub use md029_ordered_list_prefix::{ListStyle, MD029OrderedListPrefix};
95pub use md030_list_marker_space::MD030ListMarkerSpace;
96pub use md031_blanks_around_fences::MD031BlanksAroundFences;
97pub use md032_blanks_around_lists::MD032BlanksAroundLists;
98pub use md033_no_inline_html::MD033NoInlineHtml;
99pub use md034_no_bare_urls::MD034NoBareUrls;
100pub use md035_hr_style::MD035HRStyle;
101pub use md036_no_emphasis_only_first::MD036NoEmphasisAsHeading;
102pub use md037_spaces_around_emphasis::MD037NoSpaceInEmphasis;
103pub use md038_no_space_in_code::MD038NoSpaceInCode;
104pub use md039_no_space_in_links::MD039NoSpaceInLinks;
105pub use md040_fenced_code_language::MD040FencedCodeLanguage;
106pub use md041_first_line_heading::MD041FirstLineHeading;
107pub use md042_no_empty_links::MD042NoEmptyLinks;
108pub use md043_required_headings::MD043RequiredHeadings;
109pub use md044_proper_names::MD044ProperNames;
110pub use md045_no_alt_text::MD045NoAltText;
111pub use md046_code_block_style::{CodeBlockStyle, MD046CodeBlockStyle};
112pub use md047_single_trailing_newline::MD047SingleTrailingNewline;
113pub use md048_code_fence_style::MD048CodeFenceStyle;
114pub use md049_emphasis_style::MD049EmphasisStyle;
115pub use md050_strong_style::MD050StrongStyle;
116pub use md051_link_fragments::MD051LinkFragments;
117pub use md052_reference_links_images::MD052ReferenceLinkImages;
118pub use md053_link_image_reference_definitions::MD053LinkImageReferenceDefinitions;
119pub use md054_link_image_style::MD054LinkImageStyle;
120pub use md055_table_pipe_style::MD055TablePipeStyle;
121pub use md056_table_column_count::MD056TableColumnCount;
122pub use md058_blanks_around_tables::MD058BlanksAroundTables;
123pub use md059_link_text::MD059LinkText;
124pub use md060_table_format::ColumnAlign;
125pub use md060_table_format::MD060Config;
126pub use md060_table_format::MD060TableFormat;
127pub use md061_forbidden_terms::MD061ForbiddenTerms;
128pub use md062_link_destination_whitespace::MD062LinkDestinationWhitespace;
129pub use md063_heading_capitalization::MD063HeadingCapitalization;
130pub use md064_no_multiple_consecutive_spaces::MD064NoMultipleConsecutiveSpaces;
131pub use md065_blanks_around_horizontal_rules::MD065BlanksAroundHorizontalRules;
132pub use md066_footnote_validation::MD066FootnoteValidation;
133pub use md067_footnote_definition_order::MD067FootnoteDefinitionOrder;
134pub use md068_empty_footnote_definition::MD068EmptyFootnoteDefinition;
135pub use md069_no_duplicate_list_markers::MD069NoDuplicateListMarkers;
136pub use md070_nested_code_fence::MD070NestedCodeFence;
137pub use md071_blank_line_after_frontmatter::MD071BlankLineAfterFrontmatter;
138pub use md072_frontmatter_key_sort::MD072FrontmatterKeySort;
139pub use md073_toc_validation::MD073TocValidation;
140pub use md074_mkdocs_nav::MD074MkDocsNav;
141pub use md075_orphaned_table_rows::MD075OrphanedTableRows;
142pub use md076_list_item_spacing::{ListItemSpacingStyle, MD076ListItemSpacing};
143pub use md077_list_continuation_indent::{ContinuationStyle, MD077ListContinuationIndent};
144pub use md078_missing_chunk_labels::MD078MissingChunkLabels;
145pub use md079_chunk_label_spaces::MD079ChunkLabelSpaces;
146pub use md080_heading_anchor_collision::MD080HeadingAnchorCollision;
147pub use md081_no_excessive_emphasis::MD081NoExcessiveEmphasis;
148pub use md082_no_empty_sections::MD082NoEmptySections;
149
150mod md012_no_multiple_blanks;
151pub use md012_no_multiple_blanks::MD012NoMultipleBlanks;
152
153mod md018_no_missing_space_atx;
154pub use md018_no_missing_space_atx::MD018NoMissingSpaceAtx;
155
156mod md019_no_multiple_space_atx;
157pub use md019_no_multiple_space_atx::MD019NoMultipleSpaceAtx;
158
159mod md020_no_missing_space_closed_atx;
160mod md021_no_multiple_space_closed_atx;
161pub use md020_no_missing_space_closed_atx::MD020NoMissingSpaceClosedAtx;
162pub use md021_no_multiple_space_closed_atx::MD021NoMultipleSpaceClosedAtx;
163
164pub(crate) mod md022_blanks_around_headings;
165pub use md022_blanks_around_headings::MD022BlanksAroundHeadings;
166
167mod md023_heading_start_left;
168pub use md023_heading_start_left::MD023HeadingStartLeft;
169
170mod md057_existing_relative_links;
171
172pub use md057_existing_relative_links::{AbsoluteLinksOption, MD057Config, MD057ExistingRelativeLinks};
173
174use crate::rule::Rule;
175
176type RuleCtor = fn(&crate::config::Config) -> Box<dyn Rule>;
178
179struct RuleEntry {
181 name: &'static str,
182 ctor: RuleCtor,
183 opt_in: bool,
185}
186
187const RULES: &[RuleEntry] = &[
194 RuleEntry {
195 name: "MD001",
196 ctor: MD001HeadingIncrement::from_config,
197 opt_in: false,
198 },
199 RuleEntry {
200 name: "MD003",
201 ctor: MD003HeadingStyle::from_config,
202 opt_in: false,
203 },
204 RuleEntry {
205 name: "MD004",
206 ctor: MD004UnorderedListStyle::from_config,
207 opt_in: false,
208 },
209 RuleEntry {
210 name: "MD005",
211 ctor: MD005ListIndent::from_config,
212 opt_in: false,
213 },
214 RuleEntry {
215 name: "MD007",
216 ctor: MD007ULIndent::from_config,
217 opt_in: false,
218 },
219 RuleEntry {
220 name: "MD009",
221 ctor: MD009TrailingSpaces::from_config,
222 opt_in: false,
223 },
224 RuleEntry {
225 name: "MD010",
226 ctor: MD010NoHardTabs::from_config,
227 opt_in: false,
228 },
229 RuleEntry {
230 name: "MD011",
231 ctor: MD011NoReversedLinks::from_config,
232 opt_in: false,
233 },
234 RuleEntry {
235 name: "MD012",
236 ctor: MD012NoMultipleBlanks::from_config,
237 opt_in: false,
238 },
239 RuleEntry {
240 name: "MD013",
241 ctor: MD013LineLength::from_config,
242 opt_in: false,
243 },
244 RuleEntry {
245 name: "MD014",
246 ctor: MD014CommandsShowOutput::from_config,
247 opt_in: false,
248 },
249 RuleEntry {
250 name: "MD018",
251 ctor: MD018NoMissingSpaceAtx::from_config,
252 opt_in: false,
253 },
254 RuleEntry {
255 name: "MD019",
256 ctor: MD019NoMultipleSpaceAtx::from_config,
257 opt_in: false,
258 },
259 RuleEntry {
260 name: "MD020",
261 ctor: MD020NoMissingSpaceClosedAtx::from_config,
262 opt_in: false,
263 },
264 RuleEntry {
265 name: "MD021",
266 ctor: MD021NoMultipleSpaceClosedAtx::from_config,
267 opt_in: false,
268 },
269 RuleEntry {
270 name: "MD022",
271 ctor: MD022BlanksAroundHeadings::from_config,
272 opt_in: false,
273 },
274 RuleEntry {
275 name: "MD023",
276 ctor: MD023HeadingStartLeft::from_config,
277 opt_in: false,
278 },
279 RuleEntry {
280 name: "MD024",
281 ctor: MD024NoDuplicateHeading::from_config,
282 opt_in: false,
283 },
284 RuleEntry {
285 name: "MD025",
286 ctor: MD025SingleTitle::from_config,
287 opt_in: false,
288 },
289 RuleEntry {
290 name: "MD026",
291 ctor: MD026NoTrailingPunctuation::from_config,
292 opt_in: false,
293 },
294 RuleEntry {
295 name: "MD027",
296 ctor: MD027MultipleSpacesBlockquote::from_config,
297 opt_in: false,
298 },
299 RuleEntry {
300 name: "MD028",
301 ctor: MD028NoBlanksBlockquote::from_config,
302 opt_in: false,
303 },
304 RuleEntry {
305 name: "MD029",
306 ctor: MD029OrderedListPrefix::from_config,
307 opt_in: false,
308 },
309 RuleEntry {
310 name: "MD030",
311 ctor: MD030ListMarkerSpace::from_config,
312 opt_in: false,
313 },
314 RuleEntry {
315 name: "MD031",
316 ctor: MD031BlanksAroundFences::from_config,
317 opt_in: false,
318 },
319 RuleEntry {
320 name: "MD032",
321 ctor: MD032BlanksAroundLists::from_config,
322 opt_in: false,
323 },
324 RuleEntry {
325 name: "MD033",
326 ctor: MD033NoInlineHtml::from_config,
327 opt_in: false,
328 },
329 RuleEntry {
330 name: "MD034",
331 ctor: MD034NoBareUrls::from_config,
332 opt_in: false,
333 },
334 RuleEntry {
335 name: "MD035",
336 ctor: MD035HRStyle::from_config,
337 opt_in: false,
338 },
339 RuleEntry {
340 name: "MD036",
341 ctor: MD036NoEmphasisAsHeading::from_config,
342 opt_in: false,
343 },
344 RuleEntry {
345 name: "MD037",
346 ctor: MD037NoSpaceInEmphasis::from_config,
347 opt_in: false,
348 },
349 RuleEntry {
350 name: "MD038",
351 ctor: MD038NoSpaceInCode::from_config,
352 opt_in: false,
353 },
354 RuleEntry {
355 name: "MD039",
356 ctor: MD039NoSpaceInLinks::from_config,
357 opt_in: false,
358 },
359 RuleEntry {
360 name: "MD040",
361 ctor: MD040FencedCodeLanguage::from_config,
362 opt_in: false,
363 },
364 RuleEntry {
365 name: "MD041",
366 ctor: MD041FirstLineHeading::from_config,
367 opt_in: false,
368 },
369 RuleEntry {
370 name: "MD042",
371 ctor: MD042NoEmptyLinks::from_config,
372 opt_in: false,
373 },
374 RuleEntry {
375 name: "MD043",
376 ctor: MD043RequiredHeadings::from_config,
377 opt_in: false,
378 },
379 RuleEntry {
380 name: "MD044",
381 ctor: MD044ProperNames::from_config,
382 opt_in: false,
383 },
384 RuleEntry {
385 name: "MD045",
386 ctor: MD045NoAltText::from_config,
387 opt_in: false,
388 },
389 RuleEntry {
390 name: "MD046",
391 ctor: MD046CodeBlockStyle::from_config,
392 opt_in: false,
393 },
394 RuleEntry {
395 name: "MD047",
396 ctor: MD047SingleTrailingNewline::from_config,
397 opt_in: false,
398 },
399 RuleEntry {
400 name: "MD048",
401 ctor: MD048CodeFenceStyle::from_config,
402 opt_in: false,
403 },
404 RuleEntry {
405 name: "MD049",
406 ctor: MD049EmphasisStyle::from_config,
407 opt_in: false,
408 },
409 RuleEntry {
410 name: "MD050",
411 ctor: MD050StrongStyle::from_config,
412 opt_in: false,
413 },
414 RuleEntry {
415 name: "MD051",
416 ctor: MD051LinkFragments::from_config,
417 opt_in: false,
418 },
419 RuleEntry {
420 name: "MD052",
421 ctor: MD052ReferenceLinkImages::from_config,
422 opt_in: false,
423 },
424 RuleEntry {
425 name: "MD053",
426 ctor: MD053LinkImageReferenceDefinitions::from_config,
427 opt_in: false,
428 },
429 RuleEntry {
430 name: "MD054",
431 ctor: MD054LinkImageStyle::from_config,
432 opt_in: false,
433 },
434 RuleEntry {
435 name: "MD055",
436 ctor: MD055TablePipeStyle::from_config,
437 opt_in: false,
438 },
439 RuleEntry {
440 name: "MD056",
441 ctor: MD056TableColumnCount::from_config,
442 opt_in: false,
443 },
444 RuleEntry {
445 name: "MD057",
446 ctor: MD057ExistingRelativeLinks::from_config,
447 opt_in: false,
448 },
449 RuleEntry {
450 name: "MD058",
451 ctor: MD058BlanksAroundTables::from_config,
452 opt_in: false,
453 },
454 RuleEntry {
455 name: "MD059",
456 ctor: MD059LinkText::from_config,
457 opt_in: false,
458 },
459 RuleEntry {
460 name: "MD060",
461 ctor: MD060TableFormat::from_config,
462 opt_in: true,
463 },
464 RuleEntry {
465 name: "MD061",
466 ctor: MD061ForbiddenTerms::from_config,
467 opt_in: false,
468 },
469 RuleEntry {
470 name: "MD062",
471 ctor: MD062LinkDestinationWhitespace::from_config,
472 opt_in: false,
473 },
474 RuleEntry {
475 name: "MD063",
476 ctor: MD063HeadingCapitalization::from_config,
477 opt_in: true,
478 },
479 RuleEntry {
480 name: "MD064",
481 ctor: MD064NoMultipleConsecutiveSpaces::from_config,
482 opt_in: false,
483 },
484 RuleEntry {
485 name: "MD065",
486 ctor: MD065BlanksAroundHorizontalRules::from_config,
487 opt_in: false,
488 },
489 RuleEntry {
490 name: "MD066",
491 ctor: MD066FootnoteValidation::from_config,
492 opt_in: false,
493 },
494 RuleEntry {
495 name: "MD067",
496 ctor: MD067FootnoteDefinitionOrder::from_config,
497 opt_in: false,
498 },
499 RuleEntry {
500 name: "MD068",
501 ctor: MD068EmptyFootnoteDefinition::from_config,
502 opt_in: false,
503 },
504 RuleEntry {
505 name: "MD069",
506 ctor: MD069NoDuplicateListMarkers::from_config,
507 opt_in: false,
508 },
509 RuleEntry {
510 name: "MD070",
511 ctor: MD070NestedCodeFence::from_config,
512 opt_in: true,
513 },
514 RuleEntry {
515 name: "MD071",
516 ctor: MD071BlankLineAfterFrontmatter::from_config,
517 opt_in: false,
518 },
519 RuleEntry {
520 name: "MD072",
521 ctor: MD072FrontmatterKeySort::from_config,
522 opt_in: true,
523 },
524 RuleEntry {
525 name: "MD073",
526 ctor: MD073TocValidation::from_config,
527 opt_in: true,
528 },
529 RuleEntry {
530 name: "MD074",
531 ctor: MD074MkDocsNav::from_config,
532 opt_in: true,
533 },
534 RuleEntry {
535 name: "MD075",
536 ctor: MD075OrphanedTableRows::from_config,
537 opt_in: false,
538 },
539 RuleEntry {
540 name: "MD076",
541 ctor: MD076ListItemSpacing::from_config,
542 opt_in: false,
543 },
544 RuleEntry {
545 name: "MD077",
546 ctor: MD077ListContinuationIndent::from_config,
547 opt_in: false,
548 },
549 RuleEntry {
550 name: "MD078",
551 ctor: MD078MissingChunkLabels::from_config,
552 opt_in: false,
553 },
554 RuleEntry {
555 name: "MD079",
556 ctor: MD079ChunkLabelSpaces::from_config,
557 opt_in: false,
558 },
559 RuleEntry {
560 name: "MD080",
561 ctor: MD080HeadingAnchorCollision::from_config,
562 opt_in: true,
563 },
564 RuleEntry {
565 name: "MD081",
566 ctor: MD081NoExcessiveEmphasis::from_config,
567 opt_in: false,
568 },
569 RuleEntry {
570 name: "MD082",
571 ctor: MD082NoEmptySections::from_config,
572 opt_in: true,
573 },
574];
575
576pub fn all_rules(config: &crate::config::Config) -> Vec<Box<dyn Rule>> {
578 RULES.iter().map(|entry| (entry.ctor)(config)).collect()
579}
580
581pub fn opt_in_rules() -> HashSet<&'static str> {
583 RULES
584 .iter()
585 .filter(|entry| entry.opt_in)
586 .map(|entry| entry.name)
587 .collect()
588}
589
590pub fn create_rule_by_name(name: &str, config: &crate::config::Config) -> Option<Box<dyn Rule>> {
597 RULES
598 .iter()
599 .find(|entry| entry.name == name)
600 .map(|entry| (entry.ctor)(config))
601}
602
603use crate::config::GlobalConfig;
606use std::collections::HashSet;
607
608fn contains_all_keyword(list: &[String]) -> bool {
610 list.iter().any(|s| s.eq_ignore_ascii_case("all"))
611}
612
613fn canonical_rule_set(list: &[String]) -> HashSet<String> {
620 list.iter()
621 .map(|s| {
622 if s.eq_ignore_ascii_case("all") {
623 "all".to_string()
624 } else {
625 crate::config::resolve_rule_name(s)
626 }
627 })
628 .collect()
629}
630
631pub fn filter_rules(rules: &[Box<dyn Rule>], global_config: &GlobalConfig) -> Vec<Box<dyn Rule>> {
642 let mut enabled_rules: Vec<Box<dyn Rule>> = Vec::new();
643 let disabled_rules: HashSet<String> = canonical_rule_set(&global_config.disable);
644 let opt_in_set = opt_in_rules();
645 let extend_enable_set: HashSet<String> = canonical_rule_set(&global_config.extend_enable);
646 let extend_disable_set: HashSet<String> = canonical_rule_set(&global_config.extend_disable);
647
648 let extend_enable_all = contains_all_keyword(&global_config.extend_enable);
649 let extend_disable_all = contains_all_keyword(&global_config.extend_disable);
650
651 let is_disabled = |name: &str| -> bool {
653 disabled_rules.contains(name) || extend_disable_all || extend_disable_set.contains(name)
654 };
655
656 if disabled_rules.contains("all") {
658 if !global_config.enable.is_empty() {
660 if contains_all_keyword(&global_config.enable) {
661 for rule in rules {
663 enabled_rules.push(dyn_clone::clone_box(&**rule));
664 }
665 } else {
666 let enabled_set: HashSet<String> = canonical_rule_set(&global_config.enable);
667 for rule in rules {
668 if enabled_set.contains(rule.name()) {
669 enabled_rules.push(dyn_clone::clone_box(&**rule));
670 }
671 }
672 }
673 }
674 return enabled_rules;
676 }
677
678 if !global_config.enable.is_empty() || global_config.enable_is_explicit {
680 if contains_all_keyword(&global_config.enable) || extend_enable_all {
681 for rule in rules {
683 if !is_disabled(rule.name()) {
684 enabled_rules.push(dyn_clone::clone_box(&**rule));
685 }
686 }
687 } else {
688 let mut enabled_set: HashSet<String> = canonical_rule_set(&global_config.enable);
690 for name in &extend_enable_set {
691 enabled_set.insert(name.clone());
692 }
693 for rule in rules {
694 if enabled_set.contains(rule.name()) && !is_disabled(rule.name()) {
695 enabled_rules.push(dyn_clone::clone_box(&**rule));
696 }
697 }
698 }
699 } else if extend_enable_all {
700 for rule in rules {
702 if !is_disabled(rule.name()) {
703 enabled_rules.push(dyn_clone::clone_box(&**rule));
704 }
705 }
706 } else {
707 for rule in rules {
709 let is_opt_in = opt_in_set.contains(rule.name());
710 let explicitly_extended = extend_enable_set.contains(rule.name());
711 if (!is_opt_in || explicitly_extended) && !is_disabled(rule.name()) {
712 enabled_rules.push(dyn_clone::clone_box(&**rule));
713 }
714 }
715 }
716
717 enabled_rules
718}
719
720#[cfg(test)]
721mod filter_rules_alias_tests {
722 use super::*;
723 use crate::config::Config;
724
725 #[test]
730 fn alias_in_disable_filters_canonical_rule() {
731 let config = Config::default();
732 let rules = all_rules(&config);
733 let global = GlobalConfig {
734 disable: vec!["no-inline-html".to_string()],
735 ..Default::default()
736 };
737
738 let filtered = filter_rules(&rules, &global);
739 assert!(
740 !filtered.iter().any(|r| r.name() == "MD033"),
741 "filter_rules must drop MD033 when its alias `no-inline-html` is in disable, \
742 even on a hand-built GlobalConfig. Got: {:?}",
743 filtered.iter().map(|r| r.name()).collect::<Vec<_>>(),
744 );
745 }
746
747 #[test]
749 fn alias_in_extend_disable_filters_canonical_rule() {
750 let config = Config::default();
751 let rules = all_rules(&config);
752 let global = GlobalConfig {
753 extend_disable: vec!["line-length".to_string()],
754 ..Default::default()
755 };
756
757 let filtered = filter_rules(&rules, &global);
758 assert!(
759 !filtered.iter().any(|r| r.name() == "MD013"),
760 "filter_rules must drop MD013 when alias `line-length` is in extend_disable. Got: {:?}",
761 filtered.iter().map(|r| r.name()).collect::<Vec<_>>(),
762 );
763 }
764
765 #[test]
767 fn alias_in_enable_selects_canonical_rule() {
768 let config = Config::default();
769 let rules = all_rules(&config);
770 let global = GlobalConfig {
771 enable: vec!["no-inline-html".to_string()],
772 ..Default::default()
773 };
774
775 let filtered = filter_rules(&rules, &global);
776 let names: Vec<&str> = filtered.iter().map(|r| r.name()).collect();
777 assert_eq!(
778 names,
779 vec!["MD033"],
780 "filter_rules must select only MD033 when alias `no-inline-html` is the sole enable. \
781 Got: {names:?}",
782 );
783 }
784
785 #[test]
788 fn alias_and_canonical_produce_identical_filter_result() {
789 let config = Config::default();
790 let rules = all_rules(&config);
791
792 let alias_global = GlobalConfig {
793 disable: vec!["no-inline-html".to_string(), "line-length".to_string()],
794 ..Default::default()
795 };
796 let canonical_global = GlobalConfig {
797 disable: vec!["MD033".to_string(), "MD013".to_string()],
798 ..Default::default()
799 };
800
801 let alias_names: Vec<&str> = filter_rules(&rules, &alias_global).iter().map(|r| r.name()).collect();
802 let canonical_names: Vec<&str> = filter_rules(&rules, &canonical_global)
803 .iter()
804 .map(|r| r.name())
805 .collect();
806 assert_eq!(alias_names, canonical_names);
807 }
808}