Repository: cpp-linter/cpp-linter (language: python)

Issue:
dead links to `clang-analyzer-*` diagnostics
I just found that the generated links to `clang-analyzer-*` diagnostics are broken.

## Example
Consider the following examples output (generated from the nRF24/RF24 repo)

- **RF24.cpp:1504:9:** warning: [[clang-analyzer-core.NullDereference](https://clang.llvm.org/extra/clang-tidy/checks/clang/analyzer-core.NullDereference.html)]
   > Dereference of null pointer (loaded from variable 'pipe_num')

   ```cpp
   // code in question here...
   ```

---

Notice the dead link. According to the clang-tidy docs, these [clang-analyzer diagnostics are really just aliases](https://clang.llvm.org/extra/clang-tidy/checks/list.html#check-aliases) to checks explained in the clang-analyzer tool (another utility built from clang's lib tooling API).

For instance, the above link to `clang-analyzer-core.NullDereference` should direct users to https://clang.llvm.org/extra/clang-tidy/checks/clang-analyzer/core.NullDereference.html which is a placeholder page that redirects to https://clang.llvm.org/docs/analyzer/checkers.html#core-nulldereference.

dead links to `clang-analyzer-*` diagnostics
I just found that the generated links to `clang-analyzer-*` diagnostics are broken.

## Example
Consider the following examples output (generated from the nRF24/RF24 repo)

- **RF24.cpp:1504:9:** warning: [[clang-analyzer-core.NullDereference](https://clang.llvm.org/extra/clang-tidy/checks/clang/analyzer-core.NullDereference.html)]
   > Dereference of null pointer (loaded from variable 'pipe_num')

   ```cpp
   // code in question here...
   ```

---

Notice the dead link. According to the clang-tidy docs, these [clang-analyzer diagnostics are really just aliases](https://clang.llvm.org/extra/clang-tidy/checks/list.html#check-aliases) to checks explained in the clang-analyzer tool (another utility built from clang's lib tooling API).

For instance, the above link to `clang-analyzer-core.NullDereference` should direct users to https://clang.llvm.org/extra/clang-tidy/checks/clang-analyzer/core.NullDereference.html which is a placeholder page that redirects to https://clang.llvm.org/docs/analyzer/checkers.html#core-nulldereference.



Discussion / hints:

Fix patch:
diff --git a/cpp_linter/clang_tools/clang_tidy.py b/cpp_linter/clang_tools/clang_tidy.py
index a33afd5..48b156c 100644
--- a/cpp_linter/clang_tools/clang_tidy.py
+++ b/cpp_linter/clang_tools/clang_tidy.py
@@ -85,6 +85,10 @@ def diagnostic_link(self) -> str:
         if self.diagnostic.startswith("clang-diagnostic-"):
             return self.diagnostic
         link = f"[{self.diagnostic}](https://clang.llvm.org/extra/clang-tidy/checks/"
+        if self.diagnostic.startswith("clang-analyzer-"):
+            check_name_parts = self.diagnostic.split("-", maxsplit=2)
+            assert len(check_name_parts) > 2, "diagnostic name malformed"
+            return link + "clang-analyzer/{}.html)".format(check_name_parts[2])
         return link + "{}/{}.html)".format(*self.diagnostic.split("-", maxsplit=1))
 
     def __repr__(self) -> str:


Test patch:
diff --git a/tests/test_misc.py b/tests/test_misc.py
index 286d702..0f02575 100644
--- a/tests/test_misc.py
+++ b/tests/test_misc.py
@@ -19,6 +19,7 @@
     end_log_group,
 )
 from cpp_linter.rest_api.github_api import GithubApiClient
+from cpp_linter.clang_tools.clang_tidy import TidyNotification
 
 
 def test_exit_output(monkeypatch: pytest.MonkeyPatch, tmp_path: Path):
@@ -118,3 +119,31 @@ def test_tool_exe_path(tool_name: str, version: str):
     exe_path = assemble_version_exec(tool_name, version)
     assert exe_path
     assert tool_name in exe_path
+
+
+def test_clang_analyzer_link():
+    """Ensures the hyper link for a diagnostic about clang-analyzer checks is
+    not malformed"""
+    file_name = "RF24.cpp"
+    line = "1504"
+    column = "9"
+    rationale = "Dereference of null pointer (loaded from variable 'pipe_num')"
+    severity = "warning"
+    diagnostic_name = "clang-analyzer-core.NullDereference"
+    note = TidyNotification(
+        (
+            file_name,
+            line,
+            column,
+            severity,
+            rationale,
+            diagnostic_name,
+        )
+    )
+    assert note.diagnostic_link == (
+        "[{}]({}/{}.html)".format(
+            diagnostic_name,
+            "https://clang.llvm.org/extra/clang-tidy/checks/clang-analyzer",
+            diagnostic_name.split("-", maxsplit=2)[2],
+        )
+    )