-
Notifications
You must be signed in to change notification settings - Fork 910
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent wrapping markdown headers in doc comments
Fixes 5238 A markdown header is defined by a string that starts with `#`. Previously, rustfmt would wrap long markdown headers when `wrap_comments=true`. This lead to issues when rendering these headers in HTML using rustdoc. Now, rustfmt leaves markdown headers alone when wrapping comments.
- Loading branch information
1 parent
12048e4
commit 272fb42
Showing
5 changed files
with
61 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
tests/source/issue-5238/markdown_header_wrap_comments_false.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// rustfmt-wrap_comments: false | ||
|
||
/// no markdown header so rustfmt should wrap this comment when `format_code_in_doc_comments = true` and `wrap_comments = true` | ||
fn not_documented_with_markdown_header() { | ||
// This is just a normal inline comment so rustfmt should wrap this comment when `wrap_comments = true` | ||
} | ||
|
||
/// # We're using a markdown header here so rustfmt should refuse to wrap this comment in all circumstances | ||
fn documented_with_markdown_header() { | ||
// # We're using a markdown header in an inline comment. rustfmt should be able to wrap this comment when `wrap_comments = true` | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/source/issue-5238/markdown_header_wrap_comments_true.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// rustfmt-wrap_comments: true | ||
|
||
/// no markdown header so rustfmt should wrap this comment when `format_code_in_doc_comments = true` and `wrap_comments = true` | ||
fn not_documented_with_markdown_header() { | ||
// This is just a normal inline comment so rustfmt should wrap this comment when `wrap_comments = true` | ||
} | ||
|
||
/// # We're using a markdown header here so rustfmt should refuse to wrap this comment in all circumstances | ||
fn documented_with_markdown_header() { | ||
// # We're using a markdown header in an inline comment. rustfmt should be able to wrap this comment when `wrap_comments = true` | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/target/issue-5238/markdown_header_wrap_comments_false.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// rustfmt-wrap_comments: false | ||
|
||
/// no markdown header so rustfmt should wrap this comment when `format_code_in_doc_comments = true` and `wrap_comments = true` | ||
fn not_documented_with_markdown_header() { | ||
// This is just a normal inline comment so rustfmt should wrap this comment when `wrap_comments = true` | ||
} | ||
|
||
/// # We're using a markdown header here so rustfmt should refuse to wrap this comment in all circumstances | ||
fn documented_with_markdown_header() { | ||
// # We're using a markdown header in an inline comment. rustfmt should be able to wrap this comment when `wrap_comments = true` | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/target/issue-5238/markdown_header_wrap_comments_true.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// rustfmt-wrap_comments: true | ||
|
||
/// no markdown header so rustfmt should wrap this comment when | ||
/// `format_code_in_doc_comments = true` and `wrap_comments = true` | ||
fn not_documented_with_markdown_header() { | ||
// This is just a normal inline comment so rustfmt should wrap this comment | ||
// when `wrap_comments = true` | ||
} | ||
|
||
/// # We're using a markdown header here so rustfmt should refuse to wrap this comment in all circumstances | ||
fn documented_with_markdown_header() { | ||
// # We're using a markdown header in an inline comment. rustfmt should be | ||
// able to wrap this comment when `wrap_comments = true` | ||
} |