Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d63e557
feat: make the comment, review and annotations read at a glance
shenxianpeng Nov 19, 2026
b9af270
fix: count review comments, not suggestions, in the review summary
shenxianpeng Nov 19, 2026
c9ae558
feat: show the brand status marks in tables and review comments
shenxianpeng Nov 19, 2026
3ceba6f
docs: reshoot the comment, review and annotation previews
shenxianpeng Nov 19, 2026
6b4ed1f
fix: scope the clang-format command to the checked lines and tighten …
shenxianpeng Nov 19, 2026
dde0c5e
test: avoid single-range literals flagged by newer clippy
shenxianpeng Nov 19, 2026
a63aab2
fix: point to the patch only after it is written; keep the comment wi…
shenxianpeng Nov 19, 2026
a0d46dc
Merge remote-tracking branch 'origin/main' into claude/project-thread…
shenxianpeng Nov 19, 2026
a000db3
docs: reshoot the previews with line-scoped format commands and the t…
shenxianpeng Nov 19, 2026
127849c
test: cover the remaining new report paths
shenxianpeng Nov 20, 2026
858644b
fix: keep the summary when a review fails, name files from the reposi…
shenxianpeng Nov 20, 2026
ac913ca
style: drop the rule above the comment footer
shenxianpeng Nov 20, 2026
309865c
fix: flag review errors without a patched file; prefix a relative sty…
shenxianpeng Nov 20, 2026
a390075
test: avoid a single-range literal flagged by newer clippy
shenxianpeng Nov 20, 2026
8643c84
docs: reshoot comment screenshots without the footer rule
shenxianpeng Nov 20, 2026
c619d6f
feat: brush status marks, a Tool column and plainer copy in comments
shenxianpeng Nov 20, 2026
5af58b2
chore: add absmiddle to the spelling dictionary
shenxianpeng Nov 20, 2026
58d3422
fix: keep a review with an unposted clang-tidy error from passing
shenxianpeng Nov 20, 2026
731a3b3
docs: reshoot the comment and review previews with the brush marks
shenxianpeng Nov 20, 2026
c507f9d
fix: offer the AI prompt as its own step in How to fix
shenxianpeng Nov 20, 2026
c2be22f
chore: spell out the patch line's lead word
shenxianpeng Nov 20, 2026
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
45 changes: 45 additions & 0 deletions cpp-linter/src/clang_tools/clang_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,34 @@ pub fn summarize_style(style: &str) -> String {
}
}

/// Describe the given `--style` for a sentence such as "Line 4 does not match {description}."
///
/// - `file` (or no value): the style in `.clang-format`
/// - `file:<path>`: the style in that file
/// - a predefined style (eg. `llvm`): the LLVM style
/// - anything else (eg. `{BasedOnStyle: llvm}`): the configured style
pub fn describe_style(style: &str) -> String {
if style.is_empty() || style == "file" {
String::from("the style in .clang-format")
} else if let Some(path) = style.strip_prefix("file:") {
format!("the style in {path}")
} else if [
"google",
"chromium",
"microsoft",
"mozilla",
"webkit",
"llvm",
"gnu",
]
.contains(&style)
{
format!("the {} style", summarize_style(style))
} else {
String::from("the configured style")
}
}

/// Get a total count of clang-format advice from the given list of [FileObj]s.
pub fn tally_format_advice(files: &[Arc<Mutex<FileObj>>]) -> Result<u64, String> {
let mut total = 0;
Expand Down Expand Up @@ -750,4 +778,21 @@ mod tests {
println!("{style}{l}{style:#}");
}
}

#[test]
fn style_descriptions() {
use super::describe_style;
assert_eq!(describe_style("file"), "the style in .clang-format");
assert_eq!(describe_style(""), "the style in .clang-format");
assert_eq!(
describe_style("file:../.clang-format"),
"the style in ../.clang-format"
);
assert_eq!(describe_style("llvm"), "the LLVM style");
assert_eq!(describe_style("google"), "the Google style");
assert_eq!(
describe_style("{BasedOnStyle: llvm}"),
"the configured style"
);
}
}
58 changes: 46 additions & 12 deletions cpp-linter/src/clang_tools/clang_tidy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ use regex::Regex;
use serde::Deserialize;

// project-specific modules/crates
use crate::{cli::ClangParams, common_fs::FileObj, error::ClangCaptureError};
use crate::{
cli::ClangParams,
common_fs::FileObj,
error::ClangCaptureError,
markdown::{self, Status},
};

pub mod other_files;
use other_files::{OtherFileFix, Replacement, TidyFixes};
Expand Down Expand Up @@ -146,7 +151,43 @@ impl TidyNotification {
/// The heading of a review suggestion that no clang-tidy note fixes.
///
/// Such a suggestion only has changes from clang-format.
pub(crate) const FORMAT_SUGGESTION_HEADING: &str = "### clang-format suggestion\n";
pub(crate) const FORMAT_SUGGESTION_HEADING: &str = "**clang-format** suggests this formatting.\n";

impl TidyNotification {
/// Describe this notification in a PR review comment (in markdown).
///
/// The comment is shown under the line it is about,
/// so the file name and line number are left out:
/// a line with the severity and the linked diagnostic name, then the rationale,
/// then the parts of the fix that were not applied (if any).
pub(crate) fn review_text(&self) -> String {
let (mark, severity) = match self.severity.as_str() {
"error" => (Status::Failed.small_mark(), String::from("Error")),
"warning" => (Status::Warned.small_mark(), String::from("Warning")),
other => {
let mut chars = other.chars();
let word = chars
.next()
.map(|first| first.to_uppercase().collect::<String>() + chars.as_str())
.unwrap_or_default();
(String::from("ℹ"), word)
}
};
let mut text = format!(
"{mark} **{severity}**: {}\n\n{}\n",
self.diagnostic_link(),
markdown::escape(&self.rationale)
);
for skipped in &self.skipped_fixes {
text.push_str(&format!(
"\n{} {}\n",
Status::Warned.small_mark(),
skipped.describe()
));
}
text
}
}

/// A struct to hold notification from clang-tidy about a single file
#[derive(Debug, Clone)]
Expand All @@ -160,26 +201,19 @@ impl TidyAdvice {
let mut diagnostics = vec![];
for note in &self.notes {
// A fix can change more than one line of the same hunk.
// List the note's rationale once, not once per fixed line.
// Describe the note once, not once per fixed line.
if note
.fixed_lines
.iter()
.any(|fixed_line| (start_line..=end_line).contains(fixed_line))
{
diagnostics.push(format!(
"- {} [{}]\n",
note.rationale,
note.diagnostic_link()
));
for skipped in &note.skipped_fixes {
diagnostics.push(format!(" - :warning: {}\n", skipped.describe()));
}
diagnostics.push(note.review_text());
}
}
if diagnostics.is_empty() {
return FORMAT_SUGGESTION_HEADING.to_string();
}
format!("### clang-tidy diagnostic(s)\n{}", diagnostics.join(""))
diagnostics.join("\n")
}
}

Expand Down
5 changes: 4 additions & 1 deletion cpp-linter/src/clang_tools/clang_tidy/other_files/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ async fn fix_analyzed_header() {
.as_ref()
.unwrap()
.get_suggestion_help(2, 2);
assert!(help.starts_with("### clang-tidy diagnostic(s)"), "{help}");
assert!(
help.starts_with("<img alt=\"⚠\"") && help.contains("> **Warning**: "),
"{help}"
);
assert!(help.contains(&note.rationale), "{help}");
assert_eq!(tally_tidy_advice(&files).unwrap(), 1);
}
Expand Down
24 changes: 18 additions & 6 deletions cpp-linter/src/clang_tools/clang_tidy/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,25 @@ fn suggestion_help_with_and_without_fixes() {
let advice = TidyAdvice {
notes: vec![dummy_note("demo.cpp", vec![5])],
};
// A fixed line within the range yields a "diagnostic(s)" header plus the rationale.
// A fixed line within the range yields the severity, the diagnostic and the rationale.
let help = advice.get_suggestion_help(1, 10);
assert!(help.contains("clang-tidy diagnostic(s)"));
assert!(help.contains("a dummy rationale"));
assert_eq!(
help,
"<img alt=\"⚠\" width=\"20\" align=\"absmiddle\" src=\"https://cpp-linter.github.io/m/w.png\"> **Warning**: [modernize-use-auto](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-auto.html)\n\na dummy rationale\n"
);
// No fixed line within the range: the suggestion only has clang-format changes.
let help = advice.get_suggestion_help(20, 30);
assert_eq!(help, "### clang-format suggestion\n");
assert_eq!(help, "**clang-format** suggests this formatting.\n");
}

#[test]
fn review_text_for_other_severities() {
let mut note = dummy_note("demo.cpp", vec![]);
note.severity = String::from("note");
assert_eq!(
note.review_text(),
"ℹ **Note**: [modernize-use-auto](https://clang.llvm.org/extra/clang-tidy/checks/modernize/use-auto.html)\n\na dummy rationale\n"
);
}

#[test]
Expand All @@ -319,7 +331,7 @@ fn suggestion_help_lists_a_multi_line_fix_once() {
let advice = TidyAdvice { notes: vec![note] };
let help = advice.get_suggestion_help(1, 10);
assert_eq!(help.matches("a dummy rationale").count(), 1);
assert_eq!(help.matches(":warning:").count(), 1);
assert_eq!(help.matches("/m/w.png\"> Part of this fix").count(), 1);
// The note is still listed when only one of its fixed lines is in the hunk.
let help = advice.get_suggestion_help(6, 8);
assert_eq!(help.matches("a dummy rationale").count(), 1);
Expand All @@ -337,7 +349,7 @@ fn suggestion_help_with_skipped_fixes() {
let advice = TidyAdvice { notes: vec![note] };
let help = advice.get_suggestion_help(5, 5);
assert!(help.contains(
"\n - :warning: Part of this fix was not applied to `demo.h` \
"/m/w.png\"> Part of this fix was not applied to `demo.h` \
because it is not one of the analyzed files.\n"
));
}
Expand Down
Loading
Loading