Skip to content
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

Add a description parameter to the add_new_check script #100111

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

njames93
Copy link
Member

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.

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 23, 2024

@llvm/pr-subscribers-clang-tidy

@llvm/pr-subscribers-clang-tools-extra

Author: Nathan James (njames93)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/100111.diff

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/add_new_check.py (+21-7)
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)

Copy link

github-actions bot commented Jul 23, 2024

✅ With the latest revision this PR passed the Python code formatter.

Copy link
Contributor

@EugeneZelenko EugeneZelenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK for me, but please wait for other reviewers.

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.
@njames93 njames93 merged commit ed1c67b into llvm:main Jul 26, 2024
7 checks passed
@njames93 njames93 deleted the ct-add-new-check-desc branch July 26, 2024 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants