Skip to content

Commit 65fb703

Browse files
authored
Rollup merge of #106263 - chenyukang:yukang/fix-106261-formater, r=jyn514
Formatter should not try to format non-Rust files Fixes #106261
2 parents caa33bf + 7ebcc78 commit 65fb703

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/bootstrap/format.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ fn update_rustfmt_version(build: &Builder<'_>) {
7474
t!(std::fs::write(stamp_file, version))
7575
}
7676

77-
/// Returns the files modified between the `merge-base` of HEAD and
77+
/// Returns the Rust files modified between the `merge-base` of HEAD and
7878
/// rust-lang/master and what is now on the disk.
7979
///
8080
/// Returns `None` if all files should be formatted.
81-
fn get_modified_files(build: &Builder<'_>) -> Option<Vec<String>> {
81+
fn get_modified_rs_files(build: &Builder<'_>) -> Option<Vec<String>> {
8282
let Ok(remote) = get_rust_lang_rust_remote() else {return None;};
8383
if !verify_rustfmt_version(build) {
8484
return None;
@@ -95,6 +95,7 @@ fn get_modified_files(build: &Builder<'_>) -> Option<Vec<String>> {
9595
)
9696
.lines()
9797
.map(|s| s.trim().to_owned())
98+
.filter(|f| Path::new(f).extension().map_or(false, |ext| ext == "rs"))
9899
.collect(),
99100
)
100101
}
@@ -195,7 +196,7 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
195196
ignore_fmt.add(&format!("!/{}", untracked_path)).expect(&untracked_path);
196197
}
197198
if !check && paths.is_empty() {
198-
if let Some(files) = get_modified_files(build) {
199+
if let Some(files) = get_modified_rs_files(build) {
199200
for file in files {
200201
println!("formatting modified file {file}");
201202
ignore_fmt.add(&format!("/{file}")).expect(&file);

0 commit comments

Comments
 (0)