Mercurial > public > mercurial-scm > hg-stable
diff contrib/check-code.py @ 34385:b52f22d9afa5
contrib: add a check to check-code to ban superfluous pass statements
These have annoyed me for a long time, and I'm tired of commenting on
them in reviews. I'm sorry for how complicated the regular expression
is, but I was too lazy to go crack open pylint's code and add the
check there.
author | Augie Fackler <augie@google.com> |
---|---|
date | Fri, 29 Sep 2017 11:55:44 -0400 |
parents | ba6e14f9a2d8 |
children | b332c01247d8 |
line wrap: on
line diff
--- a/contrib/check-code.py Sat Sep 30 07:45:18 2017 -0400 +++ b/contrib/check-code.py Fri Sep 29 11:55:44 2017 -0400 @@ -257,6 +257,16 @@ (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"), (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"), (r'\w\s=\s\s+\w', "gratuitous whitespace after ="), + (( + # a line ending with a colon, potentially with trailing comments + r':([ \t]*#[^\n]*)?\n' + # one that is not a pass and not only a comment + r'(?P<indent>[ \t]+)[^#][^\n]+\n' + # more lines at the same indent level + r'((?P=indent)[^\n]+\n)*' + # a pass at the same indent level, which is bogus + r'(?P=indent)pass[ \t\n#]' + ), 'omit superfluous pass'), (r'.{81}', "line too long"), (r'[^\n]\Z', "no trailing newline"), (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"),