Mercurial > public > mercurial-scm > hg
diff tests/test-contrib-check-code.t @ 34384: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 | 24849d53697d |
children | e223c0438f89 |
line wrap: on
line diff
--- a/tests/test-contrib-check-code.t Sat Sep 30 07:45:18 2017 -0400 +++ b/tests/test-contrib-check-code.t Fri Sep 29 11:55:44 2017 -0400 @@ -285,11 +285,43 @@ > ''' "%-6d \n 123456 .:*+-= foobar") > EOF +superfluous pass + + $ cat > superfluous_pass.py <<EOF + > # 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 @@ 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]