Skip to content

Add a description parameter to the add_new_check script #100111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading