diff --git a/contrib/check-code.py b/contrib/check-code.py --- a/contrib/check-code.py +++ b/contrib/check-code.py @@ -257,6 +257,16 @@ pypats = [ (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[ \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"), diff --git a/tests/test-contrib-check-code.t b/tests/test-contrib-check-code.t --- a/tests/test-contrib-check-code.t +++ b/tests/test-contrib-check-code.t @@ -285,11 +285,43 @@ web templates > ''' "%-6d \n 123456 .:*+-= foobar") > EOF +superfluous pass + + $ cat > superfluous_pass.py < # correct examples + > if foo: + > pass + > else: + > # comment-only line means still need pass + > pass + > def nothing(): + > pass + > class empty(object): + > pass + > if whatever: + > passvalue(value) + > # bad examples + > if foo: + > "foo" + > pass + > else: # trailing comment doesn't fool checker + > wat() + > pass + > def nothing(): + > "docstring means no pass" + > pass + > class empty(object): + > """multiline + > docstring also + > means no pass""" + > pass + > EOF + (Checking multiple invalid files at once examines whether caching translation table for repquote() works as expected or not. All files should break rules depending on result of repquote(), in this case) - $ "$check_code" stringjoin.py uigettext.py + $ "$check_code" stringjoin.py uigettext.py superfluous_pass.py stringjoin.py:1: > foo = (' foo' string join across lines with no space @@ -317,4 +349,16 @@ should break rules depending on result o uigettext.py:1: > ui.status("% 10s %05d % -3.2f %*s %%" missing _() in ui message (use () to hide false-positives) + superfluous_pass.py:14: + > if foo: + omit superfluous pass + superfluous_pass.py:17: + > else: # trailing comment doesn't fool checker + omit superfluous pass + superfluous_pass.py:20: + > def nothing(): + omit superfluous pass + superfluous_pass.py:23: + > class empty(object): + omit superfluous pass [1]