Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cpp-linter/src/cli/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ pub struct FeedbackInput {

/// The path of the generated patch file.
pub patch_path: PathBuf,

/// Whether a compilation database was given (see `--database`).
pub has_database: bool,
}

impl FeedbackInput {
Expand Down Expand Up @@ -434,6 +437,7 @@ impl From<&Cli> for FeedbackInput {
Some(path) => absolute_or_given(path),
None => ClangParams::default_patch_path(&args.source_options.repo_root),
},
has_database: args.tidy_options.database.is_some(),
}
}
}
Expand All @@ -456,6 +460,7 @@ impl Default for FeedbackInput {
code_quality_file: None,
gen_patch: false,
patch_path: ClangParams::default_patch_path(Path::new(".")),
has_database: false,
}
}
}
Expand Down Expand Up @@ -606,6 +611,8 @@ mod test {
let cli = Cli::parse_from(["cpp-linter", "--database", tmp_dir.path().to_str().unwrap()]);
let clang_params = ClangParams::from(&cli);
assert_eq!(clang_params.database, Some(tmp_dir.path().to_path_buf()));
assert!(FeedbackInput::from(&cli).has_database);
assert!(!FeedbackInput::from(&Cli::parse_from(["cpp-linter"])).has_database);
}

#[test]
Expand Down
27 changes: 20 additions & 7 deletions cpp-linter/src/rest_client/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl RestClient {
max_len: Option<u64>,
patch_exists: bool,
format_run: FormatRun<'_>,
has_database: bool,
) -> Result<String, ClientError> {
let findings = Findings::collect(files, format_run)?;
Ok(findings.to_markdown(&CommentContext {
Expand All @@ -60,6 +61,7 @@ impl RestClient {
.unwrap_or(usize::MAX),
patch_exists,
format_run,
has_database,
}))
}
}
Expand All @@ -77,6 +79,8 @@ struct CommentContext<'a> {
patch_exists: bool,
/// How clang-format ran.
format_run: FormatRun<'a>,
/// Whether a compilation database was given (see `database`).
has_database: bool,
}

/// The findings about one file, for a thread comment or step summary.
Expand Down Expand Up @@ -278,13 +282,22 @@ impl Findings {

let missing = self.missing_includes();
if missing > 0 {
comment.push_str(&format!(
"\nclang-tidy could not find {}, so it likely does not know how this code \
is built, and its other findings may be wrong too. Generate a compilation \
database (with CMake: `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`) and pass its \
folder as the `database` option.\n",
plural(missing, "included file")
));
let missing = plural(missing, "included file");
comment.push_str(&if ctx.has_database {
format!(
"\nclang-tidy could not find {missing} with the given compilation \
database, so its other findings may be wrong too. The database may be \
out of date or not match these sources: check that it was generated \
for this checkout and that the `database` option points to its folder.\n"
)
} else {
format!(
"\nclang-tidy could not find {missing}, so it likely does not know how \
this code is built, and its other findings may be wrong too. Generate a \
compilation database (with CMake: `-DCMAKE_EXPORT_COMPILE_COMMANDS=ON`) \
and pass its folder as the `database` option.\n"
)
});
}

// "How to fix" matters most when there are many findings, so room for it is kept
Expand Down
2 changes: 2 additions & 0 deletions cpp-linter/src/rest_client/feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ impl RestClient {
None,
patch_exists,
format_run,
feedback_inputs.has_database,
)?;
if feedback_inputs.step_summary {
self.client.append_step_summary(&summary)?;
Expand Down Expand Up @@ -250,6 +251,7 @@ impl RestClient {
Some(u16::MAX as u64),
patch_exists,
format_run,
feedback_inputs.has_database,
)?);
}
let options = ThreadCommentOptions {
Expand Down
Loading