##// END OF EJS Templates
contrib: add a check to check-code to ban superfluous pass statements...
Augie Fackler -
r34383:b52f22d9 default
parent child Browse files
Show More
@@ -257,6 +257,16 b' pypats = ['
257 257 (r'(\w|\))[+/*\-<>]\w', "missing whitespace in expression"),
258 258 (r'^\s+(\w|\.)+=\w[^,()\n]*$', "missing whitespace in assignment"),
259 259 (r'\w\s=\s\s+\w', "gratuitous whitespace after ="),
260 ((
261 # a line ending with a colon, potentially with trailing comments
262 r':([ \t]*#[^\n]*)?\n'
263 # one that is not a pass and not only a comment
264 r'(?P<indent>[ \t]+)[^#][^\n]+\n'
265 # more lines at the same indent level
266 r'((?P=indent)[^\n]+\n)*'
267 # a pass at the same indent level, which is bogus
268 r'(?P=indent)pass[ \t\n#]'
269 ), 'omit superfluous pass'),
260 270 (r'.{81}', "line too long"),
261 271 (r'[^\n]\Z', "no trailing newline"),
262 272 (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"),
@@ -285,11 +285,43 b' web templates'
285 285 > ''' "%-6d \n 123456 .:*+-= foobar")
286 286 > EOF
287 287
288 superfluous pass
289
290 $ cat > superfluous_pass.py <<EOF
291 > # correct examples
292 > if foo:
293 > pass
294 > else:
295 > # comment-only line means still need pass
296 > pass
297 > def nothing():
298 > pass
299 > class empty(object):
300 > pass
301 > if whatever:
302 > passvalue(value)
303 > # bad examples
304 > if foo:
305 > "foo"
306 > pass
307 > else: # trailing comment doesn't fool checker
308 > wat()
309 > pass
310 > def nothing():
311 > "docstring means no pass"
312 > pass
313 > class empty(object):
314 > """multiline
315 > docstring also
316 > means no pass"""
317 > pass
318 > EOF
319
288 320 (Checking multiple invalid files at once examines whether caching
289 321 translation table for repquote() works as expected or not. All files
290 322 should break rules depending on result of repquote(), in this case)
291 323
292 $ "$check_code" stringjoin.py uigettext.py
324 $ "$check_code" stringjoin.py uigettext.py superfluous_pass.py
293 325 stringjoin.py:1:
294 326 > foo = (' foo'
295 327 string join across lines with no space
@@ -317,4 +349,16 b' should break rules depending on result o'
317 349 uigettext.py:1:
318 350 > ui.status("% 10s %05d % -3.2f %*s %%"
319 351 missing _() in ui message (use () to hide false-positives)
352 superfluous_pass.py:14:
353 > if foo:
354 omit superfluous pass
355 superfluous_pass.py:17:
356 > else: # trailing comment doesn't fool checker
357 omit superfluous pass
358 superfluous_pass.py:20:
359 > def nothing():
360 omit superfluous pass
361 superfluous_pass.py:23:
362 > class empty(object):
363 omit superfluous pass
320 364 [1]
General Comments 0
You need to be logged in to leave comments. Login now