Skip to content

Commit 89f7b3d

Browse files
authored
fix: pass --extra-args to clang-tidy properly (#386)
1. The conversion function was not being used in production code. 2. clang-tidy was finding the `--extra-arg` value as an unrecognized option. Prefer using `--extra-arg=...` instead. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Modified extra argument handling format for clang-tidy invocations. * Updated argument processing logic. * **Tests** * Updated test assertions to match new argument formatting. * Added debug logging for parsed arguments. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 1f563bb commit 89f7b3d

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

cpp-linter/src/clang_tools/clang_tidy.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ pub fn run_clang_tidy(
294294
cmd.args(["-p", &db.to_string_lossy()]);
295295
}
296296
for arg in &clang_params.extra_args {
297-
cmd.args(["--extra-arg", format!("\"{}\"", arg).as_str()]);
297+
// Use `--extra-arg=...` syntax to prevent values getting
298+
// interpreted as a clang-tidy options.
299+
// At this point, values should already be split by
300+
// whitespace in `ClangParams::from(&cli)` via
301+
// `crate::cli::convert_extra_arg_val()`.
302+
cmd.arg(format!("--extra-arg={arg}").as_str());
298303
}
299304
let file_name = file.name.to_string_lossy().to_string();
300305
let ranges = file.get_ranges(&clang_params.lines_changed_only);
@@ -390,6 +395,10 @@ pub fn run_clang_tidy(
390395
&clang_params.database_json,
391396
&clang_params.repo_root,
392397
)?;
398+
logs.push((
399+
log::Level::Debug,
400+
format!("Parsed {} clang-tidy notifications", notes.len()),
401+
));
393402

394403
let tidy_advice = TidyAdvice { notes };
395404
file.patched_path = Some(cache_patch_path.to_path_buf());
@@ -474,7 +483,7 @@ mod test {
474483
// ***************** test for regex parsing of clang-tidy stdout
475484

476485
#[test]
477-
fn test_capture() {
486+
fn regex_capture() {
478487
let src = "tests/demo/demo.hpp:11:11: \
479488
warning: use a trailing return type for this function \
480489
[modernize-use-trailing-return-type,-warnings-as-errors]";
@@ -540,8 +549,9 @@ mod test {
540549
.expect("expected a log message about invoked clang-tidy command")
541550
.split(' ')
542551
.collect::<Vec<&str>>();
552+
println!("args: {:?}", args);
543553
for arg in &extra_args {
544-
let extra_arg = format!("\"{arg}\"");
554+
let extra_arg = format!("--extra-arg={arg}");
545555
assert!(args.contains(&extra_arg.as_str()));
546556
}
547557
}

cpp-linter/src/cli/structs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{fmt::Display, path::PathBuf};
44
use clap::{ValueEnum, builder::PossibleValue};
55

66
#[cfg(feature = "bin")]
7-
use super::Cli;
7+
use super::{Cli, convert_extra_arg_val};
88
use crate::clang_tools::clang_tidy::CompilationUnit;
99

1010
use git_bot_feedback::FileFilter;
@@ -275,7 +275,7 @@ impl From<&Cli> for ClangParams {
275275
tidy_checks: args.tidy_options.tidy_checks.clone(),
276276
lines_changed_only: args.source_options.lines_changed_only.clone(),
277277
database,
278-
extra_args: args.tidy_options.extra_arg.clone(),
278+
extra_args: convert_extra_arg_val(&args.tidy_options.extra_arg),
279279
database_json: None,
280280
style: args.format_options.style.clone(),
281281
clang_tidy_command: None,

0 commit comments

Comments
 (0)