@@ -58,9 +58,9 @@ def collect(lints, deprecated_lints, restriction_lints, fn):
58
58
# remove \-newline escapes from description string
59
59
desc = nl_escape_re .sub ('' , match .group ('desc' ))
60
60
restriction_lints .append ((os .path .splitext (os .path .basename (fn ))[0 ],
61
- match .group ('name' ).lower (),
62
- "allow" ,
63
- desc .replace ('\\ "' , '"' )))
61
+ match .group ('name' ).lower (),
62
+ "allow" ,
63
+ desc .replace ('\\ "' , '"' )))
64
64
65
65
66
66
def gen_table (lints , link = None ):
@@ -100,6 +100,7 @@ def gen_deprecated(lints):
100
100
for lint in lints :
101
101
yield ' store.register_removed("%s", "%s");\n ' % (lint [1 ], lint [2 ])
102
102
103
+
103
104
def replace_region (fn , region_start , region_end , callback ,
104
105
replace_start = True , write_back = True ):
105
106
"""Replace a region in a file delimited by two lines matching regexes.
@@ -155,6 +156,16 @@ def main(print_only=False, check=False):
155
156
collect (lints , deprecated_lints , restriction_lints ,
156
157
os .path .join (root , fn ))
157
158
159
+ # determine version
160
+ with open ('Cargo.toml' ) as fp :
161
+ for line in fp :
162
+ if line .startswith ('version =' ):
163
+ clippy_version = line .split ()[2 ].strip ('"' )
164
+ break
165
+ else :
166
+ print ('Error: version not found in Cargo.toml!' )
167
+ return
168
+
158
169
if print_only :
159
170
sys .stdout .writelines (gen_table (lints + restriction_lints ))
160
171
return
@@ -168,8 +179,8 @@ def main(print_only=False, check=False):
168
179
changed |= replace_region (
169
180
'README.md' ,
170
181
r'^There are \d+ lints included in this crate:' , "" ,
171
- lambda : ['There are %d lints included in this crate:\n ' % ( len ( lints )
172
- + len (restriction_lints ))],
182
+ lambda : ['There are %d lints included in this crate:\n ' %
183
+ ( len ( lints ) + len (restriction_lints ))],
173
184
write_back = not check )
174
185
175
186
# update the links in the CHANGELOG
@@ -182,6 +193,19 @@ def main(print_only=False, check=False):
182
193
key = lambda l : l [1 ])],
183
194
replace_start = False , write_back = not check )
184
195
196
+ # update version of clippy_lints in Cargo.toml
197
+ changed |= replace_region (
198
+ 'Cargo.toml' , r'# begin automatic update' , '# end automatic update' ,
199
+ lambda : ['clippy_lints = { version = "%s", path = "clippy_lints" }\n ' %
200
+ clippy_version ],
201
+ replace_start = False , write_back = not check )
202
+
203
+ # update version of clippy_lints in Cargo.toml
204
+ changed |= replace_region (
205
+ 'clippy_lints/Cargo.toml' , r'# begin automatic update' , '# end automatic update' ,
206
+ lambda : ['version = "%s"\n ' % clippy_version ],
207
+ replace_start = False , write_back = not check )
208
+
185
209
# update the `pub mod` list
186
210
changed |= replace_region (
187
211
'clippy_lints/src/lib.rs' , r'begin lints modules' , r'end lints modules' ,
@@ -196,10 +220,10 @@ def main(print_only=False, check=False):
196
220
197
221
# same for "deprecated" lint collection
198
222
changed |= replace_region (
199
- 'clippy_lints/src/lib.rs' , r'let mut store' , r'end deprecated lints' ,
200
- lambda : gen_deprecated (deprecated_lints ),
201
- replace_start = False ,
202
- write_back = not check )
223
+ 'clippy_lints/src/lib.rs' , r'let mut store' , r'end deprecated lints' ,
224
+ lambda : gen_deprecated (deprecated_lints ),
225
+ replace_start = False ,
226
+ write_back = not check )
203
227
204
228
# same for "clippy_pedantic" lint collection
205
229
changed |= replace_region (
0 commit comments