Show More
@@ -231,7 +231,8 b' utestfilters = [' | |||
|
231 | 231 | (r"( +)(#([^!][^\n]*\S)?)", repcomment), |
|
232 | 232 | ] |
|
233 | 233 | |
|
234 | pypats = [ | |
|
234 | # common patterns to check *.py | |
|
235 | commonpypats = [ | |
|
235 | 236 | [ |
|
236 | 237 | (r'\\$', 'Use () to wrap long lines in Python, not \\'), |
|
237 | 238 | (r'^\s*def\s*\w+\s*\(.*,\s*\(', |
@@ -262,7 +263,6 b' pypats = [' | |||
|
262 | 263 | # a pass at the same indent level, which is bogus |
|
263 | 264 | r'(?P=indent)pass[ \t\n#]' |
|
264 | 265 | ), 'omit superfluous pass'), |
|
265 | (r'.{81}', "line too long"), | |
|
266 | 266 | (r'[^\n]\Z', "no trailing newline"), |
|
267 | 267 | (r'(\S[ \t]+|^[ \t]+)\n', "trailing whitespace"), |
|
268 | 268 | # (r'^\s+[^_ \n][^_. \n]+_[^_\n]+\s*=', |
@@ -300,7 +300,6 b' pypats = [' | |||
|
300 | 300 | "wrong whitespace around ="), |
|
301 | 301 | (r'\([^()]*( =[^=]|[^<>!=]= )', |
|
302 | 302 | "no whitespace around = for named parameters"), |
|
303 | (r'raise Exception', "don't raise generic exceptions"), | |
|
304 | 303 | (r'raise [^,(]+, (\([^\)]+\)|[^,\(\)]+)$', |
|
305 | 304 | "don't use old-style two-argument raise, use Exception(message)"), |
|
306 | 305 | (r' is\s+(not\s+)?["\'0-9-]', "object comparison with literal"), |
@@ -316,21 +315,12 b' pypats = [' | |||
|
316 | 315 | "use opener.read() instead"), |
|
317 | 316 | (r'opener\([^)]*\).write\(', |
|
318 | 317 | "use opener.write() instead"), |
|
319 | (r'[\s\(](open|file)\([^)]*\)\.read\(', | |
|
320 | "use util.readfile() instead"), | |
|
321 | (r'[\s\(](open|file)\([^)]*\)\.write\(', | |
|
322 | "use util.writefile() instead"), | |
|
323 | (r'^[\s\(]*(open(er)?|file)\([^)]*\)(?!\.close\(\))', | |
|
324 | "always assign an opened file to a variable, and close it afterwards"), | |
|
325 | (r'[\s\(](open|file)\([^)]*\)\.(?!close\(\))', | |
|
326 | "always assign an opened file to a variable, and close it afterwards"), | |
|
327 | 318 | (r'(?i)descend[e]nt', "the proper spelling is descendAnt"), |
|
328 | 319 | (r'\.debug\(\_', "don't mark debug messages for translation"), |
|
329 | 320 | (r'\.strip\(\)\.split\(\)', "no need to strip before splitting"), |
|
330 | 321 | (r'^\s*except\s*:', "naked except clause", r'#.*re-raises'), |
|
331 | 322 | (r'^\s*except\s([^\(,]+|\([^\)]+\))\s*,', |
|
332 | 323 | 'legacy exception syntax; use "as" instead of ","'), |
|
333 | (r':\n( )*( ){1,3}[^ ]', "must indent 4 spaces"), | |
|
334 | 324 | (r'release\(.*wlock, .*lock\)', "wrong lock release order"), |
|
335 | 325 | (r'\bdef\s+__bool__\b', "__bool__ should be __nonzero__ in Python 2"), |
|
336 | 326 | (r'os\.path\.join\(.*, *(""|\'\')\)', |
@@ -340,7 +330,6 b' pypats = [' | |||
|
340 | 330 | (r'def.*[( ]\w+=\{\}', "don't use mutable default arguments"), |
|
341 | 331 | (r'\butil\.Abort\b', "directly use error.Abort"), |
|
342 | 332 | (r'^@(\w*\.)?cachefunc', "module-level @cachefunc is risky, please avoid"), |
|
343 | (r'^import atexit', "don't use atexit, use ui.atexit"), | |
|
344 | 333 | (r'^import Queue', "don't use Queue, use pycompat.queue.Queue + " |
|
345 | 334 | "pycompat.queue.Empty"), |
|
346 | 335 | (r'^import cStringIO', "don't use cStringIO.StringIO, use util.stringio"), |
@@ -359,6 +348,34 b' pypats = [' | |||
|
359 | 348 | "don't convert rev to node before passing to revision(nodeorrev)"), |
|
360 | 349 | (r'platform\.system\(\)', "don't use platform.system(), use pycompat"), |
|
361 | 350 | |
|
351 | ], | |
|
352 | # warnings | |
|
353 | [ | |
|
354 | ] | |
|
355 | ] | |
|
356 | ||
|
357 | # patterns to check normal *.py files | |
|
358 | pypats = [ | |
|
359 | [ | |
|
360 | # Ideally, these should be placed in "commonpypats" for | |
|
361 | # consistency of coding rules in Mercurial source tree. | |
|
362 | # But on the other hand, these are not so seriously required for | |
|
363 | # python code fragments embedded in test scripts. Fixing test | |
|
364 | # scripts for these patterns requires many changes, and has less | |
|
365 | # profit than effort. | |
|
366 | (r'.{81}', "line too long"), | |
|
367 | (r'raise Exception', "don't raise generic exceptions"), | |
|
368 | (r'[\s\(](open|file)\([^)]*\)\.read\(', | |
|
369 | "use util.readfile() instead"), | |
|
370 | (r'[\s\(](open|file)\([^)]*\)\.write\(', | |
|
371 | "use util.writefile() instead"), | |
|
372 | (r'^[\s\(]*(open(er)?|file)\([^)]*\)(?!\.close\(\))', | |
|
373 | "always assign an opened file to a variable, and close it afterwards"), | |
|
374 | (r'[\s\(](open|file)\([^)]*\)\.(?!close\(\))', | |
|
375 | "always assign an opened file to a variable, and close it afterwards"), | |
|
376 | (r':\n( )*( ){1,3}[^ ]', "must indent 4 spaces"), | |
|
377 | (r'^import atexit', "don't use atexit, use ui.atexit"), | |
|
378 | ||
|
362 | 379 | # rules depending on implementation of repquote() |
|
363 | 380 | (r' x+[xpqo%APM][\'"]\n\s+[\'"]x', |
|
364 | 381 | 'string join across lines with no space'), |
@@ -377,21 +394,26 b' pypats = [' | |||
|
377 | 394 | # because _preparepats forcibly adds "\n" into [^...], |
|
378 | 395 | # even though this regexp wants match it against "\n")''', |
|
379 | 396 | "missing _() in ui message (use () to hide false-positives)"), |
|
380 | ], | |
|
397 | ] + commonpypats[0], | |
|
381 | 398 | # warnings |
|
382 | 399 | [ |
|
383 | 400 | # rules depending on implementation of repquote() |
|
384 | 401 | (r'(^| )pp +xxxxqq[ \n][^\n]', "add two newlines after '.. note::'"), |
|
385 | ] | |
|
402 | ] + commonpypats[1] | |
|
386 | 403 | ] |
|
387 | 404 | |
|
388 | pyfilters = [ | |
|
405 | # common filters to convert *.py | |
|
406 | commonpyfilters = [ | |
|
389 | 407 | (r"""(?msx)(?P<comment>\#.*?$)| |
|
390 | 408 | ((?P<quote>('''|\"\"\"|(?<!')'(?!')|(?<!")"(?!"))) |
|
391 | 409 | (?P<text>(([^\\]|\\.)*?)) |
|
392 | 410 | (?P=quote))""", reppython), |
|
393 | 411 | ] |
|
394 | 412 | |
|
413 | # filters to convert normal *.py files | |
|
414 | pyfilters = [ | |
|
415 | ] + commonpyfilters | |
|
416 | ||
|
395 | 417 | # non-filter patterns |
|
396 | 418 | pynfpats = [ |
|
397 | 419 | [ |
General Comments 0
You need to be logged in to leave comments.
Login now