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