Skip to content

Commit 507030f

Browse files
committed
Run rustfmt on batches of multiple files
1 parent 608c9e8 commit 507030f

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

clippy_dev/src/fmt.rs

+24-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::clippy_project_root;
2+
use itertools::Itertools;
23
use shell_escape::escape;
3-
use std::ffi::OsStr;
4+
use std::ffi::{OsStr, OsString};
45
use std::path::Path;
56
use std::process::{self, Command};
67
use std::{fs, io};
@@ -56,15 +57,22 @@ pub fn run(check: bool, verbose: bool) {
5657
success &= cargo_fmt(context, &project_root.join("rustc_tools_util"))?;
5758
success &= cargo_fmt(context, &project_root.join("lintcheck"))?;
5859

59-
for entry in WalkDir::new(project_root.join("tests")) {
60-
let entry = entry?;
61-
let path = entry.path();
62-
63-
if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" {
64-
continue;
65-
}
66-
67-
success &= rustfmt(context, path)?;
60+
let chunks = WalkDir::new(project_root.join("tests"))
61+
.into_iter()
62+
.filter_map(|entry| {
63+
let entry = entry.expect("failed to find tests");
64+
let path = entry.path();
65+
66+
if path.extension() != Some("rs".as_ref()) || entry.file_name() == "ice-3891.rs" {
67+
None
68+
} else {
69+
Some(entry.into_path().into_os_string())
70+
}
71+
})
72+
.chunks(250);
73+
74+
for chunk in &chunks {
75+
success &= rustfmt(context, chunk)?;
6876
}
6977

7078
Ok(success)
@@ -185,14 +193,14 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
185193
}
186194
}
187195

188-
fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
189-
let mut args = vec![path.as_os_str()];
196+
fn rustfmt(context: &FmtContext, paths: impl Iterator<Item = OsString>) -> Result<bool, CliError> {
197+
let mut args = Vec::new();
190198
if context.check {
191-
args.push("--check".as_ref());
199+
args.push(OsString::from("--check"));
192200
}
201+
args.extend(paths);
202+
193203
let success = exec(context, "rustfmt", std::env::current_dir()?, &args)?;
194-
if !success {
195-
eprintln!("rustfmt failed on {}", path.display());
196-
}
204+
197205
Ok(success)
198206
}

0 commit comments

Comments
 (0)