comparison contrib/check-code.py @ 16705:c2d9ef43ff6c

check-code: ignore naked excepts with a "re-raise" comment This also promotes the naked except check from a warning to an error.
author Brodie Rao <brodie@sf.io>
date Sun, 13 May 2012 13:18:06 +0200
parents 1f3acc30bdfe
children 91284af53508
comparison
equal deleted inserted replaced
16704:1f3acc30bdfe 16705:c2d9ef43ff6c
201 (r'[\s\(](open|file)\([^)]*\)\.', 201 (r'[\s\(](open|file)\([^)]*\)\.',
202 "always assign an opened file to a variable, and close it afterwards"), 202 "always assign an opened file to a variable, and close it afterwards"),
203 (r'(?i)descendent', "the proper spelling is descendAnt"), 203 (r'(?i)descendent', "the proper spelling is descendAnt"),
204 (r'\.debug\(\_', "don't mark debug messages for translation"), 204 (r'\.debug\(\_', "don't mark debug messages for translation"),
205 (r'\.strip\(\)\.split\(\)', "no need to strip before splitting"), 205 (r'\.strip\(\)\.split\(\)', "no need to strip before splitting"),
206 ], 206 (r'^\s*except\s*:', "warning: naked except clause", r'#.*re-raises'),
207 # warnings 207 ],
208 [ 208 # warnings
209 (r'^\s*except\s*:', "warning: naked except clause"), 209 [
210 (r'ui\.(status|progress|write|note|warn)\([\'\"]x', 210 (r'ui\.(status|progress|write|note|warn)\([\'\"]x',
211 "warning: unwrapped ui message"), 211 "warning: unwrapped ui message"),
212 ] 212 ]
213 ] 213 ]
214 214
353 if debug: 353 if debug:
354 print "Checking %s for %s" % (name, f) 354 print "Checking %s for %s" % (name, f)
355 355
356 prelines = None 356 prelines = None
357 errors = [] 357 errors = []
358 for p, msg in pats: 358 for pat in pats:
359 if len(pat) == 3:
360 p, msg, ignore = pat
361 else:
362 p, msg = pat
363 ignore = None
364
359 # fix-up regexes for multiline searches 365 # fix-up regexes for multiline searches
360 po = p 366 po = p
361 # \s doesn't match \n 367 # \s doesn't match \n
362 p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p) 368 p = re.sub(r'(?<!\\)\\s', r'[ \\t]', p)
363 # [^...] doesn't match newline 369 # [^...] doesn't match newline
383 389
384 if "check-code" + "-ignore" in l: 390 if "check-code" + "-ignore" in l:
385 if debug: 391 if debug:
386 print "Skipping %s for %s:%s (check-code -ignore)" % ( 392 print "Skipping %s for %s:%s (check-code -ignore)" % (
387 name, f, n) 393 name, f, n)
394 continue
395 elif ignore and re.search(ignore, l, re.MULTILINE):
388 continue 396 continue
389 bd = "" 397 bd = ""
390 if blame: 398 if blame:
391 bd = 'working directory' 399 bd = 'working directory'
392 if not blamecache: 400 if not blamecache: