Skip to content

Commit

Permalink
Don't treat lines starting with . or ) as ordered markdown lists (#…
Browse files Browse the repository at this point in the history
…5839)

Fixes 5835

Ordered markdown lists start with 0-9 digits followed by a `.` or a `)`.
Now, rustfmt ensure that the `.` or `)` is only preceded by numeric
characters before deciding that it's reached an `ItemizedBlock`
  • Loading branch information
xxchan committed Aug 29, 2023
1 parent df2471b commit f89cd3c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ impl ItemizedBlock {
// allowed.
for suffix in [". ", ") "] {
if let Some((prefix, _)) = trimmed.split_once(suffix) {
if prefix.len() <= 2 && prefix.chars().all(|c| char::is_ascii_digit(&c)) {
let has_leading_digits = (1..=2).contains(&prefix.len())
&& prefix.chars().all(|c| char::is_ascii_digit(&c));
if has_leading_digits {
return Some(prefix.len() + suffix.len());
}
}
Expand Down Expand Up @@ -2126,6 +2128,9 @@ fn main() {
// https://spec.commonmark.org/0.30 says: "A start number may not be negative":
"-1. Not a list item.",
"-1 Not a list item.",
// Marker without prefix are not recognized as item markers:
". Not a list item.",
") Not a list item.",
];
for line in test_inputs.iter() {
let maybe_block = ItemizedBlock::new(line);
Expand Down
8 changes: 8 additions & 0 deletions tests/source/issue-5835.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// rustfmt-wrap_comments: true

/// . a
pub fn foo() {}

pub fn main() {
// . a
}
8 changes: 8 additions & 0 deletions tests/target/issue-5835.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// rustfmt-wrap_comments: true

/// . a
pub fn foo() {}

pub fn main() {
// . a
}

0 comments on commit f89cd3c

Please sign in to comment.