[PATCH] D73580: [clang-tidy] rename_check.py: maintain alphabetical order in Renamed checks section

Eugene Zelenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 28 14:15:50 PST 2020


Eugene.Zelenko created this revision.
Eugene.Zelenko added reviewers: alexfh, hokein, aaron.ballman, njames93, MyDeveloperDay.
Eugene.Zelenko added a project: clang-tools-extra.
Herald added a subscriber: xazax.hun.
Herald added a project: clang.

Also use //check// in add_new_check.py for terminology consistency.

PS

My GitHub ID is EugeneZelenko <https://github.com/EugeneZelenko>, if it's necessary for attribution.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73580

Files:
  clang-tools-extra/clang-tidy/add_new_check.py
  clang-tools-extra/clang-tidy/rename_check.py
  clang-tools-extra/docs/ReleaseNotes.rst


Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -113,7 +113,6 @@
 Renamed checks
 ^^^^^^^^^^^^^^
 
-
 Improvements to include-fixer
 -----------------------------
 
Index: clang-tools-extra/clang-tidy/rename_check.py
===================================================================
--- clang-tools-extra/clang-tidy/rename_check.py
+++ clang-tools-extra/clang-tidy/rename_check.py
@@ -169,21 +169,45 @@
   with open(filename, 'r') as f:
     lines = f.readlines()
 
+  lineMatcher = re.compile('Renamed checks')
+  nextSectionMatcher = re.compile('Improvements to include-fixer')
+  checkMatcher = re.compile('- The \'(.*)')
+
   print('Updating %s...' % filename)
   with open(filename, 'wb') as f:
     note_added = False
     header_found = False
+    next_header_found = False
+    add_note_here = False
 
     for line in lines:
       if not note_added:
-        match = re.search('Renamed checks', line)
+        match = lineMatcher.match(line)
+        match_next = nextSectionMatcher.match(line)
+        match_check = checkMatcher.match(line)
+        if match_check:
+          last_check = match_check.group(1)
+          if last_check > old_check_name:
+            add_note_here = True
+
+        if match_next:
+          next_header_found = True
+          add_note_here = True
+
         if match:
           header_found = True
-        elif header_found:
+          f.write(line)
+          continue
+
+        if line.startswith('^^^^'):
+          f.write(line)
+          continue
+
+        if header_found and add_note_here:
           if not line.startswith('^^^^'):
-            f.write("""
-- The '%s' check was renamed to :doc:`%s
+            f.write("""- The '%s' check was renamed to :doc:`%s
   <clang-tidy/checks/%s>`
+
 """ % (old_check_name, new_check_name, new_check_name))
             note_added = True
 
Index: clang-tools-extra/clang-tidy/add_new_check.py
===================================================================
--- clang-tools-extra/clang-tidy/add_new_check.py
+++ clang-tools-extra/clang-tidy/add_new_check.py
@@ -221,7 +221,7 @@
 
   lineMatcher = re.compile('New checks')
   nextSectionMatcher = re.compile('New check aliases')
-  checkerMatcher = re.compile('- New :doc:`(.*)')
+  checkMatcher = re.compile('- New :doc:`(.*)')
 
   print('Updating %s...' % filename)
   with open(filename, 'w') as f:
@@ -234,10 +234,10 @@
       if not note_added:
         match = lineMatcher.match(line)
         match_next = nextSectionMatcher.match(line)
-        match_checker = checkerMatcher.match(line)
-        if match_checker:
-          last_checker = match_checker.group(1)
-          if last_checker > check_name_dashes:
+        match_check = checkMatcher.match(line)
+        if match_check:
+          last_check = match_check.group(1)
+          if last_check > check_name_dashes:
             add_note_here = True
 
         if match_next:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73580.240988.patch
Type: text/x-patch
Size: 3060 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200128/c4702ea8/attachment-0001.bin>


More information about the cfe-commits mailing list