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;
75mod md083_mojibake;
76mod md084_invisible_characters;
77mod md085_paragraph_continuation_indent;
78mod md086_no_unclosed_comments;
79mod md087_unused_disable_comment;
80mod md088_quotes_dashes;
81mod md089_cjk_spacing;
82mod md090_no_hr_before_heading;
83mod md091_no_markdown_in_html;
84
85pub use code_fence_utils::CodeFenceStyle;
86pub use md001_heading_increment::MD001HeadingIncrement;
87pub use md003_heading_style::MD003HeadingStyle;
88pub use md004_unordered_list_style::MD004UnorderedListStyle;
89pub use md004_unordered_list_style::UnorderedListStyle;
90pub use md005_list_indent::MD005ListIndent;
91pub use md007_ul_indent::MD007ULIndent;
92pub use md009_trailing_spaces::MD009TrailingSpaces;
93pub use md010_no_hard_tabs::{MD010Config, MD010NoHardTabs};
94pub use md011_no_reversed_links::MD011NoReversedLinks;
95pub use md013_line_length::MD013Config;
96pub use md013_line_length::MD013LineLength;
97pub use md014_commands_show_output::MD014CommandsShowOutput;
98pub use md024_no_duplicate_heading::MD024NoDuplicateHeading;
99pub use md025_single_title::MD025SingleTitle;
100pub use md026_no_trailing_punctuation::MD026NoTrailingPunctuation;
101pub use md027_multiple_spaces_blockquote::MD027MultipleSpacesBlockquote;
102pub use md028_no_blanks_blockquote::MD028NoBlanksBlockquote;
103pub use md029_ordered_list_prefix::{ListStyle, MD029OrderedListPrefix};
104pub use md030_list_marker_space::MD030ListMarkerSpace;
105pub use md031_blanks_around_fences::MD031BlanksAroundFences;
106pub use md032_blanks_around_lists::MD032BlanksAroundLists;
107pub use md033_no_inline_html::MD033NoInlineHtml;
108pub use md034_no_bare_urls::MD034NoBareUrls;
109pub use md035_hr_style::MD035HRStyle;
110pub use md036_no_emphasis_only_first::MD036NoEmphasisAsHeading;
111pub use md037_spaces_around_emphasis::MD037NoSpaceInEmphasis;
112pub use md038_no_space_in_code::MD038NoSpaceInCode;
113pub use md039_no_space_in_links::MD039NoSpaceInLinks;
114pub use md040_fenced_code_language::MD040FencedCodeLanguage;
115pub use md041_first_line_heading::MD041FirstLineHeading;
116pub use md042_no_empty_links::MD042NoEmptyLinks;
117pub use md043_required_headings::MD043RequiredHeadings;
118pub use md044_proper_names::MD044ProperNames;
119pub use md045_no_alt_text::MD045NoAltText;
120pub use md046_code_block_style::{CodeBlockStyle, MD046CodeBlockStyle};
121pub use md047_single_trailing_newline::MD047SingleTrailingNewline;
122pub use md048_code_fence_style::MD048CodeFenceStyle;
123pub use md049_emphasis_style::MD049EmphasisStyle;
124pub use md050_strong_style::MD050StrongStyle;
125pub use md051_link_fragments::MD051LinkFragments;
126pub use md052_reference_links_images::MD052ReferenceLinkImages;
127pub use md053_link_image_reference_definitions::MD053LinkImageReferenceDefinitions;
128pub use md054_link_image_style::MD054LinkImageStyle;
129pub use md055_table_pipe_style::MD055TablePipeStyle;
130pub use md056_table_column_count::MD056TableColumnCount;
131pub use md058_blanks_around_tables::MD058BlanksAroundTables;
132pub use md059_link_text::MD059LinkText;
133pub use md060_table_format::ColumnAlign;
134pub use md060_table_format::MD060Config;
135pub use md060_table_format::MD060TableFormat;
136pub use md061_forbidden_terms::MD061ForbiddenTerms;
137pub use md062_link_destination_whitespace::MD062LinkDestinationWhitespace;
138pub use md063_heading_capitalization::MD063HeadingCapitalization;
139pub use md064_no_multiple_consecutive_spaces::MD064NoMultipleConsecutiveSpaces;
140pub use md065_blanks_around_horizontal_rules::MD065BlanksAroundHorizontalRules;
141pub use md066_footnote_validation::MD066FootnoteValidation;
142pub use md067_footnote_definition_order::MD067FootnoteDefinitionOrder;
143pub use md068_empty_footnote_definition::MD068EmptyFootnoteDefinition;
144pub use md069_no_duplicate_list_markers::MD069NoDuplicateListMarkers;
145pub use md070_nested_code_fence::MD070NestedCodeFence;
146pub use md071_blank_line_after_frontmatter::MD071BlankLineAfterFrontmatter;
147pub use md072_frontmatter_key_sort::MD072FrontmatterKeySort;
148pub use md073_toc_validation::MD073TocValidation;
149pub use md074_mkdocs_nav::MD074MkDocsNav;
150pub use md075_orphaned_table_rows::MD075OrphanedTableRows;
151pub use md076_list_item_spacing::{ListItemSpacingStyle, MD076ListItemSpacing};
152pub use md077_list_continuation_indent::{ContinuationStyle, MD077ListContinuationIndent};
153pub use md078_missing_chunk_labels::MD078MissingChunkLabels;
154pub use md079_chunk_label_spaces::MD079ChunkLabelSpaces;
155pub use md080_heading_anchor_collision::MD080HeadingAnchorCollision;
156pub use md081_no_excessive_emphasis::MD081NoExcessiveEmphasis;
157pub use md082_no_empty_sections::MD082NoEmptySections;
158pub use md083_mojibake::MD083DetectMojibake;
159pub use md084_invisible_characters::MD084InvisibleCharacters;
160pub use md085_paragraph_continuation_indent::MD085ParagraphContinuationIndent;
161pub use md086_no_unclosed_comments::MD086NoUnclosedComments;
162pub use md087_unused_disable_comment::MD087UnusedDisableComment;
163pub use md088_quotes_dashes::MD088QuotesDashes;
164pub use md089_cjk_spacing::MD089CjkSpacing;
165pub use md090_no_hr_before_heading::MD090NoHrBeforeHeading;
166pub use md091_no_markdown_in_html::MD091NoMarkdownInHtml;
167
168mod md012_no_multiple_blanks;
169pub use md012_no_multiple_blanks::MD012NoMultipleBlanks;
170
171mod md018_no_missing_space_atx;
172pub use md018_no_missing_space_atx::MD018NoMissingSpaceAtx;
173
174mod md019_no_multiple_space_atx;
175pub use md019_no_multiple_space_atx::MD019NoMultipleSpaceAtx;
176
177mod md020_no_missing_space_closed_atx;
178mod md021_no_multiple_space_closed_atx;
179pub use md020_no_missing_space_closed_atx::MD020NoMissingSpaceClosedAtx;
180pub use md021_no_multiple_space_closed_atx::MD021NoMultipleSpaceClosedAtx;
181
182pub(crate) mod md022_blanks_around_headings;
183pub use md022_blanks_around_headings::MD022BlanksAroundHeadings;
184
185mod md023_heading_start_left;
186pub use md023_heading_start_left::MD023HeadingStartLeft;
187
188mod md057_existing_relative_links;
189
190pub use md057_existing_relative_links::{AbsoluteLinksOption, MD057Config, MD057ExistingRelativeLinks};
191
192use crate::rule::Rule;
193
194type RuleCtor = fn(&crate::config::Config) -> Box<dyn Rule>;
196
197struct RuleEntry {
199 name: &'static str,
200 primary_alias: &'static str,
202 ctor: RuleCtor,
203 opt_in: bool,
205}
206
207const RULES: &[RuleEntry] = &[
214 RuleEntry {
215 name: "MD001",
216 primary_alias: "heading-increment",
217 ctor: MD001HeadingIncrement::from_config,
218 opt_in: false,
219 },
220 RuleEntry {
221 name: "MD003",
222 primary_alias: "heading-style",
223 ctor: MD003HeadingStyle::from_config,
224 opt_in: false,
225 },
226 RuleEntry {
227 name: "MD004",
228 primary_alias: "ul-style",
229 ctor: MD004UnorderedListStyle::from_config,
230 opt_in: false,
231 },
232 RuleEntry {
233 name: "MD005",
234 primary_alias: "list-indent",
235 ctor: MD005ListIndent::from_config,
236 opt_in: false,
237 },
238 RuleEntry {
239 name: "MD007",
240 primary_alias: "ul-indent",
241 ctor: MD007ULIndent::from_config,
242 opt_in: false,
243 },
244 RuleEntry {
245 name: "MD009",
246 primary_alias: "no-trailing-spaces",
247 ctor: MD009TrailingSpaces::from_config,
248 opt_in: false,
249 },
250 RuleEntry {
251 name: "MD010",
252 primary_alias: "no-hard-tabs",
253 ctor: MD010NoHardTabs::from_config,
254 opt_in: false,
255 },
256 RuleEntry {
257 name: "MD011",
258 primary_alias: "no-reversed-links",
259 ctor: MD011NoReversedLinks::from_config,
260 opt_in: false,
261 },
262 RuleEntry {
263 name: "MD012",
264 primary_alias: "no-multiple-blanks",
265 ctor: MD012NoMultipleBlanks::from_config,
266 opt_in: false,
267 },
268 RuleEntry {
269 name: "MD013",
270 primary_alias: "line-length",
271 ctor: MD013LineLength::from_config,
272 opt_in: false,
273 },
274 RuleEntry {
275 name: "MD014",
276 primary_alias: "commands-show-output",
277 ctor: MD014CommandsShowOutput::from_config,
278 opt_in: false,
279 },
280 RuleEntry {
281 name: "MD018",
282 primary_alias: "no-missing-space-atx",
283 ctor: MD018NoMissingSpaceAtx::from_config,
284 opt_in: false,
285 },
286 RuleEntry {
287 name: "MD019",
288 primary_alias: "no-multiple-space-atx",
289 ctor: MD019NoMultipleSpaceAtx::from_config,
290 opt_in: false,
291 },
292 RuleEntry {
293 name: "MD020",
294 primary_alias: "no-missing-space-closed-atx",
295 ctor: MD020NoMissingSpaceClosedAtx::from_config,
296 opt_in: false,
297 },
298 RuleEntry {
299 name: "MD021",
300 primary_alias: "no-multiple-space-closed-atx",
301 ctor: MD021NoMultipleSpaceClosedAtx::from_config,
302 opt_in: false,
303 },
304 RuleEntry {
305 name: "MD022",
306 primary_alias: "blanks-around-headings",
307 ctor: MD022BlanksAroundHeadings::from_config,
308 opt_in: false,
309 },
310 RuleEntry {
311 name: "MD023",
312 primary_alias: "heading-start-left",
313 ctor: MD023HeadingStartLeft::from_config,
314 opt_in: false,
315 },
316 RuleEntry {
317 name: "MD024",
318 primary_alias: "no-duplicate-heading",
319 ctor: MD024NoDuplicateHeading::from_config,
320 opt_in: false,
321 },
322 RuleEntry {
323 name: "MD025",
324 primary_alias: "single-title",
325 ctor: MD025SingleTitle::from_config,
326 opt_in: false,
327 },
328 RuleEntry {
329 name: "MD026",
330 primary_alias: "no-trailing-punctuation",
331 ctor: MD026NoTrailingPunctuation::from_config,
332 opt_in: false,
333 },
334 RuleEntry {
335 name: "MD027",
336 primary_alias: "no-multiple-space-blockquote",
337 ctor: MD027MultipleSpacesBlockquote::from_config,
338 opt_in: false,
339 },
340 RuleEntry {
341 name: "MD028",
342 primary_alias: "no-blanks-blockquote",
343 ctor: MD028NoBlanksBlockquote::from_config,
344 opt_in: false,
345 },
346 RuleEntry {
347 name: "MD029",
348 primary_alias: "ol-prefix",
349 ctor: MD029OrderedListPrefix::from_config,
350 opt_in: false,
351 },
352 RuleEntry {
353 name: "MD030",
354 primary_alias: "list-marker-space",
355 ctor: MD030ListMarkerSpace::from_config,
356 opt_in: false,
357 },
358 RuleEntry {
359 name: "MD031",
360 primary_alias: "blanks-around-fences",
361 ctor: MD031BlanksAroundFences::from_config,
362 opt_in: false,
363 },
364 RuleEntry {
365 name: "MD032",
366 primary_alias: "blanks-around-lists",
367 ctor: MD032BlanksAroundLists::from_config,
368 opt_in: false,
369 },
370 RuleEntry {
371 name: "MD033",
372 primary_alias: "no-inline-html",
373 ctor: MD033NoInlineHtml::from_config,
374 opt_in: false,
375 },
376 RuleEntry {
377 name: "MD034",
378 primary_alias: "no-bare-urls",
379 ctor: MD034NoBareUrls::from_config,
380 opt_in: false,
381 },
382 RuleEntry {
383 name: "MD035",
384 primary_alias: "hr-style",
385 ctor: MD035HRStyle::from_config,
386 opt_in: false,
387 },
388 RuleEntry {
389 name: "MD036",
390 primary_alias: "no-emphasis-as-heading",
391 ctor: MD036NoEmphasisAsHeading::from_config,
392 opt_in: false,
393 },
394 RuleEntry {
395 name: "MD037",
396 primary_alias: "no-space-in-emphasis",
397 ctor: MD037NoSpaceInEmphasis::from_config,
398 opt_in: false,
399 },
400 RuleEntry {
401 name: "MD038",
402 primary_alias: "no-space-in-code",
403 ctor: MD038NoSpaceInCode::from_config,
404 opt_in: false,
405 },
406 RuleEntry {
407 name: "MD039",
408 primary_alias: "no-space-in-links",
409 ctor: MD039NoSpaceInLinks::from_config,
410 opt_in: false,
411 },
412 RuleEntry {
413 name: "MD040",
414 primary_alias: "fenced-code-language",
415 ctor: MD040FencedCodeLanguage::from_config,
416 opt_in: false,
417 },
418 RuleEntry {
419 name: "MD041",
420 primary_alias: "first-line-heading",
421 ctor: MD041FirstLineHeading::from_config,
422 opt_in: false,
423 },
424 RuleEntry {
425 name: "MD042",
426 primary_alias: "no-empty-links",
427 ctor: MD042NoEmptyLinks::from_config,
428 opt_in: false,
429 },
430 RuleEntry {
431 name: "MD043",
432 primary_alias: "required-headings",
433 ctor: MD043RequiredHeadings::from_config,
434 opt_in: false,
435 },
436 RuleEntry {
437 name: "MD044",
438 primary_alias: "proper-names",
439 ctor: MD044ProperNames::from_config,
440 opt_in: false,
441 },
442 RuleEntry {
443 name: "MD045",
444 primary_alias: "no-alt-text",
445 ctor: MD045NoAltText::from_config,
446 opt_in: false,
447 },
448 RuleEntry {
449 name: "MD046",
450 primary_alias: "code-block-style",
451 ctor: MD046CodeBlockStyle::from_config,
452 opt_in: false,
453 },
454 RuleEntry {
455 name: "MD047",
456 primary_alias: "single-trailing-newline",
457 ctor: MD047SingleTrailingNewline::from_config,
458 opt_in: false,
459 },
460 RuleEntry {
461 name: "MD048",
462 primary_alias: "code-fence-style",
463 ctor: MD048CodeFenceStyle::from_config,
464 opt_in: false,
465 },
466 RuleEntry {
467 name: "MD049",
468 primary_alias: "emphasis-style",
469 ctor: MD049EmphasisStyle::from_config,
470 opt_in: false,
471 },
472 RuleEntry {
473 name: "MD050",
474 primary_alias: "strong-style",
475 ctor: MD050StrongStyle::from_config,
476 opt_in: false,
477 },
478 RuleEntry {
479 name: "MD051",
480 primary_alias: "link-fragments",
481 ctor: MD051LinkFragments::from_config,
482 opt_in: false,
483 },
484 RuleEntry {
485 name: "MD052",
486 primary_alias: "reference-links-images",
487 ctor: MD052ReferenceLinkImages::from_config,
488 opt_in: false,
489 },
490 RuleEntry {
491 name: "MD053",
492 primary_alias: "link-image-reference-definitions",
493 ctor: MD053LinkImageReferenceDefinitions::from_config,
494 opt_in: false,
495 },
496 RuleEntry {
497 name: "MD054",
498 primary_alias: "link-image-style",
499 ctor: MD054LinkImageStyle::from_config,
500 opt_in: false,
501 },
502 RuleEntry {
503 name: "MD055",
504 primary_alias: "table-pipe-style",
505 ctor: MD055TablePipeStyle::from_config,
506 opt_in: false,
507 },
508 RuleEntry {
509 name: "MD056",
510 primary_alias: "table-column-count",
511 ctor: MD056TableColumnCount::from_config,
512 opt_in: false,
513 },
514 RuleEntry {
515 name: "MD057",
516 primary_alias: "existing-relative-links",
517 ctor: MD057ExistingRelativeLinks::from_config,
518 opt_in: false,
519 },
520 RuleEntry {
521 name: "MD058",
522 primary_alias: "blanks-around-tables",
523 ctor: MD058BlanksAroundTables::from_config,
524 opt_in: false,
525 },
526 RuleEntry {
527 name: "MD059",
528 primary_alias: "descriptive-link-text",
529 ctor: MD059LinkText::from_config,
530 opt_in: false,
531 },
532 RuleEntry {
533 name: "MD060",
534 primary_alias: "table-format",
535 ctor: MD060TableFormat::from_config,
536 opt_in: true,
537 },
538 RuleEntry {
539 name: "MD061",
540 primary_alias: "forbidden-terms",
541 ctor: MD061ForbiddenTerms::from_config,
542 opt_in: false,
543 },
544 RuleEntry {
545 name: "MD062",
546 primary_alias: "link-destination-whitespace",
547 ctor: MD062LinkDestinationWhitespace::from_config,
548 opt_in: false,
549 },
550 RuleEntry {
551 name: "MD063",
552 primary_alias: "heading-capitalization",
553 ctor: MD063HeadingCapitalization::from_config,
554 opt_in: true,
555 },
556 RuleEntry {
557 name: "MD064",
558 primary_alias: "no-multiple-consecutive-spaces",
559 ctor: MD064NoMultipleConsecutiveSpaces::from_config,
560 opt_in: false,
561 },
562 RuleEntry {
563 name: "MD065",
564 primary_alias: "blanks-around-horizontal-rules",
565 ctor: MD065BlanksAroundHorizontalRules::from_config,
566 opt_in: false,
567 },
568 RuleEntry {
569 name: "MD066",
570 primary_alias: "footnote-validation",
571 ctor: MD066FootnoteValidation::from_config,
572 opt_in: false,
573 },
574 RuleEntry {
575 name: "MD067",
576 primary_alias: "footnote-definition-order",
577 ctor: MD067FootnoteDefinitionOrder::from_config,
578 opt_in: false,
579 },
580 RuleEntry {
581 name: "MD068",
582 primary_alias: "empty-footnote-definition",
583 ctor: MD068EmptyFootnoteDefinition::from_config,
584 opt_in: false,
585 },
586 RuleEntry {
587 name: "MD069",
588 primary_alias: "no-duplicate-list-markers",
589 ctor: MD069NoDuplicateListMarkers::from_config,
590 opt_in: false,
591 },
592 RuleEntry {
593 name: "MD070",
594 primary_alias: "nested-code-fence",
595 ctor: MD070NestedCodeFence::from_config,
596 opt_in: true,
597 },
598 RuleEntry {
599 name: "MD071",
600 primary_alias: "blank-line-after-frontmatter",
601 ctor: MD071BlankLineAfterFrontmatter::from_config,
602 opt_in: false,
603 },
604 RuleEntry {
605 name: "MD072",
606 primary_alias: "frontmatter-key-sort",
607 ctor: MD072FrontmatterKeySort::from_config,
608 opt_in: true,
609 },
610 RuleEntry {
611 name: "MD073",
612 primary_alias: "toc-validation",
613 ctor: MD073TocValidation::from_config,
614 opt_in: true,
615 },
616 RuleEntry {
617 name: "MD074",
618 primary_alias: "mkdocs-nav",
619 ctor: MD074MkDocsNav::from_config,
620 opt_in: true,
621 },
622 RuleEntry {
623 name: "MD075",
624 primary_alias: "orphaned-table-rows",
625 ctor: MD075OrphanedTableRows::from_config,
626 opt_in: false,
627 },
628 RuleEntry {
629 name: "MD076",
630 primary_alias: "list-item-spacing",
631 ctor: MD076ListItemSpacing::from_config,
632 opt_in: false,
633 },
634 RuleEntry {
635 name: "MD077",
636 primary_alias: "list-continuation-indent",
637 ctor: MD077ListContinuationIndent::from_config,
638 opt_in: false,
639 },
640 RuleEntry {
641 name: "MD078",
642 primary_alias: "missing-chunk-labels",
643 ctor: MD078MissingChunkLabels::from_config,
644 opt_in: false,
645 },
646 RuleEntry {
647 name: "MD079",
648 primary_alias: "chunk-label-spaces",
649 ctor: MD079ChunkLabelSpaces::from_config,
650 opt_in: false,
651 },
652 RuleEntry {
653 name: "MD080",
654 primary_alias: "heading-anchor-collision",
655 ctor: MD080HeadingAnchorCollision::from_config,
656 opt_in: true,
657 },
658 RuleEntry {
659 name: "MD081",
660 primary_alias: "no-excessive-emphasis",
661 ctor: MD081NoExcessiveEmphasis::from_config,
662 opt_in: false,
663 },
664 RuleEntry {
665 name: "MD082",
666 primary_alias: "no-empty-sections",
667 ctor: MD082NoEmptySections::from_config,
668 opt_in: true,
669 },
670 RuleEntry {
671 name: "MD083",
672 primary_alias: "mojibake",
673 ctor: MD083DetectMojibake::from_config,
674 opt_in: true,
675 },
676 RuleEntry {
677 name: "MD084",
678 primary_alias: "invisible-characters",
679 ctor: MD084InvisibleCharacters::from_config,
680 opt_in: true,
681 },
682 RuleEntry {
683 name: "MD085",
684 primary_alias: "paragraph-continuation-indent",
685 ctor: MD085ParagraphContinuationIndent::from_config,
686 opt_in: true,
687 },
688 RuleEntry {
689 name: "MD086",
690 primary_alias: "no-unclosed-comments",
691 ctor: MD086NoUnclosedComments::from_config,
692 opt_in: false,
693 },
694 RuleEntry {
695 name: "MD087",
696 primary_alias: "unused-disable-comment",
697 ctor: MD087UnusedDisableComment::from_config,
698 opt_in: true,
699 },
700 RuleEntry {
701 name: "MD088",
702 primary_alias: "quotes-dashes",
703 ctor: crate::rules::md088_quotes_dashes::MD088QuotesDashes::from_config,
704 opt_in: true,
705 },
706 RuleEntry {
707 name: "MD089",
708 primary_alias: "cjk-spacing",
709 ctor: crate::rules::md089_cjk_spacing::MD089CjkSpacing::from_config,
710 opt_in: true,
711 },
712 RuleEntry {
713 name: "MD090",
714 primary_alias: "no-hr-before-heading",
715 ctor: crate::rules::md090_no_hr_before_heading::MD090NoHrBeforeHeading::from_config,
716 opt_in: true,
717 },
718 RuleEntry {
719 name: "MD091",
720 primary_alias: "no-markdown-in-html",
721 ctor: MD091NoMarkdownInHtml::from_config,
722 opt_in: true,
723 },
724];
725
726pub fn all_rules(config: &crate::config::Config) -> Vec<Box<dyn Rule>> {
728 RULES.iter().map(|entry| (entry.ctor)(config)).collect()
729}
730
731pub fn opt_in_rules() -> HashSet<&'static str> {
733 RULES
734 .iter()
735 .filter(|entry| entry.opt_in)
736 .map(|entry| entry.name)
737 .collect()
738}
739
740pub(crate) fn primary_alias(name: &str) -> Option<&'static str> {
742 RULES
743 .binary_search_by_key(&name, |entry| entry.name)
744 .ok()
745 .map(|index| RULES[index].primary_alias)
746}
747
748pub(crate) fn rule_identity(index: usize) -> Option<(&'static str, &'static str)> {
749 RULES.get(index).map(|entry| (entry.name, entry.primary_alias))
750}
751
752pub fn create_rule_by_name(name: &str, config: &crate::config::Config) -> Option<Box<dyn Rule>> {
759 RULES
760 .iter()
761 .find(|entry| entry.name == name)
762 .map(|entry| (entry.ctor)(config))
763}
764
765use crate::config::GlobalConfig;
768use std::collections::HashSet;
769
770fn contains_all_keyword(list: &[String]) -> bool {
772 list.iter().any(|s| s.eq_ignore_ascii_case("all"))
773}
774
775fn canonical_rule_set(list: &[String]) -> HashSet<String> {
782 list.iter()
783 .map(|s| {
784 if s.eq_ignore_ascii_case("all") {
785 "all".to_string()
786 } else {
787 crate::config::resolve_rule_name(s)
788 }
789 })
790 .collect()
791}
792
793pub fn filter_rules(rules: &[Box<dyn Rule>], global_config: &GlobalConfig) -> Vec<Box<dyn Rule>> {
804 let mut enabled_rules: Vec<Box<dyn Rule>> = Vec::new();
805 let disabled_rules: HashSet<String> = canonical_rule_set(&global_config.disable);
806 let opt_in_set = opt_in_rules();
807 let extend_enable_set: HashSet<String> = canonical_rule_set(&global_config.extend_enable);
808 let extend_disable_set: HashSet<String> = canonical_rule_set(&global_config.extend_disable);
809
810 let extend_enable_all = contains_all_keyword(&global_config.extend_enable);
811 let extend_disable_all = contains_all_keyword(&global_config.extend_disable);
812
813 let is_disabled = |name: &str| -> bool {
815 disabled_rules.contains(name) || extend_disable_all || extend_disable_set.contains(name)
816 };
817
818 if disabled_rules.contains("all") {
824 let enable_all = contains_all_keyword(&global_config.enable);
825 let enabled_set: HashSet<String> = canonical_rule_set(&global_config.enable);
826 for rule in rules {
827 let name = rule.name();
828 let enabled = enable_all || enabled_set.contains(name);
829 if enabled && !extend_disable_all && !extend_disable_set.contains(name) {
830 enabled_rules.push(dyn_clone::clone_box(&**rule));
831 }
832 }
833 return enabled_rules;
834 }
835
836 if !global_config.enable.is_empty() || global_config.enable_is_explicit {
838 if contains_all_keyword(&global_config.enable) || extend_enable_all {
839 for rule in rules {
841 if !is_disabled(rule.name()) {
842 enabled_rules.push(dyn_clone::clone_box(&**rule));
843 }
844 }
845 } else {
846 let mut enabled_set: HashSet<String> = canonical_rule_set(&global_config.enable);
848 for name in &extend_enable_set {
849 enabled_set.insert(name.clone());
850 }
851 for rule in rules {
852 if enabled_set.contains(rule.name()) && !is_disabled(rule.name()) {
853 enabled_rules.push(dyn_clone::clone_box(&**rule));
854 }
855 }
856 }
857 } else if extend_enable_all {
858 for rule in rules {
860 if !is_disabled(rule.name()) {
861 enabled_rules.push(dyn_clone::clone_box(&**rule));
862 }
863 }
864 } else {
865 for rule in rules {
867 let is_opt_in = opt_in_set.contains(rule.name());
868 let explicitly_extended = extend_enable_set.contains(rule.name());
869 if (!is_opt_in || explicitly_extended) && !is_disabled(rule.name()) {
870 enabled_rules.push(dyn_clone::clone_box(&**rule));
871 }
872 }
873 }
874
875 enabled_rules
876}
877
878pub fn filter_rules_for_file(
887 rules: &[Box<dyn Rule>],
888 config: &crate::config::Config,
889 path: &std::path::Path,
890) -> Vec<Box<dyn Rule>> {
891 let ignored = config.get_ignored_rules_for_file(path);
892 if ignored.is_empty() {
893 return rules.to_vec();
894 }
895 rules
896 .iter()
897 .filter(|rule| !ignored.contains(rule.name()))
898 .map(|r| dyn_clone::clone_box(&**r))
899 .collect()
900}
901
902#[cfg(test)]
903mod filter_rules_alias_tests {
904 use super::*;
905 use crate::config::Config;
906
907 #[test]
912 fn alias_in_disable_filters_canonical_rule() {
913 let config = Config::default();
914 let rules = all_rules(&config);
915 let global = GlobalConfig {
916 disable: vec!["no-inline-html".to_string()],
917 ..Default::default()
918 };
919
920 let filtered = filter_rules(&rules, &global);
921 assert!(
922 !filtered.iter().any(|r| r.name() == "MD033"),
923 "filter_rules must drop MD033 when its alias `no-inline-html` is in disable, \
924 even on a hand-built GlobalConfig. Got: {:?}",
925 filtered.iter().map(|r| r.name()).collect::<Vec<_>>(),
926 );
927 }
928
929 #[test]
931 fn alias_in_extend_disable_filters_canonical_rule() {
932 let config = Config::default();
933 let rules = all_rules(&config);
934 let global = GlobalConfig {
935 extend_disable: vec!["line-length".to_string()],
936 ..Default::default()
937 };
938
939 let filtered = filter_rules(&rules, &global);
940 assert!(
941 !filtered.iter().any(|r| r.name() == "MD013"),
942 "filter_rules must drop MD013 when alias `line-length` is in extend_disable. Got: {:?}",
943 filtered.iter().map(|r| r.name()).collect::<Vec<_>>(),
944 );
945 }
946
947 #[test]
949 fn alias_in_enable_selects_canonical_rule() {
950 let config = Config::default();
951 let rules = all_rules(&config);
952 let global = GlobalConfig {
953 enable: vec!["no-inline-html".to_string()],
954 ..Default::default()
955 };
956
957 let filtered = filter_rules(&rules, &global);
958 let names: Vec<&str> = filtered.iter().map(|r| r.name()).collect();
959 assert_eq!(
960 names,
961 vec!["MD033"],
962 "filter_rules must select only MD033 when alias `no-inline-html` is the sole enable. \
963 Got: {names:?}",
964 );
965 }
966
967 #[test]
970 fn alias_and_canonical_produce_identical_filter_result() {
971 let config = Config::default();
972 let rules = all_rules(&config);
973
974 let alias_global = GlobalConfig {
975 disable: vec!["no-inline-html".to_string(), "line-length".to_string()],
976 ..Default::default()
977 };
978 let canonical_global = GlobalConfig {
979 disable: vec!["MD033".to_string(), "MD013".to_string()],
980 ..Default::default()
981 };
982
983 let alias_names: Vec<&str> = filter_rules(&rules, &alias_global).iter().map(|r| r.name()).collect();
984 let canonical_names: Vec<&str> = filter_rules(&rules, &canonical_global)
985 .iter()
986 .map(|r| r.name())
987 .collect();
988 assert_eq!(alias_names, canonical_names);
989 }
990}