Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustfmt sometimes breaks lists in doc-comments #4041

Closed
WaffleLapkin opened this issue Feb 8, 2020 · 8 comments · Fixed by #5560
Closed

Rustfmt sometimes breaks lists in doc-comments #4041

WaffleLapkin opened this issue Feb 8, 2020 · 8 comments · Fixed by #5560
Labels
a-comments a-markdown markdown formatting in doc comments good first issue Issues up for grabs, also good candidates for new rustfmt contributors only-with-option requires a non-default option value to reproduce p-low

Comments

@WaffleLapkin
Copy link
Member

Rustfmt breaks sub-list with + (diff from cargo +nightly fmt -- --check --config "wrap_comments=true")

 //! List:
-//! - Sub list:
-//!   + very long #1 blah blah blah blah blah blah blah blah blah blah blah blah
-//!   + very long #2 blah blah blah blah blah blah blah blah blah blah blah blah
+//! - Sub list: + very long #1 blah blah blah blah blah blah blah blah blah blah
+//!   blah blah + very long #2 blah blah blah blah blah blah blah blah blah blah
+//!   blah blah
 //! - ...

Changing + in sublist to - fixes that.

@topecongiro topecongiro added a-comments bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce labels Feb 10, 2020
@ytmimi ytmimi added a-markdown markdown formatting in doc comments p-low good first issue Issues up for grabs, also good candidates for new rustfmt contributors and removed bug Panic, non-idempotency, invalid code, etc. labels Jul 26, 2022
@ytmimi
Copy link
Contributor

ytmimi commented Jul 26, 2022

Confirming I can reproduce this with rustfmt 1.5.1-nightly (a451a39d 2022-07-25). using the following input:

//! List:
//! - Sub list:
//!   + very long #1 blah blah blah blah blah blah blah blah blah blah blah blah
//!   + very long #2 blah blah blah blah blah blah blah blah blah blah blah blah

For anyone wanting to work on this this issue is that we don't consider + the start of an itemized line.

The relevant code can be found here:

rustfmt/src/comment.rs

Lines 433 to 453 in a451a39

/// Block that is formatted as an item.
///
/// An item starts with either a star `*` a dash `-` or a greater-than `>`.
/// Different level of indentation are handled by shrinking the shape accordingly.
struct ItemizedBlock {
/// the lines that are identified as part of an itemized block
lines: Vec<String>,
/// the number of characters (typically whitespaces) up to the item sigil
indent: usize,
/// the string that marks the start of an item
opener: String,
/// sequence of characters (typically whitespaces) to prefix new lines that are part of the item
line_start: String,
}
impl ItemizedBlock {
/// Returns `true` if the line is formatted as an item
fn is_itemized_line(line: &str) -> bool {
let trimmed = line.trim_start();
trimmed.starts_with("* ") || trimmed.starts_with("- ") || trimmed.starts_with("> ")
}

@ytmimi
Copy link
Contributor

ytmimi commented Jul 26, 2022

linking tracking issue for wrap_comments #3347

@thaqibm
Copy link
Contributor

thaqibm commented Oct 11, 2022

Maybe I can help this!

@ytmimi
Copy link
Contributor

ytmimi commented Oct 11, 2022

@thaqib0437, that's great news! feel free to reach out if you have any questions

@thaqibm
Copy link
Contributor

thaqibm commented Oct 11, 2022

Is there a guide on building, testing my changes with custom inputs, and adding teat cases?

@ytmimi
Copy link
Contributor

ytmimi commented Oct 11, 2022

@thaqib0437 check out the Create Test Cases section of the contributing guide. Running cargo build is all you need to do in order to build rustfmt locally?

@thaqibm
Copy link
Contributor

thaqibm commented Oct 11, 2022

Trying to add a test case but its not running with warp_comments=true
test file:

//  rustfmt-wrap_comments=true
//! List:
//! - Sub list:
//!   + very long #1 blah blah blah blah blah blah blah blah blah blah blah blah
//!   + very long #2 blah blah blah blah blah blah blah blah blah blah blah blah

@thaqibm
Copy link
Contributor

thaqibm commented Oct 11, 2022

Created a PR
#5560

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-comments a-markdown markdown formatting in doc comments good first issue Issues up for grabs, also good candidates for new rustfmt contributors only-with-option requires a non-default option value to reproduce p-low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants