[clang-tools-extra] Add a description parameter to the add_new_check script (PR #100111)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 23 05:12:07 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r f18dd9edec9c2135a8906d795258a8c5a24f74f3...2e7e63806ad643e43ef62d18ec44837b76a188e4 clang-tools-extra/clang-tidy/add_new_check.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- add_new_check.py	2024-07-23 12:06:45.000000 +0000
+++ add_new_check.py	2024-07-23 12:11:42.470580 +0000
@@ -52,12 +52,18 @@
 
     return True
 
 
 # Adds a header for the new check.
-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='/// '))
+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:
         header_guard = (
             "LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_"
@@ -107,11 +113,11 @@
                 "header_guard": header_guard,
                 "check_name_camel": check_name_camel,
                 "check_name": check_name,
                 "module": module,
                 "namespace": namespace,
-                "description": wrapped_desc
+                "description": wrapped_desc,
             }
         )
 
 
 # Adds the implementation of the new check.
@@ -237,11 +243,15 @@
             pass
 
 
 # Adds a release notes entry.
 def add_release_notes(module_path, module, check_name, description):
-    wrapped_desc = '\n'.join(textwrap.wrap(description, width=80, initial_indent='  ', subsequent_indent='  '))
+    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")
     )
     with io.open(filename, "r", encoding="utf8") as f:
@@ -615,14 +625,15 @@
         choices=language_to_extension.keys(),
         default="c++",
         metavar="LANG",
     )
     parser.add_argument(
-        '--description','-d',
+        "--description",
+        "-d",
         help="short description of what the check does",
         default="FIXME: Write a short description",
-        type=str
+        type=str,
     )
     parser.add_argument(
         "module",
         nargs="?",
         help="module directory under which to place the new tidy check (e.g., misc)",
@@ -661,14 +672,16 @@
         namespace = module + "_check"
     else:
         namespace = module
 
     description = args.description
-    if not description.endswith('.'): 
-        description += '.'
-
-    write_header(module_path, module, namespace, check_name, check_name_camel, 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, description)
     test_extension = language_to_extension.get(args.language)
     write_test(module_path, module, check_name, test_extension)

``````````

</details>


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


More information about the cfe-commits mailing list