Skip to content

Commit 2e7e638

Browse files
committed
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.
1 parent f18dd9e commit 2e7e638

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

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

Lines changed: 21 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,8 @@ 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(module_path, module, namespace, check_name, check_name_camel, description):
58+
wrapped_desc = '\n'.join(textwrap.wrap(description, width=80, initial_indent='/// ', subsequent_indent='/// '))
5759
filename = os.path.join(module_path, check_name_camel) + ".h"
5860
print("Creating %s..." % filename)
5961
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):
8587
8688
namespace clang::tidy::%(namespace)s {
8789
88-
/// FIXME: Write a short description.
90+
%(description)s
8991
///
9092
/// For the user-facing documentation see:
9193
/// 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 {
107109
"check_name": check_name,
108110
"module": module,
109111
"namespace": namespace,
112+
"description": wrapped_desc
110113
}
111114
)
112115

@@ -235,7 +238,8 @@ def adapt_module(module_path, module, check_name, check_name_camel):
235238

236239

237240
# Adds a release notes entry.
238-
def add_release_notes(module_path, module, check_name):
241+
def add_release_notes(module_path, module, check_name, description):
242+
wrapped_desc = '\n'.join(textwrap.wrap(description, width=80, initial_indent=' ', subsequent_indent=' '))
239243
check_name_dashes = module + "-" + check_name
240244
filename = os.path.normpath(
241245
os.path.join(module_path, "../../docs/ReleaseNotes.rst")
@@ -281,10 +285,10 @@ def add_release_notes(module_path, module, check_name):
281285
"""- New :doc:`%s
282286
<clang-tidy/checks/%s/%s>` check.
283287
284-
FIXME: add release notes.
288+
%s
285289
286290
"""
287-
% (check_name_dashes, module, check_name)
291+
% (check_name_dashes, module, check_name, wrapped_desc)
288292
)
289293
note_added = True
290294

@@ -612,6 +616,12 @@ def main():
612616
default="c++",
613617
metavar="LANG",
614618
)
619+
parser.add_argument(
620+
'--description','-d',
621+
help="short description of what the check does",
622+
default="FIXME: Write a short description",
623+
type=str
624+
)
615625
parser.add_argument(
616626
"module",
617627
nargs="?",
@@ -652,10 +662,14 @@ def main():
652662
else:
653663
namespace = module
654664

655-
write_header(module_path, module, namespace, check_name, check_name_camel)
665+
description = args.description
666+
if not description.endswith('.'):
667+
description += '.'
668+
669+
write_header(module_path, module, namespace, check_name, check_name_camel, description)
656670
write_implementation(module_path, module, namespace, check_name_camel)
657671
adapt_module(module_path, module, check_name, check_name_camel)
658-
add_release_notes(module_path, module, check_name)
672+
add_release_notes(module_path, module, check_name, description)
659673
test_extension = language_to_extension.get(args.language)
660674
write_test(module_path, module, check_name, test_extension)
661675
write_docs(module_path, module, check_name)

0 commit comments

Comments
 (0)