-
Notifications
You must be signed in to change notification settings - Fork 889
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
New disable_all_formatting
config option
#1297
New disable_all_formatting
config option
#1297
Conversation
At the risk of piling onto this one, I just wanted to say that I've run into this problem a few times now, and was mildly astonished that no current resolution exists. I've enabled Rust.vim with The proper course of action is probably to convince the project owner to support rustfmt, but it'd be nice to have an escape hatch to temporarily avoid having to shave that yak by just creating a local Onto the color of the shed: the naming of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Seems like a good idea to add this, although it does seem to be working around a deficiency in the editor, which is a bit of a shame. A couple of comments need to be addressed before landing, but the strategy is good.
@@ -0,0 +1,4 @@ | |||
// rustfmt-disable_all_formatting: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test doesn't do anything because there is not corresponding file in tests/target. However, since you only want to do an idempotent test, you could move it to tests/target and it would be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I misread the Contributing.md instructions and put the file in the wrong directory.
Creating a test is as easy as creating a new file in ./tests/source/ and an equally named one in ./tests/target/. If it is only required that rustfmt leaves a piece of code unformatted, it may suffice to only create a target file.
src/lib.rs
Outdated
@@ -339,6 +339,10 @@ fn format_ast<F>(krate: &ast::Crate, | |||
-> Result<(FileMap, bool), io::Error> | |||
where F: FnMut(&str, &mut StringBuffer) -> Result<bool, io::Error> | |||
{ | |||
if config.disable_all_formatting { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want this check in the caller, rather than here, since there might be line-based reformating as well as AST-based reformatting
Does anyone else have an opinion about the config option name? @brandur recommends shortening it from |
Thanks for the changes! I don't think either name for the option is ideal, but I can't think of a better one. |
FWIW, I don't feel too strongly about it either. If no one feels too strongly one way or the other, I'd defer to the author of the patch. |
This pull request adds a new Boolean configuration option called
disable_all_formatting
, which causesrustfmt
to skip all formatting in all files.This option could be useful for someone who:
rustfmt
when saving a Rust source file, and,rustfmt
.Currently, in that scenario, the programmer will often inadvertently format lots of Rust code—even code unrelated to what the programmer is working on. The programmer must then undo all the formatting changes while keeping their intended changes.
Whereas, with the new
disable_all_formatting
option, the programmer can drop this.rustfmt.toml
into the project's top-level directory and avoid formatting unrelated sections of code.