1#![warn(unreachable_pub)]
2#![warn(clippy::pedantic)]
3#![allow(clippy::doc_markdown)]
7#![allow(clippy::must_use_candidate)]
8#![allow(clippy::missing_errors_doc)]
9#![allow(clippy::missing_panics_doc)]
10#![allow(clippy::too_many_lines)]
11#![allow(clippy::if_not_else)]
12#![allow(clippy::similar_names)]
13#![allow(clippy::wildcard_imports)]
14#![allow(clippy::case_sensitive_file_extension_comparisons)]
15#![allow(clippy::doc_link_with_quotes)]
16#![allow(clippy::needless_raw_string_hashes)]
17#![allow(clippy::trivially_copy_pass_by_ref)]
18#![allow(clippy::struct_excessive_bools)]
19#![allow(clippy::fn_params_excessive_bools)]
20#![allow(clippy::elidable_lifetime_names)]
21#![allow(clippy::return_self_not_must_use)]
22#![allow(clippy::redundant_else)]
23#![allow(clippy::single_match_else)]
24#![allow(clippy::needless_continue)]
25#![allow(clippy::semicolon_if_nothing_returned)]
26#![allow(clippy::ignored_unit_patterns)]
27#![allow(clippy::unreadable_literal)]
28#![allow(clippy::implicit_hasher)]
29#![allow(clippy::ref_option)]
30#![allow(clippy::struct_field_names)]
31#![allow(clippy::unused_self)]
32#![allow(clippy::unnested_or_patterns)]
33#![allow(clippy::cast_precision_loss)]
34#![allow(clippy::cast_sign_loss)]
35#![allow(clippy::cast_possible_wrap)]
36#![allow(clippy::cast_possible_truncation)]
37#![allow(clippy::cast_lossless)]
38#![allow(clippy::items_after_statements)]
39#![allow(clippy::match_same_arms)]
40#![allow(clippy::format_push_string)]
41#![allow(clippy::no_effect_underscore_binding)]
44#![allow(clippy::default_trait_access)]
46#![allow(clippy::manual_string_new)]
49
50pub mod code_block_tools;
51pub mod config;
52pub mod discovery;
53pub mod doc_comment_lint;
54pub mod embedded_lint;
55pub mod exit_codes;
56pub mod filtered_lines;
57pub mod fix_coordinator;
58pub mod inline_config;
59pub mod linguist_data;
60pub mod lint_context;
61pub mod markdownlint_config;
62pub mod profiling;
63pub mod rule;
64#[cfg(feature = "colored")]
65pub mod vscode;
66pub mod workspace_index;
67#[macro_use]
68pub mod rule_config;
69#[macro_use]
70pub mod rule_config_serde;
71pub mod rules;
72pub mod types;
73pub mod utils;
74
75#[cfg(feature = "native")]
77pub mod lsp;
78#[cfg(feature = "colored")]
79pub mod output;
80#[cfg(feature = "native")]
81pub mod performance;
82
83#[cfg(feature = "wasm")]
85pub mod wasm;
86
87pub use rules::heading_utils::HeadingStyle;
88pub use rules::*;
89
90pub use crate::lint_context::{LineInfo, LintContext, ListItemInfo};
91use crate::rule::{LintResult, Rule, RuleCategory};
92use crate::utils::calculate_indentation_width_default;
93#[cfg(not(target_arch = "wasm32"))]
94use std::time::Instant;
95
96#[derive(Debug, Default)]
98struct ContentCharacteristics {
99 has_headings: bool, has_lists: bool, has_links: bool, has_code: bool, has_emphasis: bool, has_html: bool, has_tables: bool, has_blockquotes: bool, has_images: bool, }
109
110fn has_potential_indented_code_indent(line: &str) -> bool {
113 calculate_indentation_width_default(line) >= 4
114}
115
116impl ContentCharacteristics {
117 fn analyze(content: &str) -> Self {
118 let mut chars = Self { ..Default::default() };
119
120 let mut has_atx_heading = false;
122 let mut has_setext_heading = false;
123
124 for line in content.lines() {
125 let trimmed = line.trim();
126
127 if !has_atx_heading
134 && (trimmed.starts_with('#') || trimmed.trim_start_matches(['>', ' ', '\t']).starts_with('#'))
135 {
136 has_atx_heading = true;
137 }
138 if !has_setext_heading && (trimmed.chars().all(|c| c == '=' || c == '-') && trimmed.len() > 1) {
139 has_setext_heading = true;
140 }
141
142 if !chars.has_lists
145 && (line.contains("* ")
146 || line.contains("- ")
147 || line.contains("+ ")
148 || trimmed.starts_with("* ")
149 || trimmed.starts_with("- ")
150 || trimmed.starts_with("+ ")
151 || trimmed.starts_with('*')
152 || trimmed.starts_with('-')
153 || trimmed.starts_with('+'))
154 {
155 chars.has_lists = true;
156 }
157 if !chars.has_lists
159 && ((line.chars().next().is_some_and(|c| c.is_ascii_digit())
160 && (line.contains(". ") || line.contains('.')))
161 || (trimmed.starts_with('>')
162 && trimmed.chars().any(|c| c.is_ascii_digit())
163 && (trimmed.contains(". ") || trimmed.contains('.'))))
164 {
165 chars.has_lists = true;
166 }
167 if !chars.has_links
168 && (line.contains('[')
169 || line.contains("http://")
170 || line.contains("https://")
171 || line.contains("ftp://")
172 || line.contains("www."))
173 {
174 chars.has_links = true;
175 }
176 if !chars.has_images && line.contains("![") {
177 chars.has_images = true;
178 }
179 if !chars.has_code
180 && (line.contains('`') || line.contains("~~~") || has_potential_indented_code_indent(line))
181 {
182 chars.has_code = true;
183 }
184 if !chars.has_emphasis && (line.contains('*') || line.contains('_')) {
185 chars.has_emphasis = true;
186 }
187 if !chars.has_html && line.contains('<') {
188 chars.has_html = true;
189 }
190 if !chars.has_tables && line.contains('|') {
191 chars.has_tables = true;
192 }
193 if !chars.has_blockquotes && line.starts_with('>') {
194 chars.has_blockquotes = true;
195 }
196 }
197
198 chars.has_headings = has_atx_heading || has_setext_heading;
199 chars
200 }
201
202 fn should_skip_rule(&self, rule: &dyn Rule) -> bool {
204 match rule.category() {
205 RuleCategory::Heading => !self.has_headings,
206 RuleCategory::List => !self.has_lists,
207 RuleCategory::Link => !self.has_links && !self.has_images,
208 RuleCategory::Image => !self.has_images,
209 RuleCategory::CodeBlock => !self.has_code,
210 RuleCategory::Html => !self.has_html,
211 RuleCategory::Emphasis => !self.has_emphasis,
212 RuleCategory::Blockquote => !self.has_blockquotes,
213 RuleCategory::Table => !self.has_tables,
214 RuleCategory::Whitespace | RuleCategory::FrontMatter | RuleCategory::Other => false,
216 }
217 }
218}
219
220#[cfg(feature = "native")]
225fn compute_content_hash(content: &str) -> String {
226 #[cfg(feature = "profiling")]
227 let start = std::time::Instant::now();
228 let hash = blake3::hash(content.as_bytes()).to_hex().to_string();
229 #[cfg(feature = "profiling")]
230 profiling::record_duration("index: hash content", start.elapsed());
231 hash
232}
233
234#[cfg(not(feature = "native"))]
236fn compute_content_hash(content: &str) -> String {
237 use std::hash::{DefaultHasher, Hash, Hasher};
238 let mut hasher = DefaultHasher::new();
239 content.hash(&mut hasher);
240 format!("{:016x}", hasher.finish())
241}
242
243pub fn lint(
247 content: &str,
248 rules: &[Box<dyn Rule>],
249 verbose: bool,
250 flavor: crate::config::MarkdownFlavor,
251 source_file: Option<std::path::PathBuf>,
252 config: Option<&crate::config::Config>,
253) -> LintResult {
254 let (result, _file_index) = lint_and_index(content, rules, verbose, flavor, source_file, config);
255 result
256}
257
258pub fn build_file_index_only(
266 content: &str,
267 rules: &[Box<dyn Rule>],
268 flavor: crate::config::MarkdownFlavor,
269 source_file: Option<std::path::PathBuf>,
270) -> crate::workspace_index::FileIndex {
271 let content_hash = compute_content_hash(content);
273 let mut file_index = crate::workspace_index::FileIndex::with_hash(content_hash);
274
275 if content.is_empty() {
277 return file_index;
278 }
279
280 let lint_ctx = time_function!(
282 "index: parse lint context",
283 crate::lint_context::LintContext::new(content, flavor, source_file)
284 );
285
286 let (file_disabled, persistent_transitions, line_disabled) = lint_ctx.inline_config().export_for_file_index();
290 file_index.file_disabled_rules = file_disabled;
291 file_index.persistent_transitions = persistent_transitions;
292 file_index.line_disabled_rules = line_disabled;
293
294 time_section!("index: contribute cross-file data", {
296 for rule in rules {
297 if rule.cross_file_scope() == crate::rule::CrossFileScope::Workspace {
298 rule.contribute_to_index(&lint_ctx, &mut file_index);
299 }
300 }
301 });
302
303 file_index
304}
305
306fn retain_reportable_warnings(
314 lint_ctx: &crate::lint_context::LintContext,
315 config: Option<&crate::config::Config>,
316 rule_name: &str,
317 rule_warnings: Vec<crate::rule::LintWarning>,
318 mut suppressed: Option<&mut Vec<crate::rule::SuppressedWarning>>,
319) -> Vec<crate::rule::LintWarning> {
320 let inline_config = lint_ctx.inline_config();
321 let mut kept = Vec::with_capacity(rule_warnings.len());
322
323 for mut warning in rule_warnings {
324 if lint_ctx
325 .line_info(warning.line)
326 .is_some_and(|info| info.in_kramdown_extension_block)
327 {
328 continue;
329 }
330
331 let rule_name_to_check = warning.rule_name.as_deref().unwrap_or(rule_name);
333
334 let base_rule_name = if let Some(dash_pos) = rule_name_to_check.find('-') {
336 &rule_name_to_check[..dash_pos]
337 } else {
338 rule_name_to_check
339 };
340
341 let end = if warning.end_line >= warning.line {
347 warning.end_line
348 } else {
349 warning.line
350 };
351 let disabled_at = (warning.line..=end).find_map(|line| {
352 inline_config
353 .disabling_layer(base_rule_name, line)
354 .map(|layer| (line, layer))
355 });
356 if let Some((line, layer)) = disabled_at {
357 if let Some(record) = suppressed.as_deref_mut() {
358 record.push(crate::rule::SuppressedWarning {
359 rule_name: base_rule_name.to_string(),
360 line,
361 layer,
362 });
363 }
364 continue;
365 }
366
367 if let Some(cfg) = config
369 && let Some(override_severity) = cfg.get_rule_severity(rule_name_to_check)
370 {
371 warning.severity = override_severity;
372 }
373
374 kept.push(warning);
375 }
376
377 kept
378}
379
380#[cfg_attr(test, allow(unused_variables))]
388pub fn lint_and_index(
389 content: &str,
390 rules: &[Box<dyn Rule>],
391 verbose: bool,
392 flavor: crate::config::MarkdownFlavor,
393 source_file: Option<std::path::PathBuf>,
394 config: Option<&crate::config::Config>,
395) -> (LintResult, crate::workspace_index::FileIndex) {
396 let mut warnings = Vec::new();
397 let content_hash = compute_content_hash(content);
399 let mut file_index = crate::workspace_index::FileIndex::with_hash(content_hash);
400
401 if content.is_empty() {
403 return (Ok(warnings), file_index);
404 }
405
406 let ignored_for_file = match (config, source_file.as_deref()) {
413 (Some(cfg), Some(path)) => cfg.get_ignored_rules_for_file(path),
414 _ => std::collections::HashSet::new(),
415 };
416
417 let lint_ctx = time_function!(
419 "lint: parse lint context",
420 crate::lint_context::LintContext::new(content, flavor, source_file)
421 );
422 let inline_config = lint_ctx.inline_config();
423
424 let (file_disabled, persistent_transitions, line_disabled) = inline_config.export_for_file_index();
426 file_index.file_disabled_rules = file_disabled;
427 file_index.persistent_transitions = persistent_transitions;
428 file_index.line_disabled_rules = line_disabled;
429
430 let characteristics = time_function!(
432 "lint: analyze content characteristics",
433 ContentCharacteristics::analyze(content)
434 );
435
436 let applicable_rules: Vec<_> = rules
438 .iter()
439 .filter(|rule| !ignored_for_file.contains(rule.name()))
440 .filter(|rule| !(rule.skippable_by_category() && characteristics.should_skip_rule(rule.as_ref())))
441 .collect();
442
443 #[cfg(not(test))]
445 let total_rules = rules.len();
446 #[cfg(not(test))]
447 let applicable_count = applicable_rules.len();
448
449 #[cfg(not(target_arch = "wasm32"))]
450 let profile_rules = std::env::var("RUMDL_PROFILE_RULES").is_ok();
451
452 let inline_overrides = inline_config.get_all_rule_configs();
455 let merged_config = if !inline_overrides.is_empty() {
456 config.map(|c| c.merge_with_inline_config(inline_config))
457 } else {
458 None
459 };
460 let effective_config = merged_config.as_ref().or(config);
461
462 let mut recreated_rules: std::collections::HashMap<String, Box<dyn crate::rule::Rule>> =
464 std::collections::HashMap::new();
465
466 if let Some(cfg) = effective_config {
468 for rule_name in inline_overrides.keys() {
469 if let Some(recreated) = crate::rules::create_rule_by_name(rule_name, cfg) {
470 recreated_rules.insert(rule_name.clone(), recreated);
471 }
472 }
473 }
474
475 let suppression_observers: Vec<_> = applicable_rules
479 .iter()
480 .filter(|rule| rule.observes_suppressions() && !rule.should_skip(&lint_ctx))
481 .collect();
482 let mut suppressed = Vec::new();
483
484 {
485 let _timer = profiling::ScopedTimer::new("lint: run single-file rules");
486 for rule in &applicable_rules {
487 #[cfg(not(target_arch = "wasm32"))]
488 let rule_start = Instant::now();
489
490 if rule.should_skip(&lint_ctx) {
492 continue;
493 }
494
495 let effective_rule: &dyn crate::rule::Rule = recreated_rules
497 .get(rule.name())
498 .map_or(rule.as_ref(), std::convert::AsRef::as_ref);
499
500 let result = effective_rule.check(&lint_ctx);
502
503 match result {
504 Ok(rule_warnings) => {
505 let record = if suppression_observers.is_empty() {
506 None
507 } else {
508 Some(&mut suppressed)
509 };
510 let filtered_warnings =
511 retain_reportable_warnings(&lint_ctx, config, rule.name(), rule_warnings, record);
512 warnings.extend(filtered_warnings);
513 }
514 Err(e) => {
515 log::error!("Error checking rule {}: {}", rule.name(), e);
516 return (Err(e), file_index);
517 }
518 }
519
520 #[cfg(not(target_arch = "wasm32"))]
521 {
522 let rule_duration = rule_start.elapsed();
523 if profile_rules {
524 eprintln!("[RULE] {:6} {:?}", rule.name(), rule_duration);
525 }
526
527 #[cfg(not(test))]
528 if verbose && rule_duration.as_millis() > 500 {
529 log::debug!("Rule {} took {:?}", rule.name(), rule_duration);
530 }
531 }
532 }
533 }
534
535 if !suppression_observers.is_empty() {
538 let _timer = profiling::ScopedTimer::new("lint: run suppression rules");
539
540 let report = crate::rule::SuppressionReport {
545 suppressed,
546 judged_rules: rules
547 .iter()
548 .filter(|rule| rule.cross_file_scope() != crate::rule::CrossFileScope::Workspace)
549 .filter(|rule| !ignored_for_file.contains(rule.name()))
550 .map(|rule| rule.name().to_string())
551 .collect(),
552 };
553
554 for rule in &suppression_observers {
555 match rule.check_suppressions(&lint_ctx, &report) {
556 Ok(rule_warnings) => {
557 let filtered_warnings =
558 retain_reportable_warnings(&lint_ctx, config, rule.name(), rule_warnings, None);
559 warnings.extend(filtered_warnings);
560 }
561 Err(e) => {
562 log::error!("Error checking rule {}: {}", rule.name(), e);
563 return (Err(e), file_index);
564 }
565 }
566 }
567 }
568
569 time_section!("lint: contribute cross-file data", {
577 for rule in rules {
578 if rule.cross_file_scope() == crate::rule::CrossFileScope::Workspace {
579 rule.contribute_to_index(&lint_ctx, &mut file_index);
580 }
581 }
582 });
583
584 #[cfg(not(test))]
585 if verbose {
586 let skipped_rules = total_rules - applicable_count;
587 if skipped_rules > 0 {
588 log::debug!("Skipped {skipped_rules} of {total_rules} rules based on content analysis");
589 }
590 }
591
592 (Ok(warnings), file_index)
593}
594
595pub fn run_cross_file_checks(
608 file_path: &std::path::Path,
609 file_index: &crate::workspace_index::FileIndex,
610 rules: &[Box<dyn Rule>],
611 workspace_index: &crate::workspace_index::WorkspaceIndex,
612 config: Option<&crate::config::Config>,
613) -> LintResult {
614 use crate::rule::CrossFileScope;
615
616 let mut warnings = Vec::new();
617
618 let ignored_rules_for_file = config.map(|cfg| cfg.get_ignored_rules_for_file(file_path));
624
625 for rule in rules {
627 if rule.cross_file_scope() != CrossFileScope::Workspace {
628 continue;
629 }
630
631 if ignored_rules_for_file
632 .as_ref()
633 .is_some_and(|ignored| ignored.contains(rule.name()))
634 {
635 continue;
636 }
637
638 match time_function!(
639 "workspace: cross-file rule check",
640 rule.cross_file_check(file_path, file_index, workspace_index)
641 ) {
642 Ok(rule_warnings) => {
643 let filtered: Vec<_> = rule_warnings
645 .into_iter()
646 .filter(|w| !file_index.is_rule_disabled_at_line(rule.name(), w.line))
647 .map(|mut warning| {
648 if let Some(cfg) = config
650 && let Some(override_severity) = cfg.get_rule_severity(rule.name())
651 {
652 warning.severity = override_severity;
653 }
654 warning
655 })
656 .collect();
657 warnings.extend(filtered);
658 }
659 Err(e) => {
660 log::error!("Error in cross-file check for rule {}: {}", rule.name(), e);
661 return Err(e);
662 }
663 }
664 }
665
666 Ok(warnings)
667}
668
669pub fn get_profiling_report() -> String {
671 profiling::get_report()
672}
673
674pub fn reset_profiling() {
676 profiling::reset()
677}
678
679pub fn get_regex_cache_stats() -> std::collections::HashMap<String, u64> {
681 crate::utils::regex_cache::get_cache_stats()
682}
683
684#[cfg(test)]
685mod tests {
686 use super::*;
687 use crate::rule::Rule;
688 use crate::rules::{MD001HeadingIncrement, MD009TrailingSpaces};
689
690 #[test]
691 fn test_content_characteristics_analyze() {
692 let chars = ContentCharacteristics::analyze("");
694 assert!(!chars.has_headings);
695 assert!(!chars.has_lists);
696 assert!(!chars.has_links);
697 assert!(!chars.has_code);
698 assert!(!chars.has_emphasis);
699 assert!(!chars.has_html);
700 assert!(!chars.has_tables);
701 assert!(!chars.has_blockquotes);
702 assert!(!chars.has_images);
703
704 let chars = ContentCharacteristics::analyze("# Heading");
706 assert!(chars.has_headings);
707
708 let chars = ContentCharacteristics::analyze("Heading\n=======");
710 assert!(chars.has_headings);
711
712 let chars = ContentCharacteristics::analyze("> ## Alpha\n>\n> ## Alpha");
715 assert!(chars.has_headings, "blockquoted ATX heading must set has_headings");
716 let chars = ContentCharacteristics::analyze(">> # Nested");
717 assert!(
718 chars.has_headings,
719 "nested-blockquote ATX heading must set has_headings"
720 );
721 let chars = ContentCharacteristics::analyze(">\t## Tabbed");
724 assert!(
725 chars.has_headings,
726 "tab-separated blockquote ATX heading must set has_headings"
727 );
728
729 let chars = ContentCharacteristics::analyze("* Item\n- Item 2\n+ Item 3");
731 assert!(chars.has_lists);
732
733 let chars = ContentCharacteristics::analyze("1. First\n2. Second");
735 assert!(chars.has_lists);
736
737 let chars = ContentCharacteristics::analyze("[link](url)");
739 assert!(chars.has_links);
740
741 let chars = ContentCharacteristics::analyze("Visit https://example.com");
743 assert!(chars.has_links);
744
745 let chars = ContentCharacteristics::analyze("");
747 assert!(chars.has_images);
748
749 let chars = ContentCharacteristics::analyze("`inline code`");
751 assert!(chars.has_code);
752
753 let chars = ContentCharacteristics::analyze("~~~\ncode block\n~~~");
754 assert!(chars.has_code);
755
756 let chars = ContentCharacteristics::analyze("Text\n\n indented code\n\nMore text");
758 assert!(chars.has_code);
759
760 let chars = ContentCharacteristics::analyze("Text\n\n\ttab indented code\n\nMore text");
762 assert!(chars.has_code);
763
764 let chars = ContentCharacteristics::analyze("Text\n\n \tmixed indent code\n\nMore text");
766 assert!(chars.has_code);
767
768 let chars = ContentCharacteristics::analyze("Text\n\n \ttab after space\n\nMore text");
770 assert!(chars.has_code);
771
772 let chars = ContentCharacteristics::analyze("*emphasis* and _more_");
774 assert!(chars.has_emphasis);
775
776 let chars = ContentCharacteristics::analyze("<div>HTML content</div>");
778 assert!(chars.has_html);
779
780 let chars = ContentCharacteristics::analyze("| Header | Header |\n|--------|--------|");
782 assert!(chars.has_tables);
783
784 let chars = ContentCharacteristics::analyze("> Quote");
786 assert!(chars.has_blockquotes);
787
788 let content = "# Heading\n* List item\n[link](url)\n`code`\n*emphasis*\n<p>html</p>\n| table |\n> quote\n";
790 let chars = ContentCharacteristics::analyze(content);
791 assert!(chars.has_headings);
792 assert!(chars.has_lists);
793 assert!(chars.has_links);
794 assert!(chars.has_code);
795 assert!(chars.has_emphasis);
796 assert!(chars.has_html);
797 assert!(chars.has_tables);
798 assert!(chars.has_blockquotes);
799 assert!(chars.has_images);
800 }
801
802 #[test]
803 fn test_content_characteristics_should_skip_rule() {
804 let chars = ContentCharacteristics {
805 has_headings: true,
806 has_lists: false,
807 has_links: true,
808 has_code: false,
809 has_emphasis: true,
810 has_html: false,
811 has_tables: true,
812 has_blockquotes: false,
813 has_images: false,
814 };
815
816 let heading_rule = MD001HeadingIncrement::default();
818 assert!(!chars.should_skip_rule(&heading_rule));
819
820 let trailing_spaces_rule = MD009TrailingSpaces::new(2, false);
821 assert!(!chars.should_skip_rule(&trailing_spaces_rule)); let chars_no_headings = ContentCharacteristics {
825 has_headings: false,
826 ..Default::default()
827 };
828 assert!(chars_no_headings.should_skip_rule(&heading_rule));
829 }
830
831 #[test]
832 fn test_lint_empty_content() {
833 let rules: Vec<Box<dyn Rule>> = vec![Box::new(MD001HeadingIncrement::default())];
834
835 let result = lint("", &rules, false, crate::config::MarkdownFlavor::Standard, None, None);
836 assert!(result.is_ok());
837 assert!(result.unwrap().is_empty());
838 }
839
840 #[test]
841 fn test_lint_with_violations() {
842 let content = "## Level 2\n#### Level 4"; let rules: Vec<Box<dyn Rule>> = vec![Box::new(MD001HeadingIncrement::default())];
844
845 let result = lint(
846 content,
847 &rules,
848 false,
849 crate::config::MarkdownFlavor::Standard,
850 None,
851 None,
852 );
853 assert!(result.is_ok());
854 let warnings = result.unwrap();
855 assert!(!warnings.is_empty());
856 assert_eq!(warnings[0].rule_name.as_deref(), Some("MD001"));
858 }
859
860 #[test]
861 fn test_lint_with_inline_disable() {
862 let content = "<!-- rumdl-disable MD001 -->\n## Level 2\n#### Level 4";
863 let rules: Vec<Box<dyn Rule>> = vec![Box::new(MD001HeadingIncrement::default())];
864
865 let result = lint(
866 content,
867 &rules,
868 false,
869 crate::config::MarkdownFlavor::Standard,
870 None,
871 None,
872 );
873 assert!(result.is_ok());
874 let warnings = result.unwrap();
875 assert!(warnings.is_empty()); }
877
878 #[test]
879 fn test_lint_rule_filtering() {
880 let content = "# Heading\nJust text";
882 let rules: Vec<Box<dyn Rule>> = vec![
883 Box::new(MD001HeadingIncrement::default()),
884 ];
886
887 let result = lint(
888 content,
889 &rules,
890 false,
891 crate::config::MarkdownFlavor::Standard,
892 None,
893 None,
894 );
895 assert!(result.is_ok());
896 }
897
898 #[test]
899 fn test_get_profiling_report() {
900 let report = get_profiling_report();
902 assert!(!report.is_empty());
903 assert!(report.contains("Profiling"));
904 }
905
906 #[test]
907 fn test_reset_profiling() {
908 reset_profiling();
910
911 let report = get_profiling_report();
913 assert!(report.contains("disabled") || report.contains("no measurements"));
914 }
915
916 #[test]
917 fn test_get_regex_cache_stats() {
918 let stats = get_regex_cache_stats();
919 assert!(stats.is_empty() || !stats.is_empty());
921
922 for count in stats.values() {
924 assert!(*count > 0);
925 }
926 }
927
928 #[test]
929 fn test_content_characteristics_edge_cases() {
930 let chars = ContentCharacteristics::analyze("-"); assert!(!chars.has_headings);
933
934 let chars = ContentCharacteristics::analyze("--"); assert!(chars.has_headings);
936
937 let chars = ContentCharacteristics::analyze("*emphasis*"); assert!(chars.has_lists); let chars = ContentCharacteristics::analyze("1.Item"); assert!(chars.has_lists); let chars = ContentCharacteristics::analyze("text > not a quote");
947 assert!(!chars.has_blockquotes);
948 }
949}