From fbc03b5add9e38c16b5122fe062a726dd4d68973 Mon Sep 17 00:00:00 2001 From: "Craig M. Brandenburg" Date: Sat, 4 Feb 2017 05:54:47 -0700 Subject: [PATCH 1/2] New `disable_all_formatting` config option --- src/config.rs | 1 + src/lib.rs | 4 ++++ tests/source/disable_all_formatting.rs | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 tests/source/disable_all_formatting.rs diff --git a/src/config.rs b/src/config.rs index f5d563197c3..508b569232b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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 \ diff --git a/src/lib.rs b/src/lib.rs index 3caeaf92ebb..ddf8ce95ee3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -339,6 +339,10 @@ fn format_ast(krate: &ast::Crate, -> Result<(FileMap, bool), io::Error> where F: FnMut(&str, &mut StringBuffer) -> Result { + if config.disable_all_formatting { + return Ok((FileMap::new(), false)); + } + let mut result = FileMap::new(); // diff mode: check if any files are differing let mut has_diff = false; diff --git a/tests/source/disable_all_formatting.rs b/tests/source/disable_all_formatting.rs new file mode 100644 index 00000000000..ef7e4ee9362 --- /dev/null +++ b/tests/source/disable_all_formatting.rs @@ -0,0 +1,4 @@ +// rustfmt-disable_all_formatting: true +// Don't format anything. + +fn main() { println!("This should not be formatted."); } From 0e14b1754975637b06d6fa32947531aebe083f34 Mon Sep 17 00:00:00 2001 From: "Craig M. Brandenburg" Date: Mon, 6 Feb 2017 20:45:06 -0700 Subject: [PATCH 2/2] Resolve code review comments --- src/lib.rs | 7 +++---- tests/{source => target}/disable_all_formatting.rs | 0 2 files changed, 3 insertions(+), 4 deletions(-) rename tests/{source => target}/disable_all_formatting.rs (100%) diff --git a/src/lib.rs b/src/lib.rs index ddf8ce95ee3..abe9a6e8554 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -339,10 +339,6 @@ fn format_ast(krate: &ast::Crate, -> Result<(FileMap, bool), io::Error> where F: FnMut(&str, &mut StringBuffer) -> Result { - if config.disable_all_formatting { - return Ok((FileMap::new(), false)); - } - let mut result = FileMap::new(); // diff mode: check if any files are differing let mut has_diff = false; @@ -477,6 +473,9 @@ pub fn format_input(input: Input, mut out: Option<&mut T>) -> Result<(Summary, FileMap, FormatReport), (io::Error, Summary)> { let mut summary = Summary::new(); + if config.disable_all_formatting { + return Ok((summary, FileMap::new(), FormatReport::new())); + } let codemap = Rc::new(CodeMap::new()); let tty_handler = diff --git a/tests/source/disable_all_formatting.rs b/tests/target/disable_all_formatting.rs similarity index 100% rename from tests/source/disable_all_formatting.rs rename to tests/target/disable_all_formatting.rs