1use crate::utils::fast_hash;
2use crate::utils::regex_cache::{escape_regex, get_cached_regex};
3
4use crate::rule::{Fix, LintError, LintResult, LintWarning, Rule, RuleCategory, Severity};
5use std::collections::{HashMap, HashSet};
6use std::sync::{Arc, Mutex};
7
8mod md044_config;
9pub use md044_config::MD044Config;
10
11type WarningPosition = (usize, usize, String); fn is_inline_config_comment(trimmed: &str) -> bool {
70 trimmed.starts_with("<!-- rumdl-")
71 || trimmed.starts_with("<!-- markdownlint-")
72 || trimmed.starts_with("<!-- vale off")
73 || trimmed.starts_with("<!-- vale on")
74 || (trimmed.starts_with("<!-- vale ") && trimmed.contains(" = "))
75 || trimmed.starts_with("<!-- vale style")
76 || trimmed.starts_with("<!-- lint disable ")
77 || trimmed.starts_with("<!-- lint enable ")
78 || trimmed.starts_with("<!-- lint ignore ")
79}
80
81#[derive(Clone)]
82pub struct MD044ProperNames {
83 config: MD044Config,
84 combined_pattern: Option<String>,
86 name_variants: Vec<String>,
88 content_cache: Arc<Mutex<HashMap<u64, Vec<WarningPosition>>>>,
90}
91
92impl MD044ProperNames {
93 pub fn new(names: Vec<String>, code_blocks: bool) -> Self {
94 let config = MD044Config {
95 names,
96 code_blocks,
97 html_elements: true, html_comments: true, };
100 let combined_pattern = Self::create_combined_pattern(&config);
101 let name_variants = Self::build_name_variants(&config);
102 Self {
103 config,
104 combined_pattern,
105 name_variants,
106 content_cache: Arc::new(Mutex::new(HashMap::new())),
107 }
108 }
109
110 fn ascii_normalize(s: &str) -> String {
112 s.replace(['é', 'è', 'ê', 'ë'], "e")
113 .replace(['à', 'á', 'â', 'ä', 'ã', 'å'], "a")
114 .replace(['ï', 'î', 'í', 'ì'], "i")
115 .replace(['ü', 'ú', 'ù', 'û'], "u")
116 .replace(['ö', 'ó', 'ò', 'ô', 'õ'], "o")
117 .replace('ñ', "n")
118 .replace('ç', "c")
119 }
120
121 pub fn from_config_struct(config: MD044Config) -> Self {
122 let combined_pattern = Self::create_combined_pattern(&config);
123 let name_variants = Self::build_name_variants(&config);
124 Self {
125 config,
126 combined_pattern,
127 name_variants,
128 content_cache: Arc::new(Mutex::new(HashMap::new())),
129 }
130 }
131
132 fn create_combined_pattern(config: &MD044Config) -> Option<String> {
134 if config.names.is_empty() {
135 return None;
136 }
137
138 let mut patterns: Vec<String> = config
140 .names
141 .iter()
142 .flat_map(|name| {
143 let mut variations = vec![];
144 let lower_name = name.to_lowercase();
145
146 variations.push(escape_regex(&lower_name));
148
149 let lower_name_no_dots = lower_name.replace('.', "");
151 if lower_name != lower_name_no_dots {
152 variations.push(escape_regex(&lower_name_no_dots));
153 }
154
155 let ascii_normalized = Self::ascii_normalize(&lower_name);
157
158 if ascii_normalized != lower_name {
159 variations.push(escape_regex(&ascii_normalized));
160
161 let ascii_no_dots = ascii_normalized.replace('.', "");
163 if ascii_normalized != ascii_no_dots {
164 variations.push(escape_regex(&ascii_no_dots));
165 }
166 }
167
168 variations
169 })
170 .collect();
171
172 patterns.sort_by_key(|b| std::cmp::Reverse(b.len()));
174
175 Some(format!(r"(?i)({})", patterns.join("|")))
178 }
179
180 fn build_name_variants(config: &MD044Config) -> Vec<String> {
181 let mut variants = HashSet::new();
182 for name in &config.names {
183 let lower_name = name.to_lowercase();
184 variants.insert(lower_name.clone());
185
186 let lower_no_dots = lower_name.replace('.', "");
187 if lower_name != lower_no_dots {
188 variants.insert(lower_no_dots);
189 }
190
191 let ascii_normalized = Self::ascii_normalize(&lower_name);
192 if ascii_normalized != lower_name {
193 variants.insert(ascii_normalized.clone());
194
195 let ascii_no_dots = ascii_normalized.replace('.', "");
196 if ascii_normalized != ascii_no_dots {
197 variants.insert(ascii_no_dots);
198 }
199 }
200 }
201
202 variants.into_iter().collect()
203 }
204
205 fn find_name_violations(
208 &self,
209 content: &str,
210 ctx: &crate::lint_context::LintContext,
211 content_lower: &str,
212 ) -> Vec<WarningPosition> {
213 if self.config.names.is_empty() || content.is_empty() || self.combined_pattern.is_none() {
215 return Vec::new();
216 }
217
218 let has_potential_matches = self.name_variants.iter().any(|name| content_lower.contains(name));
220
221 if !has_potential_matches {
222 return Vec::new();
223 }
224
225 let hash = fast_hash(content);
227 {
228 if let Ok(cache) = self.content_cache.lock()
230 && let Some(cached) = cache.get(&hash)
231 {
232 return cached.clone();
233 }
234 }
235
236 let mut violations = Vec::new();
237
238 let combined_regex = match &self.combined_pattern {
240 Some(pattern) => match get_cached_regex(pattern) {
241 Ok(regex) => regex,
242 Err(_) => return Vec::new(),
243 },
244 None => return Vec::new(),
245 };
246
247 for (line_idx, line_info) in ctx.lines.iter().enumerate() {
249 let line_num = line_idx + 1;
250 let line = line_info.content(ctx.content);
251
252 let trimmed = line.trim_start();
254 if trimmed.starts_with("```") || trimmed.starts_with("~~~") {
255 continue;
256 }
257
258 if !self.config.code_blocks && line_info.in_code_block {
260 continue;
261 }
262
263 if !self.config.html_elements && line_info.in_html_block {
265 continue;
266 }
267
268 if !self.config.html_comments && line_info.in_html_comment {
270 continue;
271 }
272
273 if line_info.in_jsx_expression || line_info.in_mdx_comment {
275 continue;
276 }
277
278 if line_info.in_obsidian_comment {
280 continue;
281 }
282
283 let fm_value_offset = if line_info.in_front_matter {
286 Self::frontmatter_value_offset(line)
287 } else {
288 0
289 };
290 if fm_value_offset == usize::MAX {
291 continue;
292 }
293
294 if is_inline_config_comment(trimmed) {
296 continue;
297 }
298
299 let line_lower = line.to_lowercase();
301 let has_line_matches = self.name_variants.iter().any(|name| line_lower.contains(name));
302
303 if !has_line_matches {
304 continue;
305 }
306
307 for cap in combined_regex.find_iter(line) {
309 let found_name = &line[cap.start()..cap.end()];
310
311 let start_pos = cap.start();
313 let end_pos = cap.end();
314
315 if start_pos < fm_value_offset {
317 continue;
318 }
319
320 let byte_pos = line_info.byte_offset + start_pos;
322 if ctx.is_in_html_tag(byte_pos) {
323 continue;
324 }
325
326 if !Self::is_at_word_boundary(line, start_pos, true) || !Self::is_at_word_boundary(line, end_pos, false)
327 {
328 continue; }
330
331 if !self.config.code_blocks {
333 if ctx.is_in_code_block_or_span(byte_pos) {
334 continue;
335 }
336 if (line_info.in_html_comment || line_info.in_html_block || line_info.in_front_matter)
340 && Self::is_in_backtick_code_in_line(line, start_pos)
341 {
342 continue;
343 }
344 }
345
346 if Self::is_in_link(ctx, byte_pos) {
348 continue;
349 }
350
351 if Self::is_in_angle_bracket_url(line, start_pos) {
355 continue;
356 }
357
358 if (line_info.in_html_comment || line_info.in_html_block || line_info.in_front_matter)
362 && Self::is_in_markdown_link_url(line, start_pos)
363 {
364 continue;
365 }
366
367 if Self::is_in_wikilink_url(ctx, byte_pos) {
372 continue;
373 }
374
375 if let Some(proper_name) = self.get_proper_name_for(found_name) {
377 if found_name != proper_name {
379 violations.push((line_num, cap.start() + 1, found_name.to_string()));
380 }
381 }
382 }
383 }
384
385 if let Ok(mut cache) = self.content_cache.lock() {
387 cache.insert(hash, violations.clone());
388 }
389 violations
390 }
391
392 fn is_in_link(ctx: &crate::lint_context::LintContext, byte_pos: usize) -> bool {
399 use pulldown_cmark::LinkType;
400
401 let link_idx = ctx.links.partition_point(|link| link.byte_offset <= byte_pos);
403 if link_idx > 0 {
404 let link = &ctx.links[link_idx - 1];
405 if byte_pos < link.byte_end {
406 let text_start = if matches!(link.link_type, LinkType::WikiLink { .. }) {
408 link.byte_offset + 2
409 } else {
410 link.byte_offset + 1
411 };
412 let text_end = text_start + link.text.len();
413
414 if byte_pos >= text_start && byte_pos < text_end {
418 let is_wikilink = matches!(link.link_type, LinkType::WikiLink { .. });
419 return Self::link_text_is_url(&link.text)
420 || (!is_wikilink && Self::link_text_matches_link_url(&link.text, &link.url));
421 }
422 return true;
424 }
425 }
426
427 let image_idx = ctx.images.partition_point(|img| img.byte_offset <= byte_pos);
429 if image_idx > 0 {
430 let image = &ctx.images[image_idx - 1];
431 if byte_pos < image.byte_end {
432 let alt_start = image.byte_offset + 2;
434 let alt_end = alt_start + image.alt_text.len();
435
436 if byte_pos >= alt_start && byte_pos < alt_end {
438 return false;
439 }
440 return true;
442 }
443 }
444
445 ctx.is_in_reference_def(byte_pos)
447 }
448
449 fn link_text_is_url(text: &str) -> bool {
451 let lower = text.trim().to_ascii_lowercase();
452 lower.starts_with("http://")
453 || lower.starts_with("https://")
454 || lower.starts_with("www.")
455 || lower.starts_with("//")
456 }
457
458 fn link_text_matches_link_url(text: &str, url: &str) -> bool {
470 let text = text.trim();
471 if !text.contains('.') {
473 return false;
474 }
475 let url_lower = url.to_ascii_lowercase();
476 let url_without_scheme = url_lower
477 .strip_prefix("https://")
478 .or_else(|| url_lower.strip_prefix("http://"))
479 .or_else(|| url_lower.strip_prefix("//"))
480 .unwrap_or(&url_lower);
481 let text_lower = text.to_ascii_lowercase();
482 if url_without_scheme == text_lower.as_str() {
484 return true;
485 }
486 url_without_scheme.len() > text_lower.len()
488 && url_without_scheme.starts_with(text_lower.as_str())
489 && matches!(
490 url_without_scheme.as_bytes().get(text_lower.len()),
491 Some(b'/') | Some(b'?') | Some(b'#')
492 )
493 }
494
495 fn is_in_angle_bracket_url(line: &str, pos: usize) -> bool {
501 let bytes = line.as_bytes();
502 let len = bytes.len();
503 let mut i = 0;
504 while i < len {
505 if bytes[i] == b'<' {
506 let after_open = i + 1;
507 if after_open < len && bytes[after_open].is_ascii_alphabetic() {
511 let mut s = after_open + 1;
512 let scheme_max = (after_open + 32).min(len);
513 while s < scheme_max
514 && (bytes[s].is_ascii_alphanumeric()
515 || bytes[s] == b'+'
516 || bytes[s] == b'-'
517 || bytes[s] == b'.')
518 {
519 s += 1;
520 }
521 if s < len && bytes[s] == b':' {
522 let mut j = s + 1;
524 let mut found_close = false;
525 while j < len {
526 match bytes[j] {
527 b'>' => {
528 found_close = true;
529 break;
530 }
531 b' ' | b'<' => break,
532 _ => j += 1,
533 }
534 }
535 if found_close && pos >= i && pos <= j {
536 return true;
537 }
538 if found_close {
539 i = j + 1;
540 continue;
541 }
542 }
543 }
544 }
545 i += 1;
546 }
547 false
548 }
549
550 fn is_in_wikilink_url(ctx: &crate::lint_context::LintContext, byte_pos: usize) -> bool {
563 use pulldown_cmark::LinkType;
564 let content = ctx.content.as_bytes();
565
566 let end = ctx.links.partition_point(|l| l.byte_offset <= byte_pos);
569
570 for link in &ctx.links[..end] {
571 if !matches!(link.link_type, LinkType::WikiLink { .. }) {
572 continue;
573 }
574 let wiki_end = link.byte_end;
575 if wiki_end >= byte_pos || wiki_end >= content.len() || content[wiki_end] != b'(' {
577 continue;
578 }
579 let mut depth: u32 = 1;
584 let mut k = wiki_end + 1;
585 let mut valid_destination = true;
586 while k < content.len() && depth > 0 {
587 match content[k] {
588 b'\\' => {
589 k += 1; }
591 b'(' => depth += 1,
592 b')' => depth -= 1,
593 b' ' | b'\t' | b'\n' | b'\r' => {
594 valid_destination = false;
595 break;
596 }
597 _ => {}
598 }
599 k += 1;
600 }
601 if valid_destination && depth == 0 && byte_pos > wiki_end && byte_pos < k {
604 return true;
605 }
606 }
607 false
608 }
609
610 fn is_in_markdown_link_url(line: &str, pos: usize) -> bool {
620 let bytes = line.as_bytes();
621 let len = bytes.len();
622 let mut i = 0;
623
624 while i < len {
625 if bytes[i] == b'[' && (i == 0 || bytes[i - 1] != b'\\' || (i >= 2 && bytes[i - 2] == b'\\')) {
627 let mut depth: u32 = 1;
629 let mut j = i + 1;
630 while j < len && depth > 0 {
631 match bytes[j] {
632 b'\\' => {
633 j += 1; }
635 b'[' => depth += 1,
636 b']' => depth -= 1,
637 _ => {}
638 }
639 j += 1;
640 }
641
642 if depth == 0 && j < len {
644 if bytes[j] == b'(' {
645 let url_start = j;
647 let mut paren_depth: u32 = 1;
648 let mut k = j + 1;
649 while k < len && paren_depth > 0 {
650 match bytes[k] {
651 b'\\' => {
652 k += 1; }
654 b'(' => paren_depth += 1,
655 b')' => paren_depth -= 1,
656 _ => {}
657 }
658 k += 1;
659 }
660
661 if paren_depth == 0 {
662 if pos > url_start && pos < k {
663 return true;
664 }
665 i = k;
666 continue;
667 }
668 } else if bytes[j] == b'[' {
669 let ref_start = j;
671 let mut ref_depth: u32 = 1;
672 let mut k = j + 1;
673 while k < len && ref_depth > 0 {
674 match bytes[k] {
675 b'\\' => {
676 k += 1;
677 }
678 b'[' => ref_depth += 1,
679 b']' => ref_depth -= 1,
680 _ => {}
681 }
682 k += 1;
683 }
684
685 if ref_depth == 0 {
686 if pos > ref_start && pos < k {
687 return true;
688 }
689 i = k;
690 continue;
691 }
692 }
693 }
694 }
695 i += 1;
696 }
697 false
698 }
699
700 fn is_in_backtick_code_in_line(line: &str, pos: usize) -> bool {
708 let bytes = line.as_bytes();
709 let len = bytes.len();
710 let mut i = 0;
711 while i < len {
712 if bytes[i] == b'`' {
713 let open_start = i;
715 while i < len && bytes[i] == b'`' {
716 i += 1;
717 }
718 let tick_len = i - open_start;
719
720 while i < len {
722 if bytes[i] == b'`' {
723 let close_start = i;
724 while i < len && bytes[i] == b'`' {
725 i += 1;
726 }
727 if i - close_start == tick_len {
728 let content_start = open_start + tick_len;
732 let content_end = close_start;
733 if pos >= content_start && pos < content_end {
734 return true;
735 }
736 break;
738 }
739 } else {
741 i += 1;
742 }
743 }
744 } else {
745 i += 1;
746 }
747 }
748 false
749 }
750
751 fn is_word_boundary_char(c: char) -> bool {
753 !c.is_alphanumeric()
754 }
755
756 fn is_at_word_boundary(content: &str, pos: usize, is_start: bool) -> bool {
758 if is_start {
759 if pos == 0 {
760 return true;
761 }
762 match content[..pos].chars().next_back() {
763 None => true,
764 Some(c) => Self::is_word_boundary_char(c),
765 }
766 } else {
767 if pos >= content.len() {
768 return true;
769 }
770 match content[pos..].chars().next() {
771 None => true,
772 Some(c) => Self::is_word_boundary_char(c),
773 }
774 }
775 }
776
777 fn frontmatter_value_offset(line: &str) -> usize {
781 let trimmed = line.trim();
782
783 if trimmed == "---" || trimmed == "+++" || trimmed.is_empty() {
785 return usize::MAX;
786 }
787
788 if trimmed.starts_with('#') {
790 return usize::MAX;
791 }
792
793 let stripped = line.trim_start();
795 if let Some(after_dash) = stripped.strip_prefix("- ") {
796 let leading = line.len() - stripped.len();
797 if let Some(result) = Self::kv_value_offset(line, after_dash, leading + 2) {
799 return result;
800 }
801 return leading + 2;
803 }
804 if stripped == "-" {
805 return usize::MAX;
806 }
807
808 if let Some(result) = Self::kv_value_offset(line, stripped, line.len() - stripped.len()) {
810 return result;
811 }
812
813 if let Some(eq_pos) = line.find('=') {
815 let after_eq = eq_pos + 1;
816 if after_eq < line.len() && line.as_bytes()[after_eq] == b' ' {
817 let value_start = after_eq + 1;
818 let value_slice = &line[value_start..];
819 let value_trimmed = value_slice.trim();
820 if value_trimmed.is_empty() {
821 return usize::MAX;
822 }
823 if (value_trimmed.starts_with('"') && value_trimmed.ends_with('"'))
825 || (value_trimmed.starts_with('\'') && value_trimmed.ends_with('\''))
826 {
827 let quote_offset = value_slice.find(['"', '\'']).unwrap_or(0);
828 return value_start + quote_offset + 1;
829 }
830 return value_start;
831 }
832 return usize::MAX;
834 }
835
836 0
838 }
839
840 fn kv_value_offset(line: &str, content: &str, base_offset: usize) -> Option<usize> {
844 let colon_pos = content.find(':')?;
845 let abs_colon = base_offset + colon_pos;
846 let after_colon = abs_colon + 1;
847 if after_colon < line.len() && line.as_bytes()[after_colon] == b' ' {
848 let value_start = after_colon + 1;
849 let value_slice = &line[value_start..];
850 let value_trimmed = value_slice.trim();
851 if value_trimmed.is_empty() {
852 return Some(usize::MAX);
853 }
854 if value_trimmed.starts_with('{') || value_trimmed.starts_with('[') {
856 return Some(usize::MAX);
857 }
858 if (value_trimmed.starts_with('"') && value_trimmed.ends_with('"'))
860 || (value_trimmed.starts_with('\'') && value_trimmed.ends_with('\''))
861 {
862 let quote_offset = value_slice.find(['"', '\'']).unwrap_or(0);
863 return Some(value_start + quote_offset + 1);
864 }
865 return Some(value_start);
866 }
867 Some(usize::MAX)
869 }
870
871 fn get_proper_name_for(&self, found_name: &str) -> Option<String> {
873 let found_lower = found_name.to_lowercase();
874
875 for name in &self.config.names {
877 let lower_name = name.to_lowercase();
878 let lower_name_no_dots = lower_name.replace('.', "");
879
880 if found_lower == lower_name || found_lower == lower_name_no_dots {
882 return Some(name.clone());
883 }
884
885 let ascii_normalized = Self::ascii_normalize(&lower_name);
887
888 let ascii_no_dots = ascii_normalized.replace('.', "");
889
890 if found_lower == ascii_normalized || found_lower == ascii_no_dots {
891 return Some(name.clone());
892 }
893 }
894 None
895 }
896}
897
898impl Rule for MD044ProperNames {
899 fn name(&self) -> &'static str {
900 "MD044"
901 }
902
903 fn description(&self) -> &'static str {
904 "Proper names should have the correct capitalization"
905 }
906
907 fn category(&self) -> RuleCategory {
908 RuleCategory::Other
909 }
910
911 fn should_skip(&self, ctx: &crate::lint_context::LintContext) -> bool {
912 if self.config.names.is_empty() {
913 return true;
914 }
915 let content_lower = if ctx.content.is_ascii() {
917 ctx.content.to_ascii_lowercase()
918 } else {
919 ctx.content.to_lowercase()
920 };
921 !self.name_variants.iter().any(|name| content_lower.contains(name))
922 }
923
924 fn check(&self, ctx: &crate::lint_context::LintContext) -> LintResult {
925 let content = ctx.content;
926 if content.is_empty() || self.config.names.is_empty() || self.combined_pattern.is_none() {
927 return Ok(Vec::new());
928 }
929
930 let content_lower = if content.is_ascii() {
932 content.to_ascii_lowercase()
933 } else {
934 content.to_lowercase()
935 };
936
937 let has_potential_matches = self.name_variants.iter().any(|name| content_lower.contains(name));
939
940 if !has_potential_matches {
941 return Ok(Vec::new());
942 }
943
944 let line_index = &ctx.line_index;
945 let violations = self.find_name_violations(content, ctx, &content_lower);
946
947 let warnings = violations
948 .into_iter()
949 .filter_map(|(line, column, found_name)| {
950 self.get_proper_name_for(&found_name).map(|proper_name| {
951 let line_start = line_index.get_line_start_byte(line).unwrap_or(0);
956 let byte_start = line_start + (column - 1);
957 let byte_end = byte_start + found_name.len();
958 LintWarning {
959 rule_name: Some(self.name().to_string()),
960 line,
961 column,
962 end_line: line,
963 end_column: column + found_name.len(),
964 message: format!("Proper name '{found_name}' should be '{proper_name}'"),
965 severity: Severity::Warning,
966 fix: Some(Fix {
967 range: byte_start..byte_end,
968 replacement: proper_name,
969 }),
970 }
971 })
972 })
973 .collect();
974
975 Ok(warnings)
976 }
977
978 fn fix(&self, ctx: &crate::lint_context::LintContext) -> Result<String, LintError> {
979 if self.should_skip(ctx) {
980 return Ok(ctx.content.to_string());
981 }
982 let warnings = self.check(ctx)?;
983 if warnings.is_empty() {
984 return Ok(ctx.content.to_string());
985 }
986 let warnings =
987 crate::utils::fix_utils::filter_warnings_by_inline_config(warnings, ctx.inline_config(), self.name());
988 crate::utils::fix_utils::apply_warning_fixes(ctx.content, &warnings)
989 .map_err(crate::rule::LintError::InvalidInput)
990 }
991
992 fn as_any(&self) -> &dyn std::any::Any {
993 self
994 }
995
996 fn default_config_section(&self) -> Option<(String, toml::Value)> {
997 let json_value = serde_json::to_value(&self.config).ok()?;
998 Some((
999 self.name().to_string(),
1000 crate::rule_config_serde::json_to_toml_value(&json_value)?,
1001 ))
1002 }
1003
1004 fn from_config(config: &crate::config::Config) -> Box<dyn Rule>
1005 where
1006 Self: Sized,
1007 {
1008 let rule_config = crate::rule_config_serde::load_rule_config::<MD044Config>(config);
1009 Box::new(Self::from_config_struct(rule_config))
1010 }
1011}
1012
1013#[cfg(test)]
1014mod tests {
1015 use super::*;
1016 use crate::lint_context::LintContext;
1017
1018 fn create_context(content: &str) -> LintContext<'_> {
1019 LintContext::new(content, crate::config::MarkdownFlavor::Standard, None)
1020 }
1021
1022 #[test]
1023 fn test_correctly_capitalized_names() {
1024 let rule = MD044ProperNames::new(
1025 vec![
1026 "JavaScript".to_string(),
1027 "TypeScript".to_string(),
1028 "Node.js".to_string(),
1029 ],
1030 true,
1031 );
1032
1033 let content = "This document uses JavaScript, TypeScript, and Node.js correctly.";
1034 let ctx = create_context(content);
1035 let result = rule.check(&ctx).unwrap();
1036 assert!(result.is_empty(), "Should not flag correctly capitalized names");
1037 }
1038
1039 #[test]
1040 fn test_incorrectly_capitalized_names() {
1041 let rule = MD044ProperNames::new(vec!["JavaScript".to_string(), "TypeScript".to_string()], true);
1042
1043 let content = "This document uses javascript and typescript incorrectly.";
1044 let ctx = create_context(content);
1045 let result = rule.check(&ctx).unwrap();
1046
1047 assert_eq!(result.len(), 2, "Should flag two incorrect capitalizations");
1048 assert_eq!(result[0].message, "Proper name 'javascript' should be 'JavaScript'");
1049 assert_eq!(result[0].line, 1);
1050 assert_eq!(result[0].column, 20);
1051 assert_eq!(result[1].message, "Proper name 'typescript' should be 'TypeScript'");
1052 assert_eq!(result[1].line, 1);
1053 assert_eq!(result[1].column, 35);
1054 }
1055
1056 #[test]
1057 fn test_names_at_beginning_of_sentences() {
1058 let rule = MD044ProperNames::new(vec!["JavaScript".to_string(), "Python".to_string()], true);
1059
1060 let content = "javascript is a great language. python is also popular.";
1061 let ctx = create_context(content);
1062 let result = rule.check(&ctx).unwrap();
1063
1064 assert_eq!(result.len(), 2, "Should flag names at beginning of sentences");
1065 assert_eq!(result[0].line, 1);
1066 assert_eq!(result[0].column, 1);
1067 assert_eq!(result[1].line, 1);
1068 assert_eq!(result[1].column, 33);
1069 }
1070
1071 #[test]
1072 fn test_names_in_code_blocks_checked_by_default() {
1073 let rule = MD044ProperNames::new(vec!["JavaScript".to_string()], true);
1074
1075 let content = r#"Here is some text with JavaScript.
1076
1077```javascript
1078// This javascript should be checked
1079const lang = "javascript";
1080```
1081
1082But this javascript should be flagged."#;
1083
1084 let ctx = create_context(content);
1085 let result = rule.check(&ctx).unwrap();
1086
1087 assert_eq!(result.len(), 3, "Should flag javascript inside and outside code blocks");
1088 assert_eq!(result[0].line, 4);
1089 assert_eq!(result[1].line, 5);
1090 assert_eq!(result[2].line, 8);
1091 }
1092
1093 #[test]
1094 fn test_names_in_code_blocks_ignored_when_disabled() {
1095 let rule = MD044ProperNames::new(
1096 vec!["JavaScript".to_string()],
1097 false, );
1099
1100 let content = r#"```
1101javascript in code block
1102```"#;
1103
1104 let ctx = create_context(content);
1105 let result = rule.check(&ctx).unwrap();
1106
1107 assert_eq!(
1108 result.len(),
1109 0,
1110 "Should not flag javascript in code blocks when code_blocks is false"
1111 );
1112 }
1113
1114 #[test]
1115 fn test_names_in_inline_code_checked_by_default() {
1116 let rule = MD044ProperNames::new(vec!["JavaScript".to_string()], true);
1117
1118 let content = "This is `javascript` in inline code and javascript outside.";
1119 let ctx = create_context(content);
1120 let result = rule.check(&ctx).unwrap();
1121
1122 assert_eq!(result.len(), 2, "Should flag javascript inside and outside inline code");
1124 assert_eq!(result[0].column, 10); assert_eq!(result[1].column, 41); }
1127
1128 #[test]
1129 fn test_multiple_names_in_same_line() {
1130 let rule = MD044ProperNames::new(
1131 vec!["JavaScript".to_string(), "TypeScript".to_string(), "React".to_string()],
1132 true,
1133 );
1134
1135 let content = "I use javascript, typescript, and react in my projects.";
1136 let ctx = create_context(content);
1137 let result = rule.check(&ctx).unwrap();
1138
1139 assert_eq!(result.len(), 3, "Should flag all three incorrect names");
1140 assert_eq!(result[0].message, "Proper name 'javascript' should be 'JavaScript'");
1141 assert_eq!(result[1].message, "Proper name 'typescript' should be 'TypeScript'");
1142 assert_eq!(result[2].message, "Proper name 'react' should be 'React'");
1143 }
1144
1145 #[test]
1146 fn test_case_sensitivity() {
1147 let rule = MD044ProperNames::new(vec!["JavaScript".to_string()], true);
1148
1149 let content = "JAVASCRIPT, Javascript, javascript, and JavaScript variations.";
1150 let ctx = create_context(content);
1151 let result = rule.check(&ctx).unwrap();
1152
1153 assert_eq!(result.len(), 3, "Should flag all incorrect case variations");
1154 assert!(result.iter().all(|w| w.message.contains("should be 'JavaScript'")));
1156 }
1157
1158 #[test]
1159 fn test_configuration_with_custom_name_list() {
1160 let config = MD044Config {
1161 names: vec!["GitHub".to_string(), "GitLab".to_string(), "DevOps".to_string()],
1162 code_blocks: true,
1163 html_elements: true,
1164 html_comments: true,
1165 };
1166 let rule = MD044ProperNames::from_config_struct(config);
1167
1168 let content = "We use github, gitlab, and devops for our workflow.";
1169 let ctx = create_context(content);
1170 let result = rule.check(&ctx).unwrap();
1171
1172 assert_eq!(result.len(), 3, "Should flag all custom names");
1173 assert_eq!(result[0].message, "Proper name 'github' should be 'GitHub'");
1174 assert_eq!(result[1].message, "Proper name 'gitlab' should be 'GitLab'");
1175 assert_eq!(result[2].message, "Proper name 'devops' should be 'DevOps'");
1176 }
1177
1178 #[test]
1179 fn test_empty_configuration() {
1180 let rule = MD044ProperNames::new(vec![], true);
1181
1182 let content = "This has javascript and typescript but no configured names.";
1183 let ctx = create_context(content);
1184 let result = rule.check(&ctx).unwrap();
1185
1186 assert!(result.is_empty(), "Should not flag anything with empty configuration");
1187 }
1188
1189 #[test]
1190 fn test_names_with_special_characters() {
1191 let rule = MD044ProperNames::new(
1192 vec!["Node.js".to_string(), "ASP.NET".to_string(), "C++".to_string()],
1193 true,
1194 );
1195
1196 let content = "We use nodejs, asp.net, ASP.NET, and c++ in our stack.";
1197 let ctx = create_context(content);
1198 let result = rule.check(&ctx).unwrap();
1199
1200 assert_eq!(result.len(), 3, "Should handle special characters correctly");
1205
1206 let messages: Vec<&str> = result.iter().map(|w| w.message.as_str()).collect();
1207 assert!(messages.contains(&"Proper name 'nodejs' should be 'Node.js'"));
1208 assert!(messages.contains(&"Proper name 'asp.net' should be 'ASP.NET'"));
1209 assert!(messages.contains(&"Proper name 'c++' should be 'C++'"));
1210 }
1211
1212 #[test]
1213 fn test_word_boundaries() {
1214 let rule = MD044ProperNames::new(vec!["Java".to_string(), "Script".to_string()], true);
1215
1216 let content = "JavaScript is not java or script, but Java and Script are separate.";
1217 let ctx = create_context(content);
1218 let result = rule.check(&ctx).unwrap();
1219
1220 assert_eq!(result.len(), 2, "Should respect word boundaries");
1222 assert!(result.iter().any(|w| w.column == 19)); assert!(result.iter().any(|w| w.column == 27)); }
1225
1226 #[test]
1227 fn test_fix_method() {
1228 let rule = MD044ProperNames::new(
1229 vec![
1230 "JavaScript".to_string(),
1231 "TypeScript".to_string(),
1232 "Node.js".to_string(),
1233 ],
1234 true,
1235 );
1236
1237 let content = "I love javascript, typescript, and nodejs!";
1238 let ctx = create_context(content);
1239 let fixed = rule.fix(&ctx).unwrap();
1240
1241 assert_eq!(fixed, "I love JavaScript, TypeScript, and Node.js!");
1242 }
1243
1244 #[test]
1245 fn test_fix_multiple_occurrences() {
1246 let rule = MD044ProperNames::new(vec!["Python".to_string()], true);
1247
1248 let content = "python is great. I use python daily. PYTHON is powerful.";
1249 let ctx = create_context(content);
1250 let fixed = rule.fix(&ctx).unwrap();
1251
1252 assert_eq!(fixed, "Python is great. I use Python daily. Python is powerful.");
1253 }
1254
1255 #[test]
1256 fn test_fix_checks_code_blocks_by_default() {
1257 let rule = MD044ProperNames::new(vec!["JavaScript".to_string()], true);
1258
1259 let content = r#"I love javascript.
1260
1261```
1262const lang = "javascript";
1263```
1264
1265More javascript here."#;
1266
1267 let ctx = create_context(content);
1268 let fixed = rule.fix(&ctx).unwrap();
1269
1270 let expected = r#"I love JavaScript.
1271
1272```
1273const lang = "JavaScript";
1274```
1275
1276More JavaScript here."#;
1277
1278 assert_eq!(fixed, expected);
1279 }
1280
1281 #[test]
1282 fn test_multiline_content() {
1283 let rule = MD044ProperNames::new(vec!["Rust".to_string(), "Python".to_string()], true);
1284
1285 let content = r#"First line with rust.
1286Second line with python.
1287Third line with RUST and PYTHON."#;
1288
1289 let ctx = create_context(content);
1290 let result = rule.check(&ctx).unwrap();
1291
1292 assert_eq!(result.len(), 4, "Should flag all incorrect occurrences");
1293 assert_eq!(result[0].line, 1);
1294 assert_eq!(result[1].line, 2);
1295 assert_eq!(result[2].line, 3);
1296 assert_eq!(result[3].line, 3);
1297 }
1298
1299 #[test]
1300 fn test_default_config() {
1301 let config = MD044Config::default();
1302 assert!(config.names.is_empty());
1303 assert!(!config.code_blocks);
1304 assert!(config.html_elements);
1305 assert!(config.html_comments);
1306 }
1307
1308 #[test]
1309 fn test_default_config_checks_html_comments() {
1310 let config = MD044Config {
1311 names: vec!["JavaScript".to_string()],
1312 ..MD044Config::default()
1313 };
1314 let rule = MD044ProperNames::from_config_struct(config);
1315
1316 let content = "# Guide\n\n<!-- javascript mentioned here -->\n";
1317 let ctx = create_context(content);
1318 let result = rule.check(&ctx).unwrap();
1319
1320 assert_eq!(result.len(), 1, "Default config should check HTML comments");
1321 assert_eq!(result[0].line, 3);
1322 }
1323
1324 #[test]
1325 fn test_default_config_skips_code_blocks() {
1326 let config = MD044Config {
1327 names: vec!["JavaScript".to_string()],
1328 ..MD044Config::default()
1329 };
1330 let rule = MD044ProperNames::from_config_struct(config);
1331
1332 let content = "# Guide\n\n```\njavascript in code\n```\n";
1333 let ctx = create_context(content);
1334 let result = rule.check(&ctx).unwrap();
1335
1336 assert_eq!(result.len(), 0, "Default config should skip code blocks");
1337 }
1338
1339 #[test]
1340 fn test_standalone_html_comment_checked() {
1341 let config = MD044Config {
1342 names: vec!["Test".to_string()],
1343 ..MD044Config::default()
1344 };
1345 let rule = MD044ProperNames::from_config_struct(config);
1346
1347 let content = "# Heading\n\n<!-- this is a test example -->\n";
1348 let ctx = create_context(content);
1349 let result = rule.check(&ctx).unwrap();
1350
1351 assert_eq!(result.len(), 1, "Should flag proper name in standalone HTML comment");
1352 assert_eq!(result[0].line, 3);
1353 }
1354
1355 #[test]
1356 fn test_inline_config_comments_not_flagged() {
1357 let config = MD044Config {
1358 names: vec!["RUMDL".to_string()],
1359 ..MD044Config::default()
1360 };
1361 let rule = MD044ProperNames::from_config_struct(config);
1362
1363 let content = "<!-- rumdl-disable MD044 -->\nSome rumdl text here.\n<!-- rumdl-enable MD044 -->\n<!-- markdownlint-disable -->\nMore rumdl text.\n<!-- markdownlint-enable -->\n";
1367 let ctx = create_context(content);
1368 let result = rule.check(&ctx).unwrap();
1369
1370 assert_eq!(result.len(), 2, "Should only flag body lines, not config comments");
1371 assert_eq!(result[0].line, 2);
1372 assert_eq!(result[1].line, 5);
1373 }
1374
1375 #[test]
1376 fn test_html_comment_skipped_when_disabled() {
1377 let config = MD044Config {
1378 names: vec!["Test".to_string()],
1379 code_blocks: true,
1380 html_elements: true,
1381 html_comments: false,
1382 };
1383 let rule = MD044ProperNames::from_config_struct(config);
1384
1385 let content = "# Heading\n\n<!-- this is a test example -->\n\nRegular test here.\n";
1386 let ctx = create_context(content);
1387 let result = rule.check(&ctx).unwrap();
1388
1389 assert_eq!(
1390 result.len(),
1391 1,
1392 "Should only flag 'test' outside HTML comment when html_comments=false"
1393 );
1394 assert_eq!(result[0].line, 5);
1395 }
1396
1397 #[test]
1398 fn test_fix_corrects_html_comment_content() {
1399 let config = MD044Config {
1400 names: vec!["JavaScript".to_string()],
1401 ..MD044Config::default()
1402 };
1403 let rule = MD044ProperNames::from_config_struct(config);
1404
1405 let content = "# Guide\n\n<!-- javascript mentioned here -->\n";
1406 let ctx = create_context(content);
1407 let fixed = rule.fix(&ctx).unwrap();
1408
1409 assert_eq!(fixed, "# Guide\n\n<!-- JavaScript mentioned here -->\n");
1410 }
1411
1412 #[test]
1413 fn test_fix_does_not_modify_inline_config_comments() {
1414 let config = MD044Config {
1415 names: vec!["RUMDL".to_string()],
1416 ..MD044Config::default()
1417 };
1418 let rule = MD044ProperNames::from_config_struct(config);
1419
1420 let content = "<!-- rumdl-disable -->\nSome rumdl text.\n<!-- rumdl-enable -->\n";
1421 let ctx = create_context(content);
1422 let fixed = rule.fix(&ctx).unwrap();
1423
1424 assert!(fixed.contains("<!-- rumdl-disable -->"));
1426 assert!(fixed.contains("<!-- rumdl-enable -->"));
1427 assert!(
1429 fixed.contains("Some rumdl text."),
1430 "Line inside rumdl-disable block should not be modified by fix()"
1431 );
1432 }
1433
1434 #[test]
1435 fn test_fix_respects_inline_disable_partial() {
1436 let config = MD044Config {
1437 names: vec!["RUMDL".to_string()],
1438 ..MD044Config::default()
1439 };
1440 let rule = MD044ProperNames::from_config_struct(config);
1441
1442 let content =
1443 "<!-- rumdl-disable MD044 -->\nSome rumdl text.\n<!-- rumdl-enable MD044 -->\n\nSome rumdl text outside.\n";
1444 let ctx = create_context(content);
1445 let fixed = rule.fix(&ctx).unwrap();
1446
1447 assert!(
1449 fixed.contains("Some rumdl text.\n<!-- rumdl-enable"),
1450 "Line inside disable block should not be modified"
1451 );
1452 assert!(
1454 fixed.contains("Some RUMDL text outside."),
1455 "Line outside disable block should be fixed"
1456 );
1457 }
1458
1459 #[test]
1460 fn test_performance_with_many_names() {
1461 let mut names = vec![];
1462 for i in 0..50 {
1463 names.push(format!("ProperName{i}"));
1464 }
1465
1466 let rule = MD044ProperNames::new(names, true);
1467
1468 let content = "This has propername0, propername25, and propername49 incorrectly.";
1469 let ctx = create_context(content);
1470 let result = rule.check(&ctx).unwrap();
1471
1472 assert_eq!(result.len(), 3, "Should handle many configured names efficiently");
1473 }
1474
1475 #[test]
1476 fn test_large_name_count_performance() {
1477 let names = (0..1000).map(|i| format!("ProperName{i}")).collect::<Vec<_>>();
1480
1481 let rule = MD044ProperNames::new(names, true);
1482
1483 assert!(rule.combined_pattern.is_some());
1485
1486 let content = "This has propername0 and propername999 in it.";
1488 let ctx = create_context(content);
1489 let result = rule.check(&ctx).unwrap();
1490
1491 assert_eq!(result.len(), 2, "Should handle 1000 names without issues");
1493 }
1494
1495 #[test]
1496 fn test_cache_behavior() {
1497 let rule = MD044ProperNames::new(vec!["JavaScript".to_string()], true);
1498
1499 let content = "Using javascript here.";
1500 let ctx = create_context(content);
1501
1502 let result1 = rule.check(&ctx).unwrap();
1504 assert_eq!(result1.len(), 1);
1505
1506 let result2 = rule.check(&ctx).unwrap();
1508 assert_eq!(result2.len(), 1);
1509
1510 assert_eq!(result1[0].line, result2[0].line);
1512 assert_eq!(result1[0].column, result2[0].column);
1513 }
1514
1515 #[test]
1516 fn test_html_comments_not_checked_when_disabled() {
1517 let config = MD044Config {
1518 names: vec!["JavaScript".to_string()],
1519 code_blocks: true, html_elements: true, html_comments: false, };
1523 let rule = MD044ProperNames::from_config_struct(config);
1524
1525 let content = r#"Regular javascript here.
1526<!-- This javascript in HTML comment should be ignored -->
1527More javascript outside."#;
1528
1529 let ctx = create_context(content);
1530 let result = rule.check(&ctx).unwrap();
1531
1532 assert_eq!(result.len(), 2, "Should only flag javascript outside HTML comments");
1533 assert_eq!(result[0].line, 1);
1534 assert_eq!(result[1].line, 3);
1535 }
1536
1537 #[test]
1538 fn test_html_comments_checked_when_enabled() {
1539 let config = MD044Config {
1540 names: vec!["JavaScript".to_string()],
1541 code_blocks: true, html_elements: true, html_comments: true, };
1545 let rule = MD044ProperNames::from_config_struct(config);
1546
1547 let content = r#"Regular javascript here.
1548<!-- This javascript in HTML comment should be checked -->
1549More javascript outside."#;
1550
1551 let ctx = create_context(content);
1552 let result = rule.check(&ctx).unwrap();
1553
1554 assert_eq!(
1555 result.len(),
1556 3,
1557 "Should flag all javascript occurrences including in HTML comments"
1558 );
1559 }
1560
1561 #[test]
1562 fn test_multiline_html_comments() {
1563 let config = MD044Config {
1564 names: vec!["Python".to_string(), "JavaScript".to_string()],
1565 code_blocks: true, html_elements: true, html_comments: false, };
1569 let rule = MD044ProperNames::from_config_struct(config);
1570
1571 let content = r#"Regular python here.
1572<!--
1573This is a multiline comment
1574with javascript and python
1575that should be ignored
1576-->
1577More javascript outside."#;
1578
1579 let ctx = create_context(content);
1580 let result = rule.check(&ctx).unwrap();
1581
1582 assert_eq!(result.len(), 2, "Should only flag names outside HTML comments");
1583 assert_eq!(result[0].line, 1); assert_eq!(result[1].line, 7); }
1586
1587 #[test]
1588 fn test_fix_preserves_html_comments_when_disabled() {
1589 let config = MD044Config {
1590 names: vec!["JavaScript".to_string()],
1591 code_blocks: true, html_elements: true, html_comments: false, };
1595 let rule = MD044ProperNames::from_config_struct(config);
1596
1597 let content = r#"javascript here.
1598<!-- javascript in comment -->
1599More javascript."#;
1600
1601 let ctx = create_context(content);
1602 let fixed = rule.fix(&ctx).unwrap();
1603
1604 let expected = r#"JavaScript here.
1605<!-- javascript in comment -->
1606More JavaScript."#;
1607
1608 assert_eq!(
1609 fixed, expected,
1610 "Should not fix names inside HTML comments when disabled"
1611 );
1612 }
1613
1614 #[test]
1615 fn test_proper_names_in_link_text_are_flagged() {
1616 let rule = MD044ProperNames::new(
1617 vec!["JavaScript".to_string(), "Node.js".to_string(), "Python".to_string()],
1618 true,
1619 );
1620
1621 let content = r#"Check this [javascript documentation](https://javascript.info) for info.
1622
1623Visit [node.js homepage](https://nodejs.org) and [python tutorial](https://python.org).
1624
1625Real javascript should be flagged.
1626
1627Also see the [typescript guide][ts-ref] for more.
1628
1629Real python should be flagged too.
1630
1631[ts-ref]: https://typescript.org/handbook"#;
1632
1633 let ctx = create_context(content);
1634 let result = rule.check(&ctx).unwrap();
1635
1636 assert_eq!(result.len(), 5, "Expected 5 warnings: 3 in link text + 2 standalone");
1643
1644 let line_1_warnings: Vec<_> = result.iter().filter(|w| w.line == 1).collect();
1646 assert_eq!(line_1_warnings.len(), 1);
1647 assert!(
1648 line_1_warnings[0]
1649 .message
1650 .contains("'javascript' should be 'JavaScript'")
1651 );
1652
1653 let line_3_warnings: Vec<_> = result.iter().filter(|w| w.line == 3).collect();
1654 assert_eq!(line_3_warnings.len(), 2); assert!(result.iter().any(|w| w.line == 5 && w.message.contains("'javascript'")));
1658 assert!(result.iter().any(|w| w.line == 9 && w.message.contains("'python'")));
1659 }
1660
1661 #[test]
1662 fn test_link_urls_not_flagged() {
1663 let rule = MD044ProperNames::new(vec!["JavaScript".to_string()], true);
1664
1665 let content = r#"[Link Text](https://javascript.info/guide)"#;
1667
1668 let ctx = create_context(content);
1669 let result = rule.check(&ctx).unwrap();
1670
1671 assert!(result.is_empty(), "URLs should not be checked for proper names");
1673 }
1674
1675 #[test]
1676 fn test_proper_names_in_image_alt_text_are_flagged() {
1677 let rule = MD044ProperNames::new(vec!["JavaScript".to_string()], true);
1678
1679 let content = r#"Here is a  image.
1680
1681Real javascript should be flagged."#;
1682
1683 let ctx = create_context(content);
1684 let result = rule.check(&ctx).unwrap();
1685
1686 assert_eq!(result.len(), 2, "Expected 2 warnings: 1 in alt text + 1 standalone");
1690 assert!(result[0].message.contains("'javascript' should be 'JavaScript'"));
1691 assert!(result[0].line == 1); assert!(result[1].message.contains("'javascript' should be 'JavaScript'"));
1693 assert!(result[1].line == 3); }
1695
1696 #[test]
1697 fn test_image_urls_not_flagged() {
1698 let rule = MD044ProperNames::new(vec!["JavaScript".to_string()], true);
1699
1700 let content = r#""#;
1702
1703 let ctx = create_context(content);
1704 let result = rule.check(&ctx).unwrap();
1705
1706 assert!(result.is_empty(), "Image URLs should not be checked for proper names");
1708 }
1709
1710 #[test]
1711 fn test_reference_link_text_flagged_but_definition_not() {
1712 let rule = MD044ProperNames::new(vec!["JavaScript".to_string(), "TypeScript".to_string()], true);
1713
1714 let content = r#"Check the [javascript guide][js-ref] for details.
1715
1716Real javascript should be flagged.
1717
1718[js-ref]: https://javascript.info/typescript/guide"#;
1719
1720 let ctx = create_context(content);
1721 let result = rule.check(&ctx).unwrap();
1722
1723 assert_eq!(result.len(), 2, "Expected 2 warnings: 1 in link text + 1 standalone");
1728 assert!(result.iter().any(|w| w.line == 1 && w.message.contains("'javascript'")));
1729 assert!(result.iter().any(|w| w.line == 3 && w.message.contains("'javascript'")));
1730 }
1731
1732 #[test]
1733 fn test_reference_definitions_not_flagged() {
1734 let rule = MD044ProperNames::new(vec!["JavaScript".to_string()], true);
1735
1736 let content = r#"[js-ref]: https://javascript.info/guide"#;
1738
1739 let ctx = create_context(content);
1740 let result = rule.check(&ctx).unwrap();
1741
1742 assert!(result.is_empty(), "Reference definitions should not be checked");
1744 }
1745
1746 #[test]
1747 fn test_wikilinks_text_is_flagged() {
1748 let rule = MD044ProperNames::new(vec!["JavaScript".to_string()], true);
1749
1750 let content = r#"[[javascript]]
1752
1753Regular javascript here.
1754
1755[[JavaScript|display text]]"#;
1756
1757 let ctx = create_context(content);
1758 let result = rule.check(&ctx).unwrap();
1759
1760 assert_eq!(result.len(), 2, "Expected 2 warnings: 1 in WikiLink + 1 standalone");
1764 assert!(
1765 result
1766 .iter()
1767 .any(|w| w.line == 1 && w.column == 3 && w.message.contains("'javascript'"))
1768 );
1769 assert!(result.iter().any(|w| w.line == 3 && w.message.contains("'javascript'")));
1770 }
1771
1772 #[test]
1773 fn test_url_link_text_not_flagged() {
1774 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], true);
1775
1776 let content = r#"[https://github.com/org/repo](https://github.com/org/repo)
1778
1779[http://github.com/org/repo](http://github.com/org/repo)
1780
1781[www.github.com/org/repo](https://www.github.com/org/repo)"#;
1782
1783 let ctx = create_context(content);
1784 let result = rule.check(&ctx).unwrap();
1785
1786 assert!(
1787 result.is_empty(),
1788 "URL-like link text should not be flagged, got: {result:?}"
1789 );
1790 }
1791
1792 #[test]
1793 fn test_url_link_text_with_leading_space_not_flagged() {
1794 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], true);
1795
1796 let content = r#"[ https://github.com/org/repo](https://github.com/org/repo)"#;
1798
1799 let ctx = create_context(content);
1800 let result = rule.check(&ctx).unwrap();
1801
1802 assert!(
1803 result.is_empty(),
1804 "URL-like link text with leading space should not be flagged, got: {result:?}"
1805 );
1806 }
1807
1808 #[test]
1809 fn test_url_link_text_uppercase_scheme_not_flagged() {
1810 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], true);
1811
1812 let content = r#"[HTTPS://GITHUB.COM/org/repo](https://github.com/org/repo)"#;
1813
1814 let ctx = create_context(content);
1815 let result = rule.check(&ctx).unwrap();
1816
1817 assert!(
1818 result.is_empty(),
1819 "URL-like link text with uppercase scheme should not be flagged, got: {result:?}"
1820 );
1821 }
1822
1823 #[test]
1824 fn test_non_url_link_text_still_flagged() {
1825 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], true);
1826
1827 let content = r#"[github.com/org/repo](https://github.com/org/repo)
1831
1832[Visit github](https://github.com/org/repo)
1833
1834[//github.com/org/repo](//github.com/org/repo)
1835
1836[ftp://github.com/org/repo](ftp://github.com/org/repo)"#;
1837
1838 let ctx = create_context(content);
1839 let result = rule.check(&ctx).unwrap();
1840
1841 assert_eq!(
1846 result.len(),
1847 1,
1848 "Only prose link text should be flagged, got: {result:?}"
1849 );
1850 assert!(
1851 result.iter().any(|w| w.line == 3),
1852 "Expected 'Visit github' on line 3 to be flagged"
1853 );
1854 }
1855
1856 #[test]
1857 fn test_url_link_text_fix_not_applied() {
1858 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], true);
1859
1860 let content = "[https://github.com/org/repo](https://github.com/org/repo)\n";
1861
1862 let ctx = create_context(content);
1863 let result = rule.fix(&ctx).unwrap();
1864
1865 assert_eq!(result, content, "Fix should not modify URL-like link text");
1866 }
1867
1868 #[test]
1869 fn test_mixed_url_and_regular_link_text() {
1870 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], true);
1871
1872 let content = r#"[https://github.com/org/repo](https://github.com/org/repo)
1874
1875Visit [github documentation](https://github.com/docs) for details.
1876
1877[www.github.com/pricing](https://www.github.com/pricing)"#;
1878
1879 let ctx = create_context(content);
1880 let result = rule.check(&ctx).unwrap();
1881
1882 assert_eq!(
1884 result.len(),
1885 1,
1886 "Only non-URL link text should be flagged, got: {result:?}"
1887 );
1888 assert_eq!(result[0].line, 3);
1889 }
1890
1891 #[test]
1892 fn test_html_attribute_values_not_flagged() {
1893 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
1896 let content = "# Heading\n\ntest\n\n<img src=\"www.example.test/test_image.png\">\n";
1897 let ctx = crate::lint_context::LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
1898 let result = rule.check(&ctx).unwrap();
1899
1900 let line5_violations: Vec<_> = result.iter().filter(|w| w.line == 5).collect();
1902 assert!(
1903 line5_violations.is_empty(),
1904 "Should not flag anything inside HTML tag attributes: {line5_violations:?}"
1905 );
1906
1907 let line3_violations: Vec<_> = result.iter().filter(|w| w.line == 3).collect();
1909 assert_eq!(line3_violations.len(), 1, "Plain 'test' on line 3 should be flagged");
1910 }
1911
1912 #[test]
1913 fn test_html_text_content_still_flagged() {
1914 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
1916 let content = "# Heading\n\n<a href=\"https://example.test/page\">test link</a>\n";
1917 let ctx = crate::lint_context::LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
1918 let result = rule.check(&ctx).unwrap();
1919
1920 assert_eq!(
1923 result.len(),
1924 1,
1925 "Should flag only 'test' in anchor text, not in href: {result:?}"
1926 );
1927 assert_eq!(result[0].column, 37, "Should flag col 37 ('test link' in anchor text)");
1928 }
1929
1930 #[test]
1931 fn test_html_attribute_various_not_flagged() {
1932 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
1934 let content = concat!(
1935 "# Heading\n\n",
1936 "<img src=\"test.png\" alt=\"test image\">\n",
1937 "<span class=\"test-class\" data-test=\"value\">test content</span>\n",
1938 );
1939 let ctx = crate::lint_context::LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
1940 let result = rule.check(&ctx).unwrap();
1941
1942 assert_eq!(
1944 result.len(),
1945 1,
1946 "Should flag only 'test content' between tags: {result:?}"
1947 );
1948 assert_eq!(result[0].line, 4);
1949 }
1950
1951 #[test]
1952 fn test_plain_text_underscore_boundary_unchanged() {
1953 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
1956 let content = "# Heading\n\ntest_image is here and just_test ends here\n";
1957 let ctx = crate::lint_context::LintContext::new(content, crate::config::MarkdownFlavor::Standard, None);
1958 let result = rule.check(&ctx).unwrap();
1959
1960 assert_eq!(
1963 result.len(),
1964 2,
1965 "Should flag 'test' in both 'test_image' and 'just_test': {result:?}"
1966 );
1967 let cols: Vec<usize> = result.iter().map(|w| w.column).collect();
1968 assert!(cols.contains(&1), "Should flag col 1 (test_image): {cols:?}");
1969 assert!(cols.contains(&29), "Should flag col 29 (just_test): {cols:?}");
1970 }
1971
1972 #[test]
1973 fn test_frontmatter_yaml_keys_not_flagged() {
1974 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
1977
1978 let content = "---\ntitle: Heading\ntest: Some Test value\n---\n\nTest\n";
1979 let ctx = create_context(content);
1980 let result = rule.check(&ctx).unwrap();
1981
1982 assert!(
1986 result.is_empty(),
1987 "Should not flag YAML keys or correctly capitalized values: {result:?}"
1988 );
1989 }
1990
1991 #[test]
1992 fn test_frontmatter_yaml_values_flagged() {
1993 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
1995
1996 let content = "---\ntitle: Heading\nkey: a test value\n---\n\nTest\n";
1997 let ctx = create_context(content);
1998 let result = rule.check(&ctx).unwrap();
1999
2000 assert_eq!(result.len(), 1, "Should flag 'test' in YAML value: {result:?}");
2002 assert_eq!(result[0].line, 3);
2003 assert_eq!(result[0].column, 8); }
2005
2006 #[test]
2007 fn test_frontmatter_key_matches_name_not_flagged() {
2008 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2010
2011 let content = "---\ntest: other value\n---\n\nBody text\n";
2012 let ctx = create_context(content);
2013 let result = rule.check(&ctx).unwrap();
2014
2015 assert!(
2016 result.is_empty(),
2017 "Should not flag YAML key that matches configured name: {result:?}"
2018 );
2019 }
2020
2021 #[test]
2022 fn test_frontmatter_empty_value_not_flagged() {
2023 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2025
2026 let content = "---\ntest:\ntest: \n---\n\nBody text\n";
2027 let ctx = create_context(content);
2028 let result = rule.check(&ctx).unwrap();
2029
2030 assert!(
2031 result.is_empty(),
2032 "Should not flag YAML keys with empty values: {result:?}"
2033 );
2034 }
2035
2036 #[test]
2037 fn test_frontmatter_nested_yaml_key_not_flagged() {
2038 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2040
2041 let content = "---\nparent:\n test: nested value\n---\n\nBody text\n";
2042 let ctx = create_context(content);
2043 let result = rule.check(&ctx).unwrap();
2044
2045 assert!(result.is_empty(), "Should not flag nested YAML keys: {result:?}");
2047 }
2048
2049 #[test]
2050 fn test_frontmatter_list_items_checked() {
2051 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2053
2054 let content = "---\ntags:\n - test\n - other\n---\n\nBody text\n";
2055 let ctx = create_context(content);
2056 let result = rule.check(&ctx).unwrap();
2057
2058 assert_eq!(result.len(), 1, "Should flag 'test' in YAML list item: {result:?}");
2060 assert_eq!(result[0].line, 3);
2061 }
2062
2063 #[test]
2064 fn test_frontmatter_value_with_multiple_colons() {
2065 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2067
2068 let content = "---\ntest: description: a test thing\n---\n\nBody text\n";
2069 let ctx = create_context(content);
2070 let result = rule.check(&ctx).unwrap();
2071
2072 assert_eq!(
2075 result.len(),
2076 1,
2077 "Should flag 'test' in value after first colon: {result:?}"
2078 );
2079 assert_eq!(result[0].line, 2);
2080 assert!(result[0].column > 6, "Violation column should be in value portion");
2081 }
2082
2083 #[test]
2084 fn test_frontmatter_does_not_affect_body() {
2085 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2087
2088 let content = "---\ntitle: Heading\n---\n\ntest should be flagged here\n";
2089 let ctx = create_context(content);
2090 let result = rule.check(&ctx).unwrap();
2091
2092 assert_eq!(result.len(), 1, "Should flag 'test' in body text: {result:?}");
2093 assert_eq!(result[0].line, 5);
2094 }
2095
2096 #[test]
2097 fn test_frontmatter_fix_corrects_values_preserves_keys() {
2098 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2100
2101 let content = "---\ntest: a test value\n---\n\ntest here\n";
2102 let ctx = create_context(content);
2103 let fixed = rule.fix(&ctx).unwrap();
2104
2105 assert_eq!(fixed, "---\ntest: a Test value\n---\n\nTest here\n");
2107 }
2108
2109 #[test]
2110 fn test_frontmatter_multiword_value_flagged() {
2111 let rule = MD044ProperNames::new(vec!["JavaScript".to_string(), "TypeScript".to_string()], true);
2113
2114 let content = "---\ndescription: Learn javascript and typescript\n---\n\nBody\n";
2115 let ctx = create_context(content);
2116 let result = rule.check(&ctx).unwrap();
2117
2118 assert_eq!(result.len(), 2, "Should flag both names in YAML value: {result:?}");
2119 assert!(result.iter().all(|w| w.line == 2));
2120 }
2121
2122 #[test]
2123 fn test_frontmatter_yaml_comments_not_checked() {
2124 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2126
2127 let content = "---\n# test comment\ntitle: Heading\n---\n\nBody text\n";
2128 let ctx = create_context(content);
2129 let result = rule.check(&ctx).unwrap();
2130
2131 assert!(result.is_empty(), "Should not flag names in YAML comments: {result:?}");
2132 }
2133
2134 #[test]
2135 fn test_frontmatter_delimiters_not_checked() {
2136 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2138
2139 let content = "---\ntitle: Heading\n---\n\ntest here\n";
2140 let ctx = create_context(content);
2141 let result = rule.check(&ctx).unwrap();
2142
2143 assert_eq!(result.len(), 1, "Should only flag body text: {result:?}");
2145 assert_eq!(result[0].line, 5);
2146 }
2147
2148 #[test]
2149 fn test_frontmatter_continuation_lines_checked() {
2150 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2152
2153 let content = "---\ndescription: >\n a test value\n continued here\n---\n\nBody\n";
2154 let ctx = create_context(content);
2155 let result = rule.check(&ctx).unwrap();
2156
2157 assert_eq!(result.len(), 1, "Should flag 'test' in continuation line: {result:?}");
2159 assert_eq!(result[0].line, 3);
2160 }
2161
2162 #[test]
2163 fn test_frontmatter_quoted_values_checked() {
2164 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2166
2167 let content = "---\ntitle: \"a test title\"\n---\n\nBody\n";
2168 let ctx = create_context(content);
2169 let result = rule.check(&ctx).unwrap();
2170
2171 assert_eq!(result.len(), 1, "Should flag 'test' in quoted YAML value: {result:?}");
2172 assert_eq!(result[0].line, 2);
2173 }
2174
2175 #[test]
2176 fn test_frontmatter_single_quoted_values_checked() {
2177 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2179
2180 let content = "---\ntitle: 'a test title'\n---\n\nBody\n";
2181 let ctx = create_context(content);
2182 let result = rule.check(&ctx).unwrap();
2183
2184 assert_eq!(
2185 result.len(),
2186 1,
2187 "Should flag 'test' in single-quoted YAML value: {result:?}"
2188 );
2189 assert_eq!(result[0].line, 2);
2190 }
2191
2192 #[test]
2193 fn test_frontmatter_fix_multiword_values() {
2194 let rule = MD044ProperNames::new(vec!["JavaScript".to_string(), "TypeScript".to_string()], true);
2196
2197 let content = "---\ndescription: Learn javascript and typescript\n---\n\nBody\n";
2198 let ctx = create_context(content);
2199 let fixed = rule.fix(&ctx).unwrap();
2200
2201 assert_eq!(
2202 fixed,
2203 "---\ndescription: Learn JavaScript and TypeScript\n---\n\nBody\n"
2204 );
2205 }
2206
2207 #[test]
2208 fn test_frontmatter_fix_preserves_yaml_structure() {
2209 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2211
2212 let content = "---\ntags:\n - test\n - other\ntitle: a test doc\n---\n\ntest body\n";
2213 let ctx = create_context(content);
2214 let fixed = rule.fix(&ctx).unwrap();
2215
2216 assert_eq!(
2217 fixed,
2218 "---\ntags:\n - Test\n - other\ntitle: a Test doc\n---\n\nTest body\n"
2219 );
2220 }
2221
2222 #[test]
2223 fn test_frontmatter_toml_delimiters_not_checked() {
2224 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2226
2227 let content = "+++\ntitle = \"a test title\"\n+++\n\ntest body\n";
2228 let ctx = create_context(content);
2229 let result = rule.check(&ctx).unwrap();
2230
2231 assert_eq!(result.len(), 2, "Should flag TOML value and body: {result:?}");
2235 let fm_violations: Vec<_> = result.iter().filter(|w| w.line == 2).collect();
2236 assert_eq!(fm_violations.len(), 1, "Should flag 'test' in TOML value: {result:?}");
2237 let body_violations: Vec<_> = result.iter().filter(|w| w.line == 5).collect();
2238 assert_eq!(body_violations.len(), 1, "Should flag body 'test': {result:?}");
2239 }
2240
2241 #[test]
2242 fn test_frontmatter_toml_key_not_flagged() {
2243 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2245
2246 let content = "+++\ntest = \"other value\"\n+++\n\nBody text\n";
2247 let ctx = create_context(content);
2248 let result = rule.check(&ctx).unwrap();
2249
2250 assert!(
2251 result.is_empty(),
2252 "Should not flag TOML key that matches configured name: {result:?}"
2253 );
2254 }
2255
2256 #[test]
2257 fn test_frontmatter_toml_fix_preserves_keys() {
2258 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2260
2261 let content = "+++\ntest = \"a test value\"\n+++\n\ntest here\n";
2262 let ctx = create_context(content);
2263 let fixed = rule.fix(&ctx).unwrap();
2264
2265 assert_eq!(fixed, "+++\ntest = \"a Test value\"\n+++\n\nTest here\n");
2267 }
2268
2269 #[test]
2270 fn test_frontmatter_list_item_mapping_key_not_flagged() {
2271 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2274
2275 let content = "---\nitems:\n - test: nested value\n---\n\nBody text\n";
2276 let ctx = create_context(content);
2277 let result = rule.check(&ctx).unwrap();
2278
2279 assert!(
2280 result.is_empty(),
2281 "Should not flag YAML key in list-item mapping: {result:?}"
2282 );
2283 }
2284
2285 #[test]
2286 fn test_frontmatter_list_item_mapping_value_flagged() {
2287 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2289
2290 let content = "---\nitems:\n - key: a test value\n---\n\nBody text\n";
2291 let ctx = create_context(content);
2292 let result = rule.check(&ctx).unwrap();
2293
2294 assert_eq!(
2295 result.len(),
2296 1,
2297 "Should flag 'test' in list-item mapping value: {result:?}"
2298 );
2299 assert_eq!(result[0].line, 3);
2300 }
2301
2302 #[test]
2303 fn test_frontmatter_bare_list_item_still_flagged() {
2304 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2306
2307 let content = "---\ntags:\n - test\n - other\n---\n\nBody text\n";
2308 let ctx = create_context(content);
2309 let result = rule.check(&ctx).unwrap();
2310
2311 assert_eq!(result.len(), 1, "Should flag 'test' in bare list item: {result:?}");
2312 assert_eq!(result[0].line, 3);
2313 }
2314
2315 #[test]
2316 fn test_frontmatter_flow_mapping_not_flagged() {
2317 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2320
2321 let content = "---\nflow_map: {test: value, other: test}\n---\n\nBody text\n";
2322 let ctx = create_context(content);
2323 let result = rule.check(&ctx).unwrap();
2324
2325 assert!(
2326 result.is_empty(),
2327 "Should not flag names inside flow mappings: {result:?}"
2328 );
2329 }
2330
2331 #[test]
2332 fn test_frontmatter_flow_sequence_not_flagged() {
2333 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2335
2336 let content = "---\nitems: [test, other, test]\n---\n\nBody text\n";
2337 let ctx = create_context(content);
2338 let result = rule.check(&ctx).unwrap();
2339
2340 assert!(
2341 result.is_empty(),
2342 "Should not flag names inside flow sequences: {result:?}"
2343 );
2344 }
2345
2346 #[test]
2347 fn test_frontmatter_list_item_mapping_fix_preserves_key() {
2348 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2350
2351 let content = "---\nitems:\n - test: a test value\n---\n\ntest here\n";
2352 let ctx = create_context(content);
2353 let fixed = rule.fix(&ctx).unwrap();
2354
2355 assert_eq!(fixed, "---\nitems:\n - test: a Test value\n---\n\nTest here\n");
2358 }
2359
2360 #[test]
2361 fn test_frontmatter_backtick_code_not_flagged() {
2362 let config = MD044Config {
2364 names: vec!["GoodApplication".to_string()],
2365 code_blocks: false,
2366 ..MD044Config::default()
2367 };
2368 let rule = MD044ProperNames::from_config_struct(config);
2369
2370 let content = "---\ntitle: \"`goodapplication` CLI\"\n---\n\nIntroductory `goodapplication` CLI text.\n";
2371 let ctx = create_context(content);
2372 let result = rule.check(&ctx).unwrap();
2373
2374 assert!(
2376 result.is_empty(),
2377 "Should not flag names inside backticks in frontmatter or body: {result:?}"
2378 );
2379 }
2380
2381 #[test]
2382 fn test_frontmatter_unquoted_backtick_code_not_flagged() {
2383 let config = MD044Config {
2385 names: vec!["GoodApplication".to_string()],
2386 code_blocks: false,
2387 ..MD044Config::default()
2388 };
2389 let rule = MD044ProperNames::from_config_struct(config);
2390
2391 let content = "---\ntitle: `goodapplication` CLI\n---\n\nIntroductory `goodapplication` CLI text.\n";
2392 let ctx = create_context(content);
2393 let result = rule.check(&ctx).unwrap();
2394
2395 assert!(
2396 result.is_empty(),
2397 "Should not flag names inside backticks in unquoted YAML frontmatter: {result:?}"
2398 );
2399 }
2400
2401 #[test]
2402 fn test_frontmatter_bare_name_still_flagged_with_backtick_nearby() {
2403 let config = MD044Config {
2405 names: vec!["GoodApplication".to_string()],
2406 code_blocks: false,
2407 ..MD044Config::default()
2408 };
2409 let rule = MD044ProperNames::from_config_struct(config);
2410
2411 let content = "---\ntitle: goodapplication `goodapplication` CLI\n---\n\nBody\n";
2412 let ctx = create_context(content);
2413 let result = rule.check(&ctx).unwrap();
2414
2415 assert_eq!(
2417 result.len(),
2418 1,
2419 "Should flag bare name but not backtick-wrapped name: {result:?}"
2420 );
2421 assert_eq!(result[0].line, 2);
2422 assert_eq!(result[0].column, 8); }
2424
2425 #[test]
2426 fn test_frontmatter_backtick_code_with_code_blocks_true() {
2427 let config = MD044Config {
2429 names: vec!["GoodApplication".to_string()],
2430 code_blocks: true,
2431 ..MD044Config::default()
2432 };
2433 let rule = MD044ProperNames::from_config_struct(config);
2434
2435 let content = "---\ntitle: \"`goodapplication` CLI\"\n---\n\nBody\n";
2436 let ctx = create_context(content);
2437 let result = rule.check(&ctx).unwrap();
2438
2439 assert_eq!(
2441 result.len(),
2442 1,
2443 "Should flag backtick-wrapped name when code_blocks=true: {result:?}"
2444 );
2445 assert_eq!(result[0].line, 2);
2446 }
2447
2448 #[test]
2449 fn test_frontmatter_fix_preserves_backtick_code() {
2450 let config = MD044Config {
2452 names: vec!["GoodApplication".to_string()],
2453 code_blocks: false,
2454 ..MD044Config::default()
2455 };
2456 let rule = MD044ProperNames::from_config_struct(config);
2457
2458 let content = "---\ntitle: \"`goodapplication` CLI\"\n---\n\nIntroductory `goodapplication` CLI text.\n";
2459 let ctx = create_context(content);
2460 let fixed = rule.fix(&ctx).unwrap();
2461
2462 assert_eq!(
2464 fixed, content,
2465 "Fix should not modify names inside backticks in frontmatter"
2466 );
2467 }
2468
2469 #[test]
2472 fn test_angle_bracket_url_in_html_comment_not_flagged() {
2473 let config = MD044Config {
2475 names: vec!["Test".to_string()],
2476 ..MD044Config::default()
2477 };
2478 let rule = MD044ProperNames::from_config_struct(config);
2479
2480 let content = "---\ntitle: Level 1 heading\n---\n\n<https://www.example.test>\n\n<!-- This is a Test https://www.example.test -->\n<!-- This is a Test <https://www.example.test> -->\n";
2481 let ctx = create_context(content);
2482 let result = rule.check(&ctx).unwrap();
2483
2484 let line8_warnings: Vec<_> = result.iter().filter(|w| w.line == 8).collect();
2492 assert!(
2493 line8_warnings.is_empty(),
2494 "Should not flag names inside angle-bracket URLs in HTML comments: {line8_warnings:?}"
2495 );
2496 }
2497
2498 #[test]
2499 fn test_bare_url_in_html_comment_still_flagged() {
2500 let config = MD044Config {
2502 names: vec!["Test".to_string()],
2503 ..MD044Config::default()
2504 };
2505 let rule = MD044ProperNames::from_config_struct(config);
2506
2507 let content = "<!-- This is a test https://www.example.test -->\n";
2508 let ctx = create_context(content);
2509 let result = rule.check(&ctx).unwrap();
2510
2511 assert!(
2514 !result.is_empty(),
2515 "Should flag 'test' in prose text of HTML comment with bare URL"
2516 );
2517 }
2518
2519 #[test]
2520 fn test_angle_bracket_url_in_regular_markdown_not_flagged() {
2521 let rule = MD044ProperNames::new(vec!["Test".to_string()], true);
2524
2525 let content = "<https://www.example.test>\n";
2526 let ctx = create_context(content);
2527 let result = rule.check(&ctx).unwrap();
2528
2529 assert!(
2530 result.is_empty(),
2531 "Should not flag names inside angle-bracket URLs in regular markdown: {result:?}"
2532 );
2533 }
2534
2535 #[test]
2536 fn test_multiple_angle_bracket_urls_in_one_comment() {
2537 let config = MD044Config {
2538 names: vec!["Test".to_string()],
2539 ..MD044Config::default()
2540 };
2541 let rule = MD044ProperNames::from_config_struct(config);
2542
2543 let content = "<!-- See <https://test.example.com> and <https://www.example.test> for details -->\n";
2544 let ctx = create_context(content);
2545 let result = rule.check(&ctx).unwrap();
2546
2547 assert!(
2549 result.is_empty(),
2550 "Should not flag names inside multiple angle-bracket URLs: {result:?}"
2551 );
2552 }
2553
2554 #[test]
2555 fn test_angle_bracket_non_url_still_flagged() {
2556 assert!(
2559 !MD044ProperNames::is_in_angle_bracket_url("<test> which is not a URL.", 1),
2560 "is_in_angle_bracket_url should return false for non-URL angle brackets"
2561 );
2562 }
2563
2564 #[test]
2565 fn test_angle_bracket_mailto_url_not_flagged() {
2566 let config = MD044Config {
2567 names: vec!["Test".to_string()],
2568 ..MD044Config::default()
2569 };
2570 let rule = MD044ProperNames::from_config_struct(config);
2571
2572 let content = "<!-- Contact <mailto:test@example.com> for help -->\n";
2573 let ctx = create_context(content);
2574 let result = rule.check(&ctx).unwrap();
2575
2576 assert!(
2577 result.is_empty(),
2578 "Should not flag names inside angle-bracket mailto URLs: {result:?}"
2579 );
2580 }
2581
2582 #[test]
2583 fn test_angle_bracket_ftp_url_not_flagged() {
2584 let config = MD044Config {
2585 names: vec!["Test".to_string()],
2586 ..MD044Config::default()
2587 };
2588 let rule = MD044ProperNames::from_config_struct(config);
2589
2590 let content = "<!-- Download from <ftp://test.example.com/file> -->\n";
2591 let ctx = create_context(content);
2592 let result = rule.check(&ctx).unwrap();
2593
2594 assert!(
2595 result.is_empty(),
2596 "Should not flag names inside angle-bracket FTP URLs: {result:?}"
2597 );
2598 }
2599
2600 #[test]
2601 fn test_angle_bracket_url_fix_preserves_url() {
2602 let config = MD044Config {
2604 names: vec!["Test".to_string()],
2605 ..MD044Config::default()
2606 };
2607 let rule = MD044ProperNames::from_config_struct(config);
2608
2609 let content = "<!-- test text <https://www.example.test> -->\n";
2610 let ctx = create_context(content);
2611 let fixed = rule.fix(&ctx).unwrap();
2612
2613 assert!(
2615 fixed.contains("<https://www.example.test>"),
2616 "Fix should preserve angle-bracket URLs: {fixed}"
2617 );
2618 assert!(
2619 fixed.contains("Test text"),
2620 "Fix should correct prose 'test' to 'Test': {fixed}"
2621 );
2622 }
2623
2624 #[test]
2625 fn test_is_in_angle_bracket_url_helper() {
2626 let line = "text <https://example.test> more text";
2628
2629 assert!(MD044ProperNames::is_in_angle_bracket_url(line, 5)); assert!(MD044ProperNames::is_in_angle_bracket_url(line, 6)); assert!(MD044ProperNames::is_in_angle_bracket_url(line, 15)); assert!(MD044ProperNames::is_in_angle_bracket_url(line, 26)); assert!(!MD044ProperNames::is_in_angle_bracket_url(line, 0)); assert!(!MD044ProperNames::is_in_angle_bracket_url(line, 4)); assert!(!MD044ProperNames::is_in_angle_bracket_url(line, 27)); assert!(!MD044ProperNames::is_in_angle_bracket_url("<notaurl>", 1));
2642
2643 assert!(MD044ProperNames::is_in_angle_bracket_url(
2645 "<mailto:test@example.com>",
2646 10
2647 ));
2648
2649 assert!(MD044ProperNames::is_in_angle_bracket_url(
2651 "<ftp://test.example.com>",
2652 10
2653 ));
2654 }
2655
2656 #[test]
2657 fn test_is_in_angle_bracket_url_uppercase_scheme() {
2658 assert!(MD044ProperNames::is_in_angle_bracket_url(
2660 "<HTTPS://test.example.com>",
2661 10
2662 ));
2663 assert!(MD044ProperNames::is_in_angle_bracket_url(
2664 "<Http://test.example.com>",
2665 10
2666 ));
2667 }
2668
2669 #[test]
2670 fn test_is_in_angle_bracket_url_uncommon_schemes() {
2671 assert!(MD044ProperNames::is_in_angle_bracket_url(
2673 "<ssh://test@example.com>",
2674 10
2675 ));
2676 assert!(MD044ProperNames::is_in_angle_bracket_url("<file:///test/path>", 10));
2678 assert!(MD044ProperNames::is_in_angle_bracket_url("<data:text/plain;test>", 10));
2680 }
2681
2682 #[test]
2683 fn test_is_in_angle_bracket_url_unclosed() {
2684 assert!(!MD044ProperNames::is_in_angle_bracket_url(
2686 "<https://test.example.com",
2687 10
2688 ));
2689 }
2690
2691 #[test]
2692 fn test_vale_inline_config_comments_not_flagged() {
2693 let config = MD044Config {
2694 names: vec!["Vale".to_string(), "JavaScript".to_string()],
2695 ..MD044Config::default()
2696 };
2697 let rule = MD044ProperNames::from_config_struct(config);
2698
2699 let content = "\
2700<!-- vale off -->
2701Some javascript text here.
2702<!-- vale on -->
2703<!-- vale Style.Rule = NO -->
2704More javascript text.
2705<!-- vale Style.Rule = YES -->
2706<!-- vale JavaScript.Grammar = NO -->
2707";
2708 let ctx = create_context(content);
2709 let result = rule.check(&ctx).unwrap();
2710
2711 assert_eq!(result.len(), 2, "Should only flag body lines, not Vale config comments");
2713 assert_eq!(result[0].line, 2);
2714 assert_eq!(result[1].line, 5);
2715 }
2716
2717 #[test]
2718 fn test_remark_lint_inline_config_comments_not_flagged() {
2719 let config = MD044Config {
2720 names: vec!["JavaScript".to_string()],
2721 ..MD044Config::default()
2722 };
2723 let rule = MD044ProperNames::from_config_struct(config);
2724
2725 let content = "\
2726<!-- lint disable remark-lint-some-rule -->
2727Some javascript text here.
2728<!-- lint enable remark-lint-some-rule -->
2729<!-- lint ignore remark-lint-some-rule -->
2730More javascript text.
2731";
2732 let ctx = create_context(content);
2733 let result = rule.check(&ctx).unwrap();
2734
2735 assert_eq!(
2736 result.len(),
2737 2,
2738 "Should only flag body lines, not remark-lint config comments"
2739 );
2740 assert_eq!(result[0].line, 2);
2741 assert_eq!(result[1].line, 5);
2742 }
2743
2744 #[test]
2745 fn test_fix_does_not_modify_vale_remark_lint_comments() {
2746 let config = MD044Config {
2747 names: vec!["JavaScript".to_string(), "Vale".to_string()],
2748 ..MD044Config::default()
2749 };
2750 let rule = MD044ProperNames::from_config_struct(config);
2751
2752 let content = "\
2753<!-- vale off -->
2754Some javascript text.
2755<!-- vale on -->
2756<!-- lint disable remark-lint-some-rule -->
2757More javascript text.
2758<!-- lint enable remark-lint-some-rule -->
2759";
2760 let ctx = create_context(content);
2761 let fixed = rule.fix(&ctx).unwrap();
2762
2763 assert!(fixed.contains("<!-- vale off -->"));
2765 assert!(fixed.contains("<!-- vale on -->"));
2766 assert!(fixed.contains("<!-- lint disable remark-lint-some-rule -->"));
2767 assert!(fixed.contains("<!-- lint enable remark-lint-some-rule -->"));
2768 assert!(fixed.contains("Some JavaScript text."));
2770 assert!(fixed.contains("More JavaScript text."));
2771 }
2772
2773 #[test]
2774 fn test_mixed_tool_directives_all_skipped() {
2775 let config = MD044Config {
2776 names: vec!["JavaScript".to_string(), "Vale".to_string()],
2777 ..MD044Config::default()
2778 };
2779 let rule = MD044ProperNames::from_config_struct(config);
2780
2781 let content = "\
2782<!-- rumdl-disable MD044 -->
2783Some javascript text.
2784<!-- markdownlint-disable -->
2785More javascript text.
2786<!-- vale off -->
2787Even more javascript text.
2788<!-- lint disable some-rule -->
2789Final javascript text.
2790<!-- rumdl-enable MD044 -->
2791<!-- markdownlint-enable -->
2792<!-- vale on -->
2793<!-- lint enable some-rule -->
2794";
2795 let ctx = create_context(content);
2796 let result = rule.check(&ctx).unwrap();
2797
2798 assert_eq!(
2800 result.len(),
2801 4,
2802 "Should only flag body lines, not any tool directive comments"
2803 );
2804 assert_eq!(result[0].line, 2);
2805 assert_eq!(result[1].line, 4);
2806 assert_eq!(result[2].line, 6);
2807 assert_eq!(result[3].line, 8);
2808 }
2809
2810 #[test]
2811 fn test_vale_remark_lint_edge_cases_not_matched() {
2812 let config = MD044Config {
2813 names: vec!["JavaScript".to_string(), "Vale".to_string()],
2814 ..MD044Config::default()
2815 };
2816 let rule = MD044ProperNames::from_config_struct(config);
2817
2818 let content = "\
2826<!-- vale -->
2827<!-- vale is a tool for writing -->
2828<!-- valedictorian javascript -->
2829<!-- linting javascript tips -->
2830<!-- vale javascript -->
2831<!-- lint your javascript code -->
2832";
2833 let ctx = create_context(content);
2834 let result = rule.check(&ctx).unwrap();
2835
2836 assert_eq!(
2843 result.len(),
2844 7,
2845 "Should flag proper names in non-directive HTML comments: got {result:?}"
2846 );
2847 assert_eq!(result[0].line, 1); assert_eq!(result[1].line, 2); assert_eq!(result[2].line, 3); assert_eq!(result[3].line, 4); assert_eq!(result[4].line, 5); assert_eq!(result[5].line, 5); assert_eq!(result[6].line, 6); }
2855
2856 #[test]
2857 fn test_vale_style_directives_skipped() {
2858 let config = MD044Config {
2859 names: vec!["JavaScript".to_string(), "Vale".to_string()],
2860 ..MD044Config::default()
2861 };
2862 let rule = MD044ProperNames::from_config_struct(config);
2863
2864 let content = "\
2866<!-- vale style = MyStyle -->
2867<!-- vale styles = Style1, Style2 -->
2868<!-- vale MyRule.Name = YES -->
2869<!-- vale MyRule.Name = NO -->
2870Some javascript text.
2871";
2872 let ctx = create_context(content);
2873 let result = rule.check(&ctx).unwrap();
2874
2875 assert_eq!(
2877 result.len(),
2878 1,
2879 "Should only flag body lines, not Vale style/rule directives: got {result:?}"
2880 );
2881 assert_eq!(result[0].line, 5);
2882 }
2883
2884 #[test]
2887 fn test_backtick_code_single_backticks() {
2888 let line = "hello `world` bye";
2889 assert!(MD044ProperNames::is_in_backtick_code_in_line(line, 7));
2891 assert!(!MD044ProperNames::is_in_backtick_code_in_line(line, 0));
2893 assert!(!MD044ProperNames::is_in_backtick_code_in_line(line, 14));
2895 }
2896
2897 #[test]
2898 fn test_backtick_code_double_backticks() {
2899 let line = "a ``code`` b";
2900 assert!(MD044ProperNames::is_in_backtick_code_in_line(line, 4));
2902 assert!(!MD044ProperNames::is_in_backtick_code_in_line(line, 0));
2904 assert!(!MD044ProperNames::is_in_backtick_code_in_line(line, 11));
2906 }
2907
2908 #[test]
2909 fn test_backtick_code_unclosed() {
2910 let line = "a `code b";
2911 assert!(!MD044ProperNames::is_in_backtick_code_in_line(line, 3));
2913 }
2914
2915 #[test]
2916 fn test_backtick_code_mismatched_count() {
2917 let line = "a `code`` b";
2919 assert!(!MD044ProperNames::is_in_backtick_code_in_line(line, 3));
2922 }
2923
2924 #[test]
2925 fn test_backtick_code_multiple_spans() {
2926 let line = "`first` and `second`";
2927 assert!(MD044ProperNames::is_in_backtick_code_in_line(line, 1));
2929 assert!(!MD044ProperNames::is_in_backtick_code_in_line(line, 8));
2931 assert!(MD044ProperNames::is_in_backtick_code_in_line(line, 13));
2933 }
2934
2935 #[test]
2936 fn test_backtick_code_on_backtick_boundary() {
2937 let line = "`code`";
2938 assert!(!MD044ProperNames::is_in_backtick_code_in_line(line, 0));
2940 assert!(!MD044ProperNames::is_in_backtick_code_in_line(line, 5));
2942 assert!(MD044ProperNames::is_in_backtick_code_in_line(line, 1));
2944 assert!(MD044ProperNames::is_in_backtick_code_in_line(line, 4));
2945 }
2946
2947 #[test]
2953 fn test_double_bracket_link_url_not_flagged() {
2954 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
2955 let content = "[[rumdl]](https://github.com/rvben/rumdl)";
2957 let ctx = create_context(content);
2958 let result = rule.check(&ctx).unwrap();
2959 assert!(
2960 result.is_empty(),
2961 "URL inside [[text]](url) must not be flagged, got: {result:?}"
2962 );
2963 }
2964
2965 #[test]
2966 fn test_double_bracket_link_url_not_fixed() {
2967 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
2968 let content = "[[rumdl]](https://github.com/rvben/rumdl)\n";
2969 let ctx = create_context(content);
2970 let fixed = rule.fix(&ctx).unwrap();
2971 assert_eq!(
2972 fixed, content,
2973 "fix() must leave the URL inside [[text]](url) unchanged"
2974 );
2975 }
2976
2977 #[test]
2978 fn test_double_bracket_link_text_still_flagged() {
2979 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
2980 let content = "[[github]](https://example.com)";
2982 let ctx = create_context(content);
2983 let result = rule.check(&ctx).unwrap();
2984 assert_eq!(
2985 result.len(),
2986 1,
2987 "Incorrect name in [[text]] link text should still be flagged, got: {result:?}"
2988 );
2989 assert_eq!(result[0].message, "Proper name 'github' should be 'GitHub'");
2990 }
2991
2992 #[test]
2993 fn test_double_bracket_link_mixed_line() {
2994 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
2995 let content = "See [[rumdl]](https://github.com/rvben/rumdl) and github for more.";
2997 let ctx = create_context(content);
2998 let result = rule.check(&ctx).unwrap();
2999 assert_eq!(
3000 result.len(),
3001 1,
3002 "Only the standalone 'github' after the link should be flagged, got: {result:?}"
3003 );
3004 assert!(result[0].message.contains("'github'"));
3005 assert_eq!(
3007 result[0].column, 51,
3008 "Flagged column should be the trailing 'github', not the one in the URL"
3009 );
3010 }
3011
3012 #[test]
3013 fn test_regular_link_url_still_not_flagged() {
3014 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
3016 let content = "[rumdl](https://github.com/rvben/rumdl)";
3017 let ctx = create_context(content);
3018 let result = rule.check(&ctx).unwrap();
3019 assert!(
3020 result.is_empty(),
3021 "URL inside regular [text](url) must still not be flagged, got: {result:?}"
3022 );
3023 }
3024
3025 #[test]
3026 fn test_link_like_text_in_code_span_still_flagged_when_code_blocks_enabled() {
3027 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], true);
3032 let content = "`[foo](https://github.com/org/repo)`";
3033 let ctx = create_context(content);
3034 let result = rule.check(&ctx).unwrap();
3035 assert_eq!(
3036 result.len(),
3037 1,
3038 "Proper name inside a code span must be flagged when code-blocks=true, got: {result:?}"
3039 );
3040 assert!(result[0].message.contains("'github'"));
3041 }
3042
3043 #[test]
3044 fn test_malformed_link_not_treated_as_url() {
3045 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
3048 let content = "See [rumdl](github repo) for details.";
3049 let ctx = create_context(content);
3050 let result = rule.check(&ctx).unwrap();
3051 assert_eq!(
3052 result.len(),
3053 1,
3054 "Name inside malformed [text](url with spaces) must still be flagged, got: {result:?}"
3055 );
3056 assert!(result[0].message.contains("'github'"));
3057 }
3058
3059 #[test]
3060 fn test_wikilink_followed_by_prose_parens_still_flagged() {
3061 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
3065 let content = "[[note]](github repo)";
3066 let ctx = create_context(content);
3067 let result = rule.check(&ctx).unwrap();
3068 assert_eq!(
3069 result.len(),
3070 1,
3071 "Name inside [[wikilink]](prose with spaces) must still be flagged, got: {result:?}"
3072 );
3073 assert!(result[0].message.contains("'github'"));
3074 }
3075
3076 #[test]
3078 fn test_roundtrip_fix_then_check_basic() {
3079 let rule = MD044ProperNames::new(
3080 vec![
3081 "JavaScript".to_string(),
3082 "TypeScript".to_string(),
3083 "Node.js".to_string(),
3084 ],
3085 true,
3086 );
3087 let content = "I love javascript, typescript, and nodejs!";
3088 let ctx = create_context(content);
3089 let fixed = rule.fix(&ctx).unwrap();
3090 let ctx2 = create_context(&fixed);
3091 let warnings = rule.check(&ctx2).unwrap();
3092 assert!(
3093 warnings.is_empty(),
3094 "Re-check after fix should produce zero warnings, got: {warnings:?}"
3095 );
3096 }
3097
3098 #[test]
3100 fn test_roundtrip_fix_then_check_multiline() {
3101 let rule = MD044ProperNames::new(vec!["Rust".to_string(), "Python".to_string()], true);
3102 let content = "First line with rust.\nSecond line with python.\nThird line with RUST and PYTHON.\n";
3103 let ctx = create_context(content);
3104 let fixed = rule.fix(&ctx).unwrap();
3105 let ctx2 = create_context(&fixed);
3106 let warnings = rule.check(&ctx2).unwrap();
3107 assert!(
3108 warnings.is_empty(),
3109 "Re-check after fix should produce zero warnings, got: {warnings:?}"
3110 );
3111 }
3112
3113 #[test]
3115 fn test_roundtrip_fix_then_check_inline_config() {
3116 let config = MD044Config {
3117 names: vec!["RUMDL".to_string()],
3118 ..MD044Config::default()
3119 };
3120 let rule = MD044ProperNames::from_config_struct(config);
3121 let content =
3122 "<!-- rumdl-disable MD044 -->\nSome rumdl text.\n<!-- rumdl-enable MD044 -->\n\nSome rumdl text outside.\n";
3123 let ctx = create_context(content);
3124 let fixed = rule.fix(&ctx).unwrap();
3125 assert!(
3127 fixed.contains("Some rumdl text.\n"),
3128 "Disabled block text should be preserved"
3129 );
3130 assert!(
3131 fixed.contains("Some RUMDL text outside."),
3132 "Outside text should be fixed"
3133 );
3134 }
3135
3136 #[test]
3138 fn test_roundtrip_fix_then_check_html_comments() {
3139 let config = MD044Config {
3140 names: vec!["JavaScript".to_string()],
3141 ..MD044Config::default()
3142 };
3143 let rule = MD044ProperNames::from_config_struct(config);
3144 let content = "# Guide\n\n<!-- javascript mentioned here -->\n\njavascript outside\n";
3145 let ctx = create_context(content);
3146 let fixed = rule.fix(&ctx).unwrap();
3147 let ctx2 = create_context(&fixed);
3148 let warnings = rule.check(&ctx2).unwrap();
3149 assert!(
3150 warnings.is_empty(),
3151 "Re-check after fix should produce zero warnings, got: {warnings:?}"
3152 );
3153 }
3154
3155 #[test]
3157 fn test_roundtrip_no_op_when_correct() {
3158 let rule = MD044ProperNames::new(vec!["JavaScript".to_string(), "TypeScript".to_string()], true);
3159 let content = "This uses JavaScript and TypeScript correctly.\n";
3160 let ctx = create_context(content);
3161 let fixed = rule.fix(&ctx).unwrap();
3162 assert_eq!(fixed, content, "Fix should be a no-op when content is already correct");
3163 }
3164
3165 #[test]
3168 fn test_bare_domain_link_text_not_flagged() {
3169 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
3173 let content = "My site is [ravencentric.github.io](https://ravencentric.github.io).\n";
3174 let ctx = create_context(content);
3175 let result = rule.check(&ctx).unwrap();
3176 assert!(
3177 result.is_empty(),
3178 "Should not flag 'github' in a bare-domain link text that matches the link URL: {result:?}"
3179 );
3180 }
3181
3182 #[test]
3183 fn test_bare_domain_link_text_not_fixed() {
3184 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
3186 let content = "My site is [ravencentric.github.io](https://ravencentric.github.io).\n";
3187 let ctx = create_context(content);
3188 let fixed = rule.fix(&ctx).unwrap();
3189 assert_eq!(
3190 fixed, content,
3191 "fix() must not alter bare-domain link text that matches the destination URL"
3192 );
3193 }
3194
3195 #[test]
3196 fn test_bare_domain_link_text_with_path_not_flagged() {
3197 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
3199 let content = "Visit [ravencentric.github.io](https://ravencentric.github.io/projects).\n";
3200 let ctx = create_context(content);
3201 let result = rule.check(&ctx).unwrap();
3202 assert!(
3203 result.is_empty(),
3204 "Should not flag 'github' when bare-domain text is the hostname of its destination URL: {result:?}"
3205 );
3206 }
3207
3208 #[test]
3209 fn test_bare_domain_link_text_full_path_not_flagged() {
3210 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
3212 let content = "See [ravencentric.github.io/blog](https://ravencentric.github.io/blog).\n";
3213 let ctx = create_context(content);
3214 let result = rule.check(&ctx).unwrap();
3215 assert!(
3216 result.is_empty(),
3217 "Should not flag 'github' when link text is the full URL path without scheme: {result:?}"
3218 );
3219 }
3220
3221 #[test]
3222 fn test_github_product_name_in_link_text_still_flagged() {
3223 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
3226 let content = "Hosted on [github pages](https://pages.github.com).\n";
3227 let ctx = create_context(content);
3228 let result = rule.check(&ctx).unwrap();
3229 assert!(
3230 !result.is_empty(),
3231 "Should still flag 'github' in descriptive link text that does not match the destination URL"
3232 );
3233 }
3234
3235 #[test]
3236 fn test_protocol_relative_bare_domain_link_text_not_flagged() {
3237 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
3239 let content = "See [github.io](//github.io).\n";
3240 let ctx = create_context(content);
3241 let result = rule.check(&ctx).unwrap();
3242 assert!(
3243 result.is_empty(),
3244 "Should not flag 'github' in bare-domain text matching a protocol-relative destination: {result:?}"
3245 );
3246 }
3247
3248 #[test]
3249 fn test_dotted_wikilink_target_still_flagged() {
3250 let rule = MD044ProperNames::new(vec!["Node.js".to_string()], false);
3255 let content = "See [[node.js]] for details.\n";
3256 let ctx = create_context(content);
3257 let result = rule.check(&ctx).unwrap();
3258 assert!(
3259 !result.is_empty(),
3260 "Should flag 'node.js' in a dotted WikiLink target: {result:?}"
3261 );
3262 }
3263
3264 #[test]
3265 fn test_bare_domain_link_text_case_insensitive_url() {
3266 let rule = MD044ProperNames::new(vec!["GitHub".to_string()], false);
3269 let content = "See [github.io](HTTPS://github.io).\n";
3270 let ctx = create_context(content);
3271 let result = rule.check(&ctx).unwrap();
3272 assert!(
3273 result.is_empty(),
3274 "Should not flag bare-domain text when destination URL has an uppercase scheme: {result:?}"
3275 );
3276 }
3277}