Skip to content

Commit 12a5070

Browse files
committed
AI review suggestions
1 parent b9b4ec8 commit 12a5070

File tree

1 file changed

+10
-9
lines changed
  • cpp-linter/src/clang_tools

1 file changed

+10
-9
lines changed

cpp-linter/src/clang_tools/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ async fn analyze_single_file(
148148
if clang_params
149149
.format_filter
150150
.as_ref()
151-
.is_some_and(|f| f.is_source_or_ignored(file_name.as_path()))
152-
|| clang_params.format_filter.is_none()
151+
.is_none_or(|f| f.is_source_or_ignored(file_name.as_path()))
153152
{
154153
let format_result = run_clang_format(&file, &clang_params).await?;
155154
logs.extend(format_result);
@@ -167,8 +166,7 @@ async fn analyze_single_file(
167166
if clang_params
168167
.tidy_filter
169168
.as_ref()
170-
.is_some_and(|f| f.is_source_or_ignored(file_name.as_path()))
171-
|| clang_params.tidy_filter.is_none()
169+
.is_none_or(|f| f.is_source_or_ignored(file_name.as_path()))
172170
{
173171
let tidy_result = run_clang_tidy(&file, &clang_params).await?;
174172
logs.extend(tidy_result);
@@ -182,11 +180,11 @@ async fn analyze_single_file(
182180
));
183181
}
184182
}
185-
Ok((file_name.clone(), logs))
183+
Ok((file_name, logs))
186184
}
187185

188186
/// A struct to contain the version numbers of the clang-tools used
189-
#[derive(Default)]
187+
#[derive(Debug, Default)]
190188
pub struct ClangVersions {
191189
/// The clang-format version used.
192190
pub format_version: Option<String>,
@@ -200,7 +198,7 @@ pub struct ClangVersions {
200198
/// If `tidy_checks` is `"-*"` then clang-tidy is not executed.
201199
/// If `style` is a blank string (`""`), then clang-format is not executed.
202200
pub async fn capture_clang_tools_output(
203-
files: &Vec<Arc<Mutex<FileObj>>>,
201+
files: &[Arc<Mutex<FileObj>>],
204202
version: &RequestedVersion,
205203
clang_params: &mut ClangParams,
206204
rest_api_client: &impl RestApiClient,
@@ -241,14 +239,17 @@ pub async fn capture_clang_tools_output(
241239
};
242240

243241
let mut executors = JoinSet::new();
242+
let arc_params = Arc::new(clang_params.clone());
244243
// iterate over the discovered files and run the clang tools
245244
for file in files {
246-
let arc_params = Arc::new(clang_params.clone());
247245
let arc_file = Arc::clone(file);
248-
executors.spawn(analyze_single_file(arc_file, arc_params));
246+
executors.spawn(analyze_single_file(arc_file, arc_params.clone()));
249247
}
250248

251249
while let Some(output) = executors.join_next().await {
250+
// output?? acts as a fast-fail for any error encountered.
251+
// This includes any `spawn()` error and any `analyze_single_file(`) Result.
252+
// Any unresolved tasks are aborted and dropped when an error is returned here.
252253
let (file_name, logs) = output??;
253254
rest_api_client.start_log_group(format!("Analyzing {}", file_name.to_string_lossy()));
254255
for (level, msg) in logs {

0 commit comments

Comments
 (0)