check-code: add --nolineno option for hiding line numbers
authorMads Kiilerich <mads@kiilerich.com>
Fri, 11 Nov 2011 01:25:47 +0100
changeset 15502 7917a104a285
parent 15501 2371f4aea665
child 15503 eb5ed02d8743
check-code: add --nolineno option for hiding line numbers This makes the output more stable when it is used as a whitelist.
contrib/check-code.py
tests/test-check-code.t
--- a/contrib/check-code.py	Wed Nov 16 18:04:19 2011 -0600
+++ b/contrib/check-code.py	Fri Nov 11 01:25:47 2011 +0100
@@ -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)
--- a/tests/test-check-code.t	Wed Nov 16 18:04:19 2011 -0600
+++ b/tests/test-check-code.t	Fri Nov 11 01:25:47 2011 +0100
@@ -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]