diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index c795d529409..a8a19d96bc7 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -90,7 +90,7 @@ fn execute() -> i32 { opts.optopt("", "write-mode", "mode to write in (not usable when piping from stdin)", - "[replace|overwrite|display|diff|coverage]"); + "[replace|overwrite|display|diff|coverage|checkstyle]"); opts.optflag("", "skip-children", "don't reformat child modules"); opts.optflag("", diff --git a/src/config.rs b/src/config.rs index 4576ecc5d2a..5b6a5e05cf5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -136,6 +136,8 @@ configuration_option_enum! { WriteMode: Coverage, // Unfancy stdout Plain, + // Output a checkstyle XML file. + Checkstyle, } // This trait and the following impl blocks are there so that we an use diff --git a/src/filemap.rs b/src/filemap.rs index b518eaaa344..b22ca7b9b80 100644 --- a/src/filemap.rs +++ b/src/filemap.rs @@ -38,6 +38,7 @@ pub fn write_all_files(file_map: &FileMap, try!(write_file(&file_map[filename], filename, mode, config)); } + // Output trailers for write mode. Ok(()) } @@ -142,6 +143,19 @@ pub fn write_file(text: &StringBuffer, WriteMode::Default => { unreachable!("The WriteMode should NEVER Be default at this point!"); } + WriteMode::Checkstyle => { + // Generate the diff for the current file. + // Output the XML tags for the lines that are different. + // Use the new text as 'should be X'. + } + WriteMode::Return => { + // io::Write is not implemented for String, working around with + // Vec + let mut v = Vec::new(); + try!(write_system_newlines(&mut v, text, config)); + // won't panic, we are writing correct utf8 + return Ok(Some(String::from_utf8(v).unwrap())); + } } Ok(None)