Skip to content

New disable_all_formatting config option #1297

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

Merged
merged 2 commits into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ macro_rules! create_config {

create_config! {
verbose: bool, false, "Use verbose output";
disable_all_formatting: bool, false, "Don't reformat anything";
skip_children: bool, false, "Don't reformat out of line modules";
file_lines: FileLines, FileLines::all(),
"Lines to format; this is not supported in rustfmt.toml, and can only be specified \
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

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

return Ok((FileMap::new(), false));
}

let mut result = FileMap::new();
// diff mode: check if any files are differing
let mut has_diff = false;
Expand Down
4 changes: 4 additions & 0 deletions tests/source/disable_all_formatting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// rustfmt-disable_all_formatting: true
Copy link
Member

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.

Copy link
Contributor Author

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.

// Don't format anything.

fn main() { println!("This should not be formatted."); }