From f2c867d067eac285201e53672dcc5e42c2065785 Mon Sep 17 00:00:00 2001 From: "Craig M. Brandenburg" Date: Mon, 6 Feb 2017 21:11:47 -0700 Subject: [PATCH] New `disable_all_formatting` config option (#1297) * New `disable_all_formatting` config option * Resolve code review comments --- src/config.rs | 1 + src/lib.rs | 3 +++ tests/target/disable_all_formatting.rs | 4 ++++ 3 files changed, 8 insertions(+) create mode 100644 tests/target/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..abe9a6e8554 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -473,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/target/disable_all_formatting.rs b/tests/target/disable_all_formatting.rs new file mode 100644 index 00000000000..ef7e4ee9362 --- /dev/null +++ b/tests/target/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."); }