From 763540d4e09c2bf6614a6d4be9cf7cad153097ef Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Tue, 17 Sep 2024 21:19:09 -0700 Subject: [PATCH] fix links to clang-analyzer diagnostic's help site resolves #31 --- cpp-linter-lib/src/clang_tools/clang_tidy.rs | 46 +++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/cpp-linter-lib/src/clang_tools/clang_tidy.rs b/cpp-linter-lib/src/clang_tools/clang_tidy.rs index 44aaac0..f276e82 100644 --- a/cpp-linter-lib/src/clang_tools/clang_tidy.rs +++ b/cpp-linter-lib/src/clang_tools/clang_tidy.rs @@ -76,7 +76,14 @@ impl TidyNotification { if self.diagnostic.starts_with("clang-diagnostic") { return self.diagnostic.clone(); } - let (category, name) = self.diagnostic.split_once('-').unwrap(); + let (category, name) = if self.diagnostic.starts_with("clang-analyzer-") { + ( + "clang-analyzer", + self.diagnostic.strip_prefix("clang-analyzer-").unwrap(), + ) + } else { + self.diagnostic.split_once('-').unwrap() + }; format!( "[{}](https://clang.llvm.org/extra/clang-tidy/checks/{category}/{name}.html)", self.diagnostic @@ -345,6 +352,43 @@ mod test { }; use super::run_clang_tidy; + use super::TidyNotification; + + #[test] + fn clang_diagnostic_link() { + let note = TidyNotification { + filename: String::from("some_src.cpp"), + line: 1504, + cols: 9, + rationale: String::from("file not found"), + severity: String::from("error"), + diagnostic: String::from("clang-diagnostic-error"), + suggestion: vec![], + fixed_lines: vec![], + }; + assert_eq!(note.diagnostic_link(), note.diagnostic); + } + + #[test] + fn clang_analyzer_link() { + let note = TidyNotification { + filename: String::from("some_src.cpp"), + line: 1504, + cols: 9, + rationale: String::from( + "Dereference of null pointer (loaded from variable 'pipe_num')", + ), + severity: String::from("warning"), + diagnostic: String::from("clang-analyzer-core.NullDereference"), + suggestion: vec![], + fixed_lines: vec![], + }; + let expected = format!( + "[{}](https://clang.llvm.org/extra/clang-tidy/checks/{}/{}.html)", + note.diagnostic, "clang-analyzer", "core.NullDereference", + ); + assert_eq!(note.diagnostic_link(), expected); + } // ***************** test for regex parsing of clang-tidy stdout