-
Notifications
You must be signed in to change notification settings - Fork 900
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
[Feature Request] Add mechanism to skip formatting specific comments #5727
Comments
The only way I can think of for supporting this is something along the lines of what I mentioned in #5440 (comment) Basically, we establish some kind of marker/keyword/magic phrase/whatever that rustfmt will recognize and support, and if found in the supported position (or positions, not sure) then rustfmt will do nothing. I suggested |
My thoughts, for doc comments at least, is that the marker should be an HTML comment so it won't mess with rustdoc output. We could define something like this: const SKIP_DOC_COMMENT_MARKER: &'static str = "<!--- rustfmt::skip --->" There's probably more scenarios that we'd need to think through, but I also wonder if we'd need to handle the case where users want to prevent rustfmt from modifying their markdown, but also want to continue formatting their code blocks. The way I've defined it in my proof of concept branch is to skip the doc comment entirely if the marker is present. |
I don't have an opinion or preference one way or the other about the specifics of the marker approach. As long as it works and is practical in any and all comment types I'd be content |
I'll think on this a little more. I like the idea of keeping with |
rustfmt usually leaves comments alone, but will edit comments when
wrap_comments=true
is enabled, Additionally rustfmt sometimes removes leading / trailing spaces. However, in some cases its desirable to prevent modifications for specific comments. The#[rustfmt::skip]
attribute exists to prevent rustfmt from modifying annotated code, and although this will sometimes prevent comments from being modified it's not ideal because it also prevents the code from being formatted.Related Issues where modifying comments isn't desirable:
rustfmt_skip
can't properly preventwrap_comments
from formatting a specific comment #5725If anyone has ideas for how this mechanism could work please comment them down bellow.
The text was updated successfully, but these errors were encountered: