Skip to content
Open
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
45 changes: 34 additions & 11 deletions cpp-linter/src/clang_tools/clang_tidy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,28 @@ pub struct TidyNotification {

impl TidyNotification {
pub fn diagnostic_link(&self) -> String {
if self.diagnostic.starts_with("clang-diagnostic") {
if self.diagnostic.starts_with("clang-diagnostic-") {
// clang-diagnostic-* diagnostics are compiler diagnostics and don't have
// dedicated clang-tidy documentation pages, so return the name as-is.
return self.diagnostic.clone();
}
let (category, name) = if self.diagnostic.starts_with("clang-analyzer-") {
(
"clang-analyzer",
self.diagnostic.strip_prefix("clang-analyzer-").unwrap(),
if let Some((category, name)) = if self.diagnostic.starts_with("clang-analyzer-") {
self.diagnostic
.strip_prefix("clang-analyzer-")
.map(|n| ("clang-analyzer", n))
} else {
self.diagnostic.split_once('-')
} {
// In production, both category and name should be non-empty strings.
// Clang does not actually have a diagnostic name whose category or name is empty.
debug_assert!(!category.is_empty() && !name.is_empty());
format!(
"[{}](https://clang.llvm.org/extra/clang-tidy/checks/{category}/{name}.html)",
self.diagnostic
)
} else {
self.diagnostic.split_once('-').unwrap()
};
format!(
"[{}](https://clang.llvm.org/extra/clang-tidy/checks/{category}/{name}.html)",
self.diagnostic
)
self.diagnostic.clone()
}
}
}

Expand Down Expand Up @@ -392,6 +399,22 @@ mod test {
assert_eq!(note.diagnostic_link(), expected);
}

#[test]
fn invalid_diagnostic_link() {
let expected = "no_diagnostic_name".to_string();
let note = TidyNotification {
filename: String::from("some_src.cpp"),
line: 1504,
cols: 9,
rationale: String::from("some rationale"),
severity: String::from("warning"),
diagnostic: expected.clone(),
suggestion: vec![],
fixed_lines: vec![],
};
assert_eq!(note.diagnostic_link(), expected);
}

// ***************** test for regex parsing of clang-tidy stdout

#[test]
Expand Down
Loading