rustfmt
rustfmt copied to clipboard
`doc_comment_code_block_width ` doesn't work in inner comments
Code blocks in a //! doc comment don't seem to be formatted.
mod foo {
//! ```
//! horribly .formatted(code
//! );
//! ```
}
This is on nightly 2022-07-19 and on an older one as well.
Please update the issue description with a valid, minimal snippet that reproduces the behavior you are describing, along with relevant details like the version of rustfmt you are using and your config file
@robertbastian I think we still need more context in order to figure out what's going on. Could you please provide a complete snippet where you're experiencing this problem.
Also as @calebcartwright mentioned having the version of rustfmt and any relevant configuration options your using besides format_code_in_doc_comments is really important for us to reproduce the issue.
Updated
Thank you for updating, but I'm unable to reproduce using rustfmt from source, the latest nightly, nor even stable for that matter. There haven't been any released changes to rustfmt in the last ~2 weeks either so I don't think the latest nightly 7-21 vs 7-19 will make a difference.
Are you sure that nightly rustfmt is being invoked, and that format_code_in_doc_comments is set to true? How are you executing rustfmt, are you running rustfmt ... directly, running cargo fmt, using an editor, etc. ?
$ rustfmt +nightly --version
rustfmt 1.5.1-nightly (62b272d 2022-07-21)
$ rustfmt +nightly lib.rs --check --config format_code_in_doc_comments=true
Diff in /......................../lib.rs at line 1:
mod foo {
- //! ```
- //! horribly .formatted(code
- //! );
- //! ```
+ //! ```
+ //! horribly.formatted(code);
+ //! ```
}
Oh sorry I don't seem to have invoked rustfmt correctly. rustfmt +nightly --config format_code_in_doc_comments=true,doc_comment_code_block_width=80 provider/adapters/src/fallback/mod.rs doesn't work with the file at https://github.com/unicode-org/icu4x/blob/583de584f0ba1cfe3402915989f57aa586c0ca06/provider/adapters/src/fallback/mod.rs. The inner doc comment has a line that's too long, and also if you mess with any other formatting it fails. Without the max_length flag it works though.
if you mess with any other formatting it fails.
Could you elaborate a little more on what you types of formatting you tried messing with?
Without the
max_lengthflag it works though.
Are you saying that doc_comment_code_block_width=80 is causing the issue for you? and that running the command without it works?
I introduced a space in some foo .to_string() call (below the line that is too long) that didn't get fixed. Without the doc_comment_code_block_width=80 it does get fixed.
Alright, I'll try to take a look into this at some point. For now going to link the tracking issues for doc_comment_code_block_width #5415