X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fcheckstyle.rs;h=169a3741be46860d8de5d02a5f9ecbe87b7c862e;hb=b4b80b6395b6c52d774be04a8ea8ae70b6ac995c;hp=e25bfc03ba449dff59e402da7863120e8dc0d659;hpb=5632831bd17ca662a61af090a12f17461ca5fe05;p=rust.git diff --git a/src/checkstyle.rs b/src/checkstyle.rs index e25bfc03ba4..169a3741be4 100644 --- a/src/checkstyle.rs +++ b/src/checkstyle.rs @@ -1,66 +1,52 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , 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, Read, stdout}; -use config::WriteMode; +use std::io::{self, Write}; +use std::path::Path; +use crate::rustfmt_diff::{DiffLine, Mismatch}; -pub fn output_header(mode: WriteMode) -> Result<(), io::Error> { - let stdout = stdout(); - let mut stdout = stdout.lock(); - 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!(stdout, "{}", 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(mode: WriteMode) -> Result<(), io::Error> { - let stdout = stdout(); - let mut stdout = stdout.lock(); - if mode == WriteMode::Checkstyle { - let mut xml_tail = String::new(); - xml_tail.push_str(""); - try!(write!(stdout, "{}", 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 { - match line { - DiffLine::Expected(ref str) => { - let message = xml_escape_str(&str); - try!(write!(writer, - "", - mismatch.line_number, - message)); - } - _ => { - // Do nothing with context and expected. - } + // Do nothing with `DiffLine::Context` and `DiffLine::Resulting`. + if let DiffLine::Expected(ref str) = line { + let message = xml_escape_str(str); + write!( + writer, + "", + mismatch.line_number, message + )?; } } } - try!(write!(writer, "")); + write!(writer, "")?; Ok(()) }