Skip to content

Commit 2cea364

Browse files
authored
Merge pull request rust-lang#2618 from topecongiro/issue-1174
Output xml header and footer only once
2 parents 55dd8f1 + 8b731db commit 2cea364

File tree

4 files changed

+47
-42
lines changed

4 files changed

+47
-42
lines changed

Cargo.lock

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ env_logger = "0.5"
4646
getopts = "0.2"
4747
derive-new = "0.5"
4848
cargo_metadata = "0.5.1"
49-
rustc-ap-syntax = "91.0.0"
49+
rustc-ap-syntax = "94.0.0"
5050

5151
[dev-dependencies]
5252
lazy_static = "1.0.0"

src/bin/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ use std::{env, error};
2222

2323
use getopts::{Matches, Options};
2424

25+
use rustfmt::checkstyle;
2526
use rustfmt::config::file_lines::FileLines;
2627
use rustfmt::config::{get_toml_path, Color, Config, WriteMode};
2728
use rustfmt::{run, FileName, Input, Summary};
2829

2930
type FmtError = Box<error::Error + Send + Sync>;
3031
type FmtResult<T> = std::result::Result<T, FmtError>;
3132

33+
const WRITE_MODE_LIST: &str = "[replace|overwrite|display|plain|diff|coverage|checkstyle]";
34+
3235
/// Rustfmt operations.
3336
enum Operation {
3437
/// Format files and their child modules.
@@ -87,8 +90,8 @@ impl CliOptions {
8790
options.write_mode = Some(write_mode);
8891
} else {
8992
return Err(FmtError::from(format!(
90-
"Invalid write-mode: {}",
91-
write_mode
93+
"Invalid write-mode: {}, expected one of {}",
94+
write_mode, WRITE_MODE_LIST
9295
)));
9396
}
9497
}
@@ -206,7 +209,7 @@ fn make_opts() -> Options {
206209
"",
207210
"write-mode",
208211
"How to write output (not usable when piping from stdin)",
209-
"[replace|overwrite|display|plain|diff|coverage|checkstyle]",
212+
WRITE_MODE_LIST,
210213
);
211214

212215
opts
@@ -260,7 +263,10 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
260263

261264
let mut error_summary = Summary::default();
262265
if config.version_meets_requirement(&mut error_summary) {
266+
let mut out = &mut stdout();
267+
checkstyle::output_header(&mut out, config.write_mode())?;
263268
error_summary.add(run(Input::Text(input), &config));
269+
checkstyle::output_footer(&mut out, config.write_mode())?;
264270
}
265271

266272
Ok(error_summary)
@@ -294,6 +300,8 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
294300
}
295301
}
296302

303+
let mut out = &mut stdout();
304+
checkstyle::output_header(&mut out, config.write_mode())?;
297305
let mut error_summary = Summary::default();
298306
for file in files {
299307
if !file.exists() {
@@ -327,6 +335,7 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
327335
error_summary.add(run(Input::File(file), &config));
328336
}
329337
}
338+
checkstyle::output_footer(&mut out, config.write_mode())?;
330339

331340
// If we were given a path via dump-minimal-config, output any options
332341
// that were used during formatting as TOML.

src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ use syntax::errors::emitter::{ColorConfig, EmitterWriter};
4646
use syntax::errors::{DiagnosticBuilder, Handler};
4747
use syntax::parse::{self, ParseSess};
4848

49-
use checkstyle::{output_footer, output_header};
5049
use comment::{CharClasses, FullCodeCharKind, LineClasses};
5150
use issues::{BadIssueSeeker, Issue};
5251
use shape::Indent;
@@ -61,7 +60,7 @@ mod utils;
6160

6261
mod attr;
6362
mod chains;
64-
mod checkstyle;
63+
pub mod checkstyle;
6564
mod closures;
6665
pub mod codemap;
6766
mod comment;
@@ -883,11 +882,8 @@ pub enum Input {
883882

884883
pub fn run(input: Input, config: &Config) -> Summary {
885884
let out = &mut stdout();
886-
output_header(out, config.write_mode()).ok();
887885
match format_input(input, config, Some(out)) {
888886
Ok((summary, _, report)) => {
889-
output_footer(out, config.write_mode()).ok();
890-
891887
if report.has_warnings() {
892888
match term::stderr() {
893889
Some(ref t)

0 commit comments

Comments
 (0)