[clang-tools-extra] [clang-tidy][NFC] Fix list.rst and improve alias detection of `add_new_check.py` (PR #192228)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 15 11:52:42 PDT 2026
================
@@ -522,56 +553,66 @@ def format_link(doc_file: Tuple[str, str]) -> str:
def format_link_alias(doc_file: Tuple[str, str]) -> str:
check_name, match = process_doc(doc_file)
- if (match or (check_name.startswith("clang-analyzer-"))) and check_name:
- module = doc_file[0]
- check_file = doc_file[1].replace(".rst", "")
- if (
- not match
- or match.group(1) == "https://clang.llvm.org/docs/analyzer/checkers"
- ):
- title = "Clang Static Analyzer " + check_file
- # Preserve the anchor in checkers.html from group 2.
- target = "" if not match else match.group(1) + ".html" + match.group(2)
- autofix = ""
- ref_begin = ""
- ref_end = "_"
- else:
- redirect_parts = re.search(r"^\.\./([^/]*)/([^/]*)$", match.group(1))
- assert redirect_parts
- title = redirect_parts[1] + "-" + redirect_parts[2]
- target = redirect_parts[1] + "/" + redirect_parts[2]
- autofix = has_auto_fix(title)
- ref_begin = ":doc:"
- ref_end = ""
-
- if target:
- # The checker is just a redirect.
- return (
- " :doc:`%(check_name)s <%(module)s/%(check_file)s>`, %(ref_begin)s`%(title)s <%(target)s>`%(ref_end)s,%(autofix)s\n"
- % {
- "check_name": check_name,
- "module": module,
- "check_file": check_file,
- "target": target,
- "title": title,
- "autofix": autofix,
- "ref_begin": ref_begin,
- "ref_end": ref_end,
- }
- )
- else:
- # The checker is just a alias without redirect.
- return (
- " :doc:`%(check_name)s <%(module)s/%(check_file)s>`, %(title)s,%(autofix)s\n"
- % {
- "check_name": check_name,
- "module": module,
- "check_file": check_file,
- "title": title,
- "autofix": autofix,
- }
- )
- return ""
+ is_clang_analyzer = check_name.startswith("clang-analyzer-")
+ if not check_name or (not match and not is_clang_analyzer):
+ return ""
+
+ module = doc_file[0]
+ check_file = doc_file[1].replace(".rst", "")
+ if is_clang_analyzer:
+ title = "Clang Static Analyzer " + check_file
+ # Clang Static Analyzer aliases still need the external redirect
+ # target so list.rst can link to the upstream analyzer docs.
+ with open(os.path.join(docs_dir, *doc_file), "r", encoding="utf8") as doc:
+ content = doc.read()
+ redirect = re.search(
+ r".*:http-equiv=refresh: \d+;URL=(.*).html(.*)", content
+ )
+ # Preserve the anchor in checkers.html from group 2.
+ target = (
+ "" if not redirect else redirect.group(1) + ".html" + redirect.group(2)
----------------
EugeneZelenko wrote:
Should be f-string.
https://github.com/llvm/llvm-project/pull/192228
More information about the cfe-commits
mailing list