Skip to content

Commit ed1c67b

Browse files
authored
Add a description parameter to the add_new_check script (#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.
1 parent 988fd95 commit ed1c67b

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

clang-tools-extra/clang-tidy/add_new_check.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717
import re
1818
import sys
19+
import textwrap
1920

2021
# Adapts the module's CMakelist file. Returns 'True' if it could add a new
2122
# entry and 'False' if the entry already existed.
@@ -53,7 +54,14 @@ def adapt_cmake(module_path, check_name_camel):
5354

5455

5556
# Adds a header for the new check.
56-
def write_header(module_path, module, namespace, check_name, check_name_camel):
57+
def write_header(
58+
module_path, module, namespace, check_name, check_name_camel, description
59+
):
60+
wrapped_desc = "\n".join(
61+
textwrap.wrap(
62+
description, width=80, initial_indent="/// ", subsequent_indent="/// "
63+
)
64+
)
5765
filename = os.path.join(module_path, check_name_camel) + ".h"
5866
print("Creating %s..." % filename)
5967
with io.open(filename, "w", encoding="utf8", newline="\n") as f:
@@ -85,7 +93,7 @@ def write_header(module_path, module, namespace, check_name, check_name_camel):
8593
8694
namespace clang::tidy::%(namespace)s {
8795
88-
/// FIXME: Write a short description.
96+
%(description)s
8997
///
9098
/// For the user-facing documentation see:
9199
/// http://clang.llvm.org/extra/clang-tidy/checks/%(module)s/%(check_name)s.html
@@ -107,6 +115,7 @@ class %(check_name_camel)s : public ClangTidyCheck {
107115
"check_name": check_name,
108116
"module": module,
109117
"namespace": namespace,
118+
"description": wrapped_desc,
110119
}
111120
)
112121

@@ -235,7 +244,12 @@ def adapt_module(module_path, module, check_name, check_name_camel):
235244

236245

237246
# Adds a release notes entry.
238-
def add_release_notes(module_path, module, check_name):
247+
def add_release_notes(module_path, module, check_name, description):
248+
wrapped_desc = "\n".join(
249+
textwrap.wrap(
250+
description, width=80, initial_indent=" ", subsequent_indent=" "
251+
)
252+
)
239253
check_name_dashes = module + "-" + check_name
240254
filename = os.path.normpath(
241255
os.path.join(module_path, "../../docs/ReleaseNotes.rst")
@@ -281,10 +295,10 @@ def add_release_notes(module_path, module, check_name):
281295
"""- New :doc:`%s
282296
<clang-tidy/checks/%s/%s>` check.
283297
284-
FIXME: add release notes.
298+
%s
285299
286300
"""
287-
% (check_name_dashes, module, check_name)
301+
% (check_name_dashes, module, check_name, wrapped_desc)
288302
)
289303
note_added = True
290304

@@ -612,6 +626,13 @@ def main():
612626
default="c++",
613627
metavar="LANG",
614628
)
629+
parser.add_argument(
630+
"--description",
631+
"-d",
632+
help="short description of what the check does",
633+
default="FIXME: Write a short description",
634+
type=str,
635+
)
615636
parser.add_argument(
616637
"module",
617638
nargs="?",
@@ -652,10 +673,16 @@ def main():
652673
else:
653674
namespace = module
654675

655-
write_header(module_path, module, namespace, check_name, check_name_camel)
676+
description = args.description
677+
if not description.endswith("."):
678+
description += "."
679+
680+
write_header(
681+
module_path, module, namespace, check_name, check_name_camel, description
682+
)
656683
write_implementation(module_path, module, namespace, check_name_camel)
657684
adapt_module(module_path, module, check_name, check_name_camel)
658-
add_release_notes(module_path, module, check_name)
685+
add_release_notes(module_path, module, check_name, description)
659686
test_extension = language_to_extension.get(args.language)
660687
write_test(module_path, module, check_name, test_extension)
661688
write_docs(module_path, module, check_name)

0 commit comments

Comments
 (0)