[clang-tools-extra] Add a description parameter to the add_new_check script (PR #100111)
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 23 05:07:33 PDT 2024
https://github.com/njames93 created https://github.com/llvm/llvm-project/pull/100111
Adds a description parameter that automatically fills in the Release notes and first line of the checks documentation. If omitted the usually FIXME markers are left in their place.
>From 2e7e63806ad643e43ef62d18ec44837b76a188e4 Mon Sep 17 00:00:00 2001
From: Nathan James <n.james93 at hotmail.co.uk>
Date: Tue, 23 Jul 2024 13:05:56 +0100
Subject: [PATCH] Add a description parameter to the add_new_check script
Adds a description parameter that automatically fills in the Release
notes and first line of the checks documentation. If omitted the usually
FIXME markers are left in their place.
---
clang-tools-extra/clang-tidy/add_new_check.py | 28 ++++++++++++++-----
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/add_new_check.py b/clang-tools-extra/clang-tidy/add_new_check.py
index 3a62df1f510ba..78ac4531de74a 100755
--- a/clang-tools-extra/clang-tidy/add_new_check.py
+++ b/clang-tools-extra/clang-tidy/add_new_check.py
@@ -16,6 +16,7 @@
import os
import re
import sys
+import textwrap
# Adapts the module's CMakelist file. Returns 'True' if it could add a new
# entry and 'False' if the entry already existed.
@@ -53,7 +54,8 @@ def adapt_cmake(module_path, check_name_camel):
# Adds a header for the new check.
-def write_header(module_path, module, namespace, check_name, check_name_camel):
+def write_header(module_path, module, namespace, check_name, check_name_camel, description):
+ wrapped_desc = '\n'.join(textwrap.wrap(description, width=80, initial_indent='/// ', subsequent_indent='/// '))
filename = os.path.join(module_path, check_name_camel) + ".h"
print("Creating %s..." % filename)
with io.open(filename, "w", encoding="utf8", newline="\n") as f:
@@ -85,7 +87,7 @@ def write_header(module_path, module, namespace, check_name, check_name_camel):
namespace clang::tidy::%(namespace)s {
-/// FIXME: Write a short description.
+%(description)s
///
/// For the user-facing documentation see:
/// http://clang.llvm.org/extra/clang-tidy/checks/%(module)s/%(check_name)s.html
@@ -107,6 +109,7 @@ class %(check_name_camel)s : public ClangTidyCheck {
"check_name": check_name,
"module": module,
"namespace": namespace,
+ "description": wrapped_desc
}
)
@@ -235,7 +238,8 @@ def adapt_module(module_path, module, check_name, check_name_camel):
# Adds a release notes entry.
-def add_release_notes(module_path, module, check_name):
+def add_release_notes(module_path, module, check_name, description):
+ wrapped_desc = '\n'.join(textwrap.wrap(description, width=80, initial_indent=' ', subsequent_indent=' '))
check_name_dashes = module + "-" + check_name
filename = os.path.normpath(
os.path.join(module_path, "../../docs/ReleaseNotes.rst")
@@ -281,10 +285,10 @@ def add_release_notes(module_path, module, check_name):
"""- New :doc:`%s
<clang-tidy/checks/%s/%s>` check.
- FIXME: add release notes.
+%s
"""
- % (check_name_dashes, module, check_name)
+ % (check_name_dashes, module, check_name, wrapped_desc)
)
note_added = True
@@ -612,6 +616,12 @@ def main():
default="c++",
metavar="LANG",
)
+ parser.add_argument(
+ '--description','-d',
+ help="short description of what the check does",
+ default="FIXME: Write a short description",
+ type=str
+ )
parser.add_argument(
"module",
nargs="?",
@@ -652,10 +662,14 @@ def main():
else:
namespace = module
- write_header(module_path, module, namespace, check_name, check_name_camel)
+ description = args.description
+ if not description.endswith('.'):
+ description += '.'
+
+ write_header(module_path, module, namespace, check_name, check_name_camel, description)
write_implementation(module_path, module, namespace, check_name_camel)
adapt_module(module_path, module, check_name, check_name_camel)
- add_release_notes(module_path, module, check_name)
+ add_release_notes(module_path, module, check_name, description)
test_extension = language_to_extension.get(args.language)
write_test(module_path, module, check_name, test_extension)
write_docs(module_path, module, check_name)
More information about the cfe-commits
mailing list