Mercurial > public > mercurial-scm > hg
comparison contrib/check-code.py @ 15502:7917a104a285
check-code: add --nolineno option for hiding line numbers
This makes the output more stable when it is used as a whitelist.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Fri, 11 Nov 2011 01:25:47 +0100 |
parents | 1470f8b00694 |
children | 53ef627cda30 |
comparison
equal
deleted
inserted
replaced
15501:2371f4aea665 | 15502:7917a104a285 |
---|---|
300 user, rev = start.split() | 300 user, rev = start.split() |
301 lines.append((line[1:-1], user, rev)) | 301 lines.append((line[1:-1], user, rev)) |
302 return lines | 302 return lines |
303 | 303 |
304 def checkfile(f, logfunc=_defaultlogger.log, maxerr=None, warnings=False, | 304 def checkfile(f, logfunc=_defaultlogger.log, maxerr=None, warnings=False, |
305 blame=False, debug=False): | 305 blame=False, debug=False, lineno=True): |
306 """checks style and portability of a given file | 306 """checks style and portability of a given file |
307 | 307 |
308 :f: filepath | 308 :f: filepath |
309 :logfunc: function used to report error | 309 :logfunc: function used to report error |
310 logfunc(filename, linenumber, linecontent, errormessage) | 310 logfunc(filename, linenumber, linecontent, errormessage) |
383 blamecache = getblame(f) | 383 blamecache = getblame(f) |
384 if n < len(blamecache): | 384 if n < len(blamecache): |
385 bl, bu, br = blamecache[n] | 385 bl, bu, br = blamecache[n] |
386 if bl == l: | 386 if bl == l: |
387 bd = '%s@%s' % (bu, br) | 387 bd = '%s@%s' % (bu, br) |
388 errors.append((f, n + 1, l, msg, bd)) | 388 errors.append((f, lineno and n + 1, l, msg, bd)) |
389 result = False | 389 result = False |
390 | 390 |
391 errors.sort() | 391 errors.sort() |
392 for e in errors: | 392 for e in errors: |
393 logfunc(*e) | 393 logfunc(*e) |
406 help="max warnings per file") | 406 help="max warnings per file") |
407 parser.add_option("-b", "--blame", action="store_true", | 407 parser.add_option("-b", "--blame", action="store_true", |
408 help="use annotate to generate blame info") | 408 help="use annotate to generate blame info") |
409 parser.add_option("", "--debug", action="store_true", | 409 parser.add_option("", "--debug", action="store_true", |
410 help="show debug information") | 410 help="show debug information") |
411 | 411 parser.add_option("", "--nolineno", action="store_false", |
412 parser.set_defaults(per_file=15, warnings=False, blame=False, debug=False) | 412 dest='lineno', help="don't show line numbers") |
413 | |
414 parser.set_defaults(per_file=15, warnings=False, blame=False, debug=False, | |
415 lineno=True) | |
413 (options, args) = parser.parse_args() | 416 (options, args) = parser.parse_args() |
414 | 417 |
415 if len(args) == 0: | 418 if len(args) == 0: |
416 check = glob.glob("*") | 419 check = glob.glob("*") |
417 else: | 420 else: |
418 check = args | 421 check = args |
419 | 422 |
420 for f in check: | 423 for f in check: |
421 ret = 0 | 424 ret = 0 |
422 if not checkfile(f, maxerr=options.per_file, warnings=options.warnings, | 425 if not checkfile(f, maxerr=options.per_file, warnings=options.warnings, |
423 blame=options.blame, debug=options.debug): | 426 blame=options.blame, debug=options.debug, |
427 lineno=options.lineno): | |
424 ret = 1 | 428 ret = 1 |
425 sys.exit(ret) | 429 sys.exit(ret) |