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."); }