From 5d81b4580d461d409ddf3ccb3530fafa90e2609f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 20 Oct 2026 17:11:39 +0000 Subject: [PATCH 1/2] Respect gen_patch when caching clang-format fixes Co-authored-by: 2bndy5 <14963867+2bndy5@users.noreply.github.com> --- cpp-linter/src/clang_tools/clang_format.rs | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/cpp-linter/src/clang_tools/clang_format.rs b/cpp-linter/src/clang_tools/clang_format.rs index 5845a9d5..70a1dc4d 100644 --- a/cpp-linter/src/clang_tools/clang_format.rs +++ b/cpp-linter/src/clang_tools/clang_format.rs @@ -186,20 +186,22 @@ pub fn run_clang_format( } else { // clang-tidy was not run on this file, // so just use the clang-format fixes as the patched content. - let cache_format_fixes = cache_path.join(&file.name); - fs::create_dir_all( - cache_format_fixes - .parent() - .ok_or(ClangCaptureError::UnknownCacheParentPath)?, - ) - .map_err(ClangCaptureError::MkDirFailed)?; - fs::write(&cache_format_fixes, &output.stdout).map_err(|e| { - ClangCaptureError::WriteFileFailed { - file_name: cache_format_fixes.to_string_lossy().to_string(), - source: e, - } - })?; - file.patched_path = Some(cache_format_fixes); + if clang_params.gen_patch { + let cache_format_fixes = cache_path.join(&file.name); + fs::create_dir_all( + cache_format_fixes + .parent() + .ok_or(ClangCaptureError::UnknownCacheParentPath)?, + ) + .map_err(ClangCaptureError::MkDirFailed)?; + fs::write(&cache_format_fixes, &output.stdout).map_err(|e| { + ClangCaptureError::WriteFileFailed { + file_name: cache_format_fixes.to_string_lossy().to_string(), + source: e, + } + })?; + file.patched_path = Some(cache_format_fixes); + } } file.format_advice = Some(format_advice); @@ -459,7 +461,8 @@ mod tests { fn no_gen_patch() { let tmp_workspace = setup_tmp_workspace(); let tools_dir = tempfile::tempdir().unwrap(); - let fake_format = make_fake_tool(tools_dir.path(), "clang-format", "echo 'void main() {}'"); + let fake_format = + make_fake_tool(tools_dir.path(), "clang-format", "echo 'void main() {}'"); let mut clang_params = make_clang_params(tmp_workspace.path(), fake_format); clang_params.gen_patch = false; let file = Mutex::new(FileObj::new(PathBuf::from("demo/demo.cpp"))); From 274e9a8e131fcaa7854cdaf36ecd64ad4d94879c Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Tue, 20 Oct 2026 16:03:43 -0700 Subject: [PATCH 2/2] fix a couple tests `clang_params.gen_patch ` needed to be `true` but is `false` by default --- cpp-linter/src/clang_tools/clang_format.rs | 3 ++- cpp-linter/src/clang_tools/clang_tidy/test.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp-linter/src/clang_tools/clang_format.rs b/cpp-linter/src/clang_tools/clang_format.rs index 70a1dc4d..64051b33 100644 --- a/cpp-linter/src/clang_tools/clang_format.rs +++ b/cpp-linter/src/clang_tools/clang_format.rs @@ -449,7 +449,8 @@ mod tests { let tmp_workspace = setup_tmp_workspace(); let tools_dir = tempfile::tempdir().unwrap(); let fake_format = make_fake_tool(tools_dir.path(), "clang-format", ""); - let clang_params = make_clang_params(tmp_workspace.path(), fake_format); + let mut clang_params = make_clang_params(tmp_workspace.path(), fake_format); + clang_params.gen_patch = true; // a directory where the patched file should be cached fs::create_dir_all(clang_params.get_cache_path().join("demo/demo.cpp")).unwrap(); let file = Mutex::new(FileObj::new(PathBuf::from("demo/demo.cpp"))); diff --git a/cpp-linter/src/clang_tools/clang_tidy/test.rs b/cpp-linter/src/clang_tools/clang_tidy/test.rs index 2bfa5e9a..7c51d1f6 100644 --- a/cpp-linter/src/clang_tools/clang_tidy/test.rs +++ b/cpp-linter/src/clang_tools/clang_tidy/test.rs @@ -379,7 +379,8 @@ fn tidy_cache_not_writable() { let tmp_workspace = crate::test_common::setup_tmp_workspace(); let tools_dir = tempfile::tempdir().unwrap(); let fake_tidy = crate::test_common::make_fake_tool(tools_dir.path(), "clang-tidy", ""); - let clang_params = make_clang_params(tmp_workspace.path(), Some(fake_tidy)); + let mut clang_params = make_clang_params(tmp_workspace.path(), Some(fake_tidy)); + clang_params.gen_patch = true; // a directory where the patched file should be cached fs::create_dir_all(clang_params.get_cache_path().join("demo/demo.cpp")).unwrap(); let file = Mutex::new(FileObj::new(PathBuf::from("demo/demo.cpp")));