X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fcheckstyle.rs;h=e252e71f8298482cc592a0215939d0982f3ef86e;hb=3f6ea7788b5c65c00e995d04622533554a13dd38;hp=3fc117904c718ebf3cd2bdc716e2b0bf993bf9df;hpb=c9819ceda2b87a481ba08e045f73bfade915b41d;p=rust.git diff --git a/src/checkstyle.rs b/src/checkstyle.rs index 3fc117904c7..e252e71f829 100644 --- a/src/checkstyle.rs +++ b/src/checkstyle.rs @@ -7,56 +7,56 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -use rustfmt_diff::{Mismatch, DiffLine}; + use std::io::{self, Write}; -use config::WriteMode; +use std::path::Path; +use rustfmt_diff::{DiffLine, Mismatch}; -pub fn output_header(out: &mut T, mode: WriteMode) -> Result<(), io::Error> - where T: Write -{ - if mode == WriteMode::Checkstyle { - let mut xml_heading = String::new(); - xml_heading.push_str(""); - xml_heading.push_str("\n"); - xml_heading.push_str(""); - try!(write!(out, "{}", xml_heading)); - } - Ok(()) +/// The checkstyle header - should be emitted before the output of Rustfmt. +/// +/// Note that emitting checkstyle output is not stable and may removed in a +/// future version of Rustfmt. +pub fn header() -> String { + let mut xml_heading = String::new(); + xml_heading.push_str(""); + xml_heading.push_str("\n"); + xml_heading.push_str(""); + xml_heading } -pub fn output_footer(out: &mut T, mode: WriteMode) -> Result<(), io::Error> - where T: Write -{ - if mode == WriteMode::Checkstyle { - let mut xml_tail = String::new(); - xml_tail.push_str(""); - try!(write!(out, "{}", xml_tail)); - } - Ok(()) +/// The checkstyle footer - should be emitted after the output of Rustfmt. +/// +/// Note that emitting checkstyle output is not stable and may removed in a +/// future version of Rustfmt. +pub fn footer() -> String { + "\n".to_owned() } -pub fn output_checkstyle_file(mut writer: T, - filename: &str, - diff: Vec) - -> Result<(), io::Error> - where T: Write +pub fn output_checkstyle_file( + mut writer: T, + filename: &Path, + diff: Vec, +) -> Result<(), io::Error> +where + T: Write, { - try!(write!(writer, "", filename)); + write!(writer, "", filename.display())?; for mismatch in diff { for line in mismatch.lines { // Do nothing with `DiffLine::Context` and `DiffLine::Resulting`. if let DiffLine::Expected(ref str) = line { let message = xml_escape_str(str); - try!(write!(writer, - "", - mismatch.line_number, - message)); + write!( + writer, + "", + mismatch.line_number, message + )?; } } } - try!(write!(writer, "")); + write!(writer, "")?; Ok(()) }