[clang-tools-extra] [clang-tidy][NFC] Fix list.rst and improve alias detection of `add_new_check.py` (PR #192228)
Victor Chernyakin via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 20 08:23:41 PDT 2026
================
@@ -494,8 +487,41 @@ def has_auto_fix(check_name: str) -> str:
return ""
- def process_doc(doc_file: Tuple[str, str]) -> Tuple[str, Optional[Match[str]]]:
- check_name = doc_file[0] + "-" + doc_file[1].replace(".rst", "")
+ def detect_alias_target(check_name: str, content: str) -> Optional[str]:
+ """Return the :doc: target for non-redirect alias pages.
+
+ This recognizes pages that keep their own documentation content, but
+ whose paragraph explicitly states that the current check is an
+ alias of another check.
+ """
+ paragraphs = [
+ re.sub(r"\s+", " ", paragraph.strip())
+ for paragraph in re.split(r"\n\s*\n", content)
+ if paragraph.strip()
+ ]
+
+ self_alias = re.compile(
+ r"^This check is an alias(?: of check| for)\b",
+ re.IGNORECASE,
+ )
+ named_alias = re.compile(
+ rf"^The\s+`?{re.escape(check_name)}(?:\s+check)?`?"
+ rf"(?:\s+check)?\s+is\s+an\s+alias,?\s+please\s+see\b",
+ re.IGNORECASE,
+ )
+
+ for paragraph in paragraphs:
+ if self_alias.search(paragraph) or named_alias.search(paragraph):
+ if match := re.search(r":doc:`[^`<]+?\s*<([^>]+)>`", paragraph):
+ return match.group(1)
+ if match := re.search(
+ r"`[^`<]+?\s*<(.+?)\.html(?:#[^>]+)?>`_", paragraph
----------------
localspook wrote:
Can
```
[^`<]+?\s*
```
be simplified to just
```
[^`<]+?
```
? Since the latter will already eat the whitespace.
```suggestion
if match := re.search(r":doc:`[^`<]+?<([^>]+)>`", paragraph):
return match.group(1)
if match := re.search(
r"`[^`<]+?<(.+?)\.html(?:#[^>]+)?>`_", paragraph
```
https://github.com/llvm/llvm-project/pull/192228
More information about the cfe-commits
mailing list