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