[PATCH] D75134: [clang-tidy] Improved renamer check logic

Eugene Zelenko via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 25 13:07:55 PST 2020


Eugene.Zelenko added a comment.

It'll be reasonable to have script to create check alias, but this could be made in separate patch.



================
Comment at: clang-tools-extra/clang-tidy/add_new_check.py:17
 import sys
-
-# Adapts the module's CMakelist file. Returns 'True' if it could add a new entry
-# and 'False' if the entry already existed.
-def adapt_cmake(module_path, check_name_camel):
-  filename = os.path.join(module_path, 'CMakeLists.txt')
-  with open(filename, 'r') as f:
-    lines = f.readlines()
-
-  cpp_file = check_name_camel + '.cpp'
-
-  # Figure out whether this check already exists.
-  for line in lines:
-    if line.strip() == cpp_file:
-      return False
-
-  print('Updating %s...' % filename)
-  with open(filename, 'w') as f:
-    cpp_found = False
-    file_added = False
-    for line in lines:
-      cpp_line = line.strip().endswith('.cpp')
-      if (not file_added) and (cpp_line or cpp_found):
-        cpp_found = True
-        if (line.strip() > cpp_file) or (not cpp_line):
-          f.write('  ' + cpp_file + '\n')
-          file_added = True
-      f.write(line)
-
-  return True
-
+from utils.modify_check import *
 
----------------
It's better to use import utils.modify_check. See Flake8.


================
Comment at: clang-tools-extra/clang-tidy/add_new_check.py:153
 
-
 # Modifies the module to include the new check.
----------------
Double line spacing may be intentional. For example, Flake8 enforces such rules.


================
Comment at: clang-tools-extra/clang-tidy/rename_check.py:15
 import re
+from utils.modify_check import *
 
----------------
It's better to use import utils.modify_check. See Flake8.


================
Comment at: clang-tools-extra/clang-tidy/rename_check.py:86
+def replaceHeaderComment(newHeader):
+  txt = open(newHeader, "r").read()
+  txt = re.sub(r'//===---[ -][^-.].+', 
----------------
It's better to open files with with operator. Same in other places.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75134/new/

https://reviews.llvm.org/D75134





More information about the cfe-commits mailing list