Skip to content

Commit

Permalink
Add a description parameter to the add_new_check script (llvm#100111)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
njames93 authored Jul 26, 2024
1 parent 988fd95 commit ed1c67b
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions clang-tools-extra/clang-tidy/add_new_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -53,7 +54,14 @@ 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:
Expand Down Expand Up @@ -85,7 +93,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
Expand All @@ -107,6 +115,7 @@ class %(check_name_camel)s : public ClangTidyCheck {
"check_name": check_name,
"module": module,
"namespace": namespace,
"description": wrapped_desc,
}
)

Expand Down Expand Up @@ -235,7 +244,12 @@ 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")
Expand Down Expand Up @@ -281,10 +295,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

Expand Down Expand Up @@ -612,6 +626,13 @@ 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="?",
Expand Down Expand Up @@ -652,10 +673,16 @@ 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)
Expand Down

0 comments on commit ed1c67b

Please sign in to comment.