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

It should be possible to run rustfmt _only_ on doc comments #5345

Closed
Manishearth opened this issue May 20, 2022 · 9 comments
Closed

It should be possible to run rustfmt _only_ on doc comments #5345

Manishearth opened this issue May 20, 2022 · 9 comments

Comments

@Manishearth
Copy link
Member

There's a new format_code_in_doc_comments config which is quite useful and nice.

However, it formats the entire codebase, including non-doc comment code. This can cause challenges since it's quite likely folks may want a separate set of configs for doc comments: chief of which would be line length restrictions. Rustdoc renders code blocks with a pretty large font and typically the code is written with far more wrapping.

It would be nice to be able to run rustfmt twice, once for regular code, once for doc comments, with different settings, perhaps with a format_code_in_doc_comments_only flag.

@calebcartwright
Copy link
Member

This feels a bit like a particular solution to a problem that I'm not sure I fully understand even after glancing through the comments on the upstream PR.

Was the motivating scenario a desire to use a different/shorter width limit for code in doc comments, independent of the overall max_width and comment_width?

@Manishearth
Copy link
Member Author

Was the motivating scenario a desire to use a different/shorter width limit for code in doc comments, independent of the overall max_width and comment_width?

Yes, because, as I said, rustdoc renders code with a pretty large font (this is good), and it tends to need much shorter line length restrictions. Most docs i've encountered in the wild manually wrap to a much shorter limit because of this, and now that rustfmt supports formatting doc comments it feels like we should perhaps support that automatically too?

@calebcartwright
Copy link
Member

Thanks for confirming and clarifying. Though technically possible, I don't think it's going to be practical to try to go down the path of an entirely separate, doc comment only formatting mode (I can elaborate if need be).

What would be more straightforward is a new option that allows for controlling the width limit of code blocks separate from the other two options so that a shorter width limit could be set explicitly for those code blocks, e.g. a new doc_comment_code_block_width option or something more succinctly named.

Do you feel like that would provide a sufficient resolution to the need to be able to force wrapping more aggressively in doc code blocks?

@Manishearth
Copy link
Member Author

I think so, yes! I don't think the general feature is as necessary

@calebcartwright
Copy link
Member

Have opened #5359 to track implementation of the discussed option, will keep this separate and open as the articulation of the problem-to-be-solved. Will revisit once the option is available to confirm it will suffice, and close this if so.

@ytmimi
Copy link
Contributor

ytmimi commented Jun 28, 2022

doc_comment_code_block_width was added in the v1.5.1 release, and should be available on nightly now!

@ytmimi ytmimi closed this as completed Jun 28, 2022
@calebcartwright
Copy link
Member

calebcartwright commented Jun 28, 2022

Thanks for triaging all these issues Yacin! However, going to reopen this actually to give the team time to test drive the solution and see whether it actually allows them to address the original problem.

Let us know if/how it's working out for you Manish

@Manishearth
Copy link
Member Author

Thanks!

@Manishearth
Copy link
Member Author

It works pretty nicely! Setting it to 80 seems quite ideal for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants