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