[PATCH 2 of 3] check-code: add --nolineno option for hiding line numbers
Mads Kiilerich
mads at kiilerich.com
Thu Nov 10 18:37:07 CST 2011
# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1320971147 -3600
# Node ID a67c7da6f7d062d5b8e6840c4c13a517b1f0bdcd
# Parent 48bbf3b5d220e2a80cf1812c9ffa5f56f28ae031
check-code: add --nolineno option for hiding line numbers
This makes the output more stable when it is used as a whitelist.
diff --git a/contrib/check-code.py b/contrib/check-code.py
--- a/contrib/check-code.py
+++ b/contrib/check-code.py
@@ -302,7 +302,7 @@
return lines
def checkfile(f, logfunc=_defaultlogger.log, maxerr=None, warnings=False,
- blame=False, debug=False):
+ blame=False, debug=False, lineno=True):
"""checks style and portability of a given file
:f: filepath
@@ -385,7 +385,7 @@
bl, bu, br = blamecache[n]
if bl == l:
bd = '%s@%s' % (bu, br)
- errors.append((f, n + 1, l, msg, bd))
+ errors.append((f, lineno and n + 1, l, msg, bd))
result = False
errors.sort()
@@ -408,8 +408,11 @@
help="use annotate to generate blame info")
parser.add_option("", "--debug", action="store_true",
help="show debug information")
+ parser.add_option("", "--nolineno", action="store_false",
+ dest='lineno', help="don't show line numbers")
- parser.set_defaults(per_file=15, warnings=False, blame=False, debug=False)
+ parser.set_defaults(per_file=15, warnings=False, blame=False, debug=False,
+ lineno=True)
(options, args) = parser.parse_args()
if len(args) == 0:
@@ -420,6 +423,7 @@
for f in check:
ret = 0
if not checkfile(f, maxerr=options.per_file, warnings=options.warnings,
- blame=options.blame, debug=options.debug):
+ blame=options.blame, debug=options.debug,
+ lineno=options.lineno):
ret = 1
sys.exit(ret)
diff --git a/tests/test-check-code.t b/tests/test-check-code.t
--- a/tests/test-check-code.t
+++ b/tests/test-check-code.t
@@ -132,3 +132,11 @@
object comparison with literal
[1]
+ $ cat > warning.py <<EOF
+ > except:
+ > EOF
+ $ "$check_code" warning.py --warning --nolineno
+ warning.py:0:
+ > except:
+ warning: naked except clause
+ [1]
More information about the Mercurial-devel
mailing list