Skip to content

Commit 72ca727

Browse files
committed
Run rustfmt on batches of multiple files
1 parent 610b381 commit 72ca727

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

clippy_dev/src/fmt.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::clippy_project_root;
22
use shell_escape::escape;
33
use std::ffi::OsStr;
4-
use std::path::Path;
4+
use std::path::{Path, PathBuf};
55
use std::process::{self, Command};
66
use std::{fs, io};
77
use walkdir::WalkDir;
@@ -56,6 +56,7 @@ pub fn run(check: bool, verbose: bool) {
5656
success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?;
5757
success &= cargo_fmt(context, &project_root.join("lintcheck"))?;
5858

59+
let mut paths = Vec::new();
5960
for entry in WalkDir::new(project_root.join("tests")) {
6061
let entry = entry?;
6162
let path = entry.path();
@@ -64,7 +65,11 @@ pub fn run(check: bool, verbose: bool) {
6465
continue;
6566
}
6667

67-
success &= rustfmt(context, path)?;
68+
paths.push(entry.into_path());
69+
}
70+
71+
for chunk in paths.chunks(250) {
72+
success &= rustfmt(context, chunk)?;
6873
}
6974

7075
Ok(success)
@@ -185,14 +190,14 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
185190
}
186191
}
187192

188-
fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
189-
let mut args = vec![path.as_os_str()];
193+
fn rustfmt(context: &FmtContext, paths: &[PathBuf]) -> Result<bool, CliError> {
194+
let mut args = Vec::new();
190195
if context.check {
191196
args.push("--check".as_ref());
192197
}
198+
args.extend(paths.iter().map(|path| path.as_os_str()));
199+
193200
let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?;
194-
if !success {
195-
eprintln!("rustfmt failed on {}", path.display());
196-
}
201+
197202
Ok(success)
198203
}

0 commit comments

Comments
 (0)