utils/check-package: allow to disable warning for a line
authorRicardo Martincoski <ricardo.martincoski@gmail.com>
Sun, 27 Jan 2019 18:59:41 +0000 (16:59 -0200)
committerPeter Korsgaard <peter@korsgaard.com>
Tue, 29 Jan 2019 15:37:47 +0000 (16:37 +0100)
Currently any exceptions for a check function need to be coded into the
check-package script itself.

Create a pattern that can be used in a comment to make check-package
ignore one or more warning types in the line immediately below:
 # check-package Indent, VariableWithBraces

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Reviewed-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
utils/check-package
utils/checkpackagelib/base.py

index 26439f08ebcd6024a0ddddec8654cb0c3138a8ee..ce1fe98d67c54d757c377b94414ee4f5b28cdf8d 100755 (executable)
@@ -132,10 +132,14 @@ def check_file_using_lib(fname):
         f = open(fname, "r", errors="surrogateescape")
     else:
         f = open(fname, "r")
+    lastline = ""
     for lineno, text in enumerate(f.readlines()):
         nlines += 1
         for cf in objects:
+            if cf.disable.search(lastline):
+                continue
             nwarnings += print_warnings(cf.check_line(lineno + 1, text))
+        lastline = text
     f.close()
     for cf in objects:
         nwarnings += print_warnings(cf.after())
index fc09bec9a2ad7bf3afe06a994c58c31312e8ae24..9544a64e5af7c7d9174e223ffbe360aef37ab569 100644 (file)
@@ -1,10 +1,12 @@
 # See utils/checkpackagelib/readme.txt before editing this file.
+import re
 
 
 class _CheckFunction(object):
     def __init__(self, filename, url_to_manual):
         self.filename = filename
         self.url_to_manual = url_to_manual
+        self.disable = re.compile(r"^\s*# check-package .*\b{}\b".format(self.__class__.__name__))
 
     def before(self):
         pass