Mercurial > public > mercurial-scm > hg-stable
diff 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 |
line wrap: on
line diff
--- a/contrib/check-code.py Sun May 13 13:17:50 2012 +0200 +++ b/contrib/check-code.py Sun May 13 13:18:06 2012 +0200 @@ -203,10 +203,10 @@ (r'(?i)descendent', "the proper spelling is descendAnt"), (r'\.debug\(\_', "don't mark debug messages for translation"), (r'\.strip\(\)\.split\(\)', "no need to strip before splitting"), + (r'^\s*except\s*:', "warning: naked except clause", r'#.*re-raises'), ], # warnings [ - (r'^\s*except\s*:', "warning: naked except clause"), (r'ui\.(status|progress|write|note|warn)\([\'\"]x', "warning: unwrapped ui message"), ] @@ -355,7 +355,13 @@ prelines = None errors = [] - for p, msg in pats: + for pat in pats: + if len(pat) == 3: + p, msg, ignore = pat + else: + p, msg = pat + ignore = None + # fix-up regexes for multiline searches po = p # \s doesn't match \n @@ -386,6 +392,8 @@ print "Skipping %s for %s:%s (check-code -ignore)" % ( name, f, n) continue + elif ignore and re.search(ignore, l, re.MULTILINE): + continue bd = "" if blame: bd = 'working directory'