8
8
#
9
9
# ===-----------------------------------------------------------------------===#
10
10
11
- from __future__ import unicode_literals
12
-
13
11
import argparse
14
12
import glob
15
13
import io
16
14
import os
17
15
import re
16
+ import sys
17
+ from typing import List
18
18
19
19
20
- def replaceInFileRegex (fileName , sFrom , sTo ) :
20
+ def replaceInFileRegex (fileName : str , sFrom : str , sTo : str ) -> None :
21
21
if sFrom == sTo :
22
22
return
23
23
@@ -35,7 +35,7 @@ def replaceInFileRegex(fileName, sFrom, sTo):
35
35
f .write (txt )
36
36
37
37
38
- def replaceInFile (fileName , sFrom , sTo ) :
38
+ def replaceInFile (fileName : str , sFrom : str , sTo : str ) -> None :
39
39
if sFrom == sTo :
40
40
return
41
41
txt = None
@@ -51,7 +51,7 @@ def replaceInFile(fileName, sFrom, sTo):
51
51
f .write (txt )
52
52
53
53
54
- def generateCommentLineHeader (filename ) :
54
+ def generateCommentLineHeader (filename : str ) -> str :
55
55
return "" .join (
56
56
[
57
57
"//===--- " ,
@@ -63,7 +63,7 @@ def generateCommentLineHeader(filename):
63
63
)
64
64
65
65
66
- def generateCommentLineSource (filename ) :
66
+ def generateCommentLineSource (filename : str ) -> str :
67
67
return "" .join (
68
68
[
69
69
"//===--- " ,
@@ -75,7 +75,7 @@ def generateCommentLineSource(filename):
75
75
)
76
76
77
77
78
- def fileRename (fileName , sFrom , sTo ) :
78
+ def fileRename (fileName : str , sFrom : str , sTo : str ) -> str :
79
79
if sFrom not in fileName or sFrom == sTo :
80
80
return fileName
81
81
newFileName = fileName .replace (sFrom , sTo )
@@ -84,7 +84,7 @@ def fileRename(fileName, sFrom, sTo):
84
84
return newFileName
85
85
86
86
87
- def deleteMatchingLines (fileName , pattern ) :
87
+ def deleteMatchingLines (fileName : str , pattern : str ) -> bool :
88
88
lines = None
89
89
with io .open (fileName , "r" , encoding = "utf8" ) as f :
90
90
lines = f .readlines ()
@@ -101,7 +101,7 @@ def deleteMatchingLines(fileName, pattern):
101
101
return True
102
102
103
103
104
- def getListOfFiles (clang_tidy_path ) :
104
+ def getListOfFiles (clang_tidy_path : str ) -> List [ str ] :
105
105
files = glob .glob (os .path .join (clang_tidy_path , "**" ), recursive = True )
106
106
files += [
107
107
os .path .normpath (os .path .join (clang_tidy_path , "../docs/ReleaseNotes.rst" ))
@@ -124,7 +124,7 @@ def getListOfFiles(clang_tidy_path):
124
124
125
125
# Adapts the module's CMakelist file. Returns 'True' if it could add a new
126
126
# entry and 'False' if the entry already existed.
127
- def adapt_cmake (module_path , check_name_camel ) :
127
+ def adapt_cmake (module_path : str , check_name_camel : str ) -> bool :
128
128
filename = os .path .join (module_path , "CMakeLists.txt" )
129
129
with io .open (filename , "r" , encoding = "utf8" ) as f :
130
130
lines = f .readlines ()
@@ -153,7 +153,9 @@ def adapt_cmake(module_path, check_name_camel):
153
153
154
154
155
155
# Modifies the module to include the new check.
156
- def adapt_module (module_path , module , check_name , check_name_camel ):
156
+ def adapt_module (
157
+ module_path : str , module : str , check_name : str , check_name_camel : str
158
+ ) -> None :
157
159
modulecpp = next (
158
160
iter (
159
161
filter (
@@ -204,7 +206,9 @@ def adapt_module(module_path, module, check_name, check_name_camel):
204
206
205
207
206
208
# Adds a release notes entry.
207
- def add_release_notes (clang_tidy_path , old_check_name , new_check_name ):
209
+ def add_release_notes (
210
+ clang_tidy_path : str , old_check_name : str , new_check_name : str
211
+ ) -> None :
208
212
filename = os .path .normpath (
209
213
os .path .join (clang_tidy_path , "../docs/ReleaseNotes.rst" )
210
214
)
@@ -262,7 +266,7 @@ def add_release_notes(clang_tidy_path, old_check_name, new_check_name):
262
266
f .write (line )
263
267
264
268
265
- def main ():
269
+ def main () -> None :
266
270
parser = argparse .ArgumentParser (description = "Rename clang-tidy check." )
267
271
parser .add_argument ("old_check_name" , type = str , help = "Old check name." )
268
272
parser .add_argument ("new_check_name" , type = str , help = "New check name." )
@@ -311,7 +315,7 @@ def main():
311
315
"Check name '%s' not found in %s. Exiting."
312
316
% (check_name_camel , cmake_lists )
313
317
)
314
- return 1
318
+ sys . exit ( 1 )
315
319
316
320
modulecpp = next (
317
321
iter (
0 commit comments