Skip to content

Commit 740bdf2

Browse files
authored
fix links to clang-analyzer diagnostic's help site (#36)
resolves #31
1 parent e1f09f0 commit 740bdf2

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

cpp-linter-lib/src/clang_tools/clang_tidy.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@ impl TidyNotification {
7676
if self.diagnostic.starts_with("clang-diagnostic") {
7777
return self.diagnostic.clone();
7878
}
79-
let (category, name) = self.diagnostic.split_once('-').unwrap();
79+
let (category, name) = if self.diagnostic.starts_with("clang-analyzer-") {
80+
(
81+
"clang-analyzer",
82+
self.diagnostic.strip_prefix("clang-analyzer-").unwrap(),
83+
)
84+
} else {
85+
self.diagnostic.split_once('-').unwrap()
86+
};
8087
format!(
8188
"[{}](https://clang.llvm.org/extra/clang-tidy/checks/{category}/{name}.html)",
8289
self.diagnostic
@@ -345,6 +352,43 @@ mod test {
345352
};
346353

347354
use super::run_clang_tidy;
355+
use super::TidyNotification;
356+
357+
#[test]
358+
fn clang_diagnostic_link() {
359+
let note = TidyNotification {
360+
filename: String::from("some_src.cpp"),
361+
line: 1504,
362+
cols: 9,
363+
rationale: String::from("file not found"),
364+
severity: String::from("error"),
365+
diagnostic: String::from("clang-diagnostic-error"),
366+
suggestion: vec![],
367+
fixed_lines: vec![],
368+
};
369+
assert_eq!(note.diagnostic_link(), note.diagnostic);
370+
}
371+
372+
#[test]
373+
fn clang_analyzer_link() {
374+
let note = TidyNotification {
375+
filename: String::from("some_src.cpp"),
376+
line: 1504,
377+
cols: 9,
378+
rationale: String::from(
379+
"Dereference of null pointer (loaded from variable 'pipe_num')",
380+
),
381+
severity: String::from("warning"),
382+
diagnostic: String::from("clang-analyzer-core.NullDereference"),
383+
suggestion: vec![],
384+
fixed_lines: vec![],
385+
};
386+
let expected = format!(
387+
"[{}](https://clang.llvm.org/extra/clang-tidy/checks/{}/{}.html)",
388+
note.diagnostic, "clang-analyzer", "core.NullDereference",
389+
);
390+
assert_eq!(note.diagnostic_link(), expected);
391+
}
348392

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

0 commit comments

Comments
 (0)