utils/check-package: warn about utf-8 characters in .mk files
authorPeter Seiderer <ps.report@gmx.net>
Wed, 8 May 2019 17:34:27 +0000 (19:34 +0200)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Sat, 18 May 2019 21:34:59 +0000 (23:34 +0200)
Signed-off-by: Peter Seiderer <ps.report@gmx.net>
Tested-by: Titouan Christophe <titouan.christophe@railnova.eu>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
utils/checkpackagelib/lib.py
utils/checkpackagelib/lib_mk.py

index 6afe1aabce47192f85e4f0cccb12387fb9d28d9f..c65a2ed93968d3214d70f7f100cddc4da0fb5f3f 100644 (file)
@@ -52,3 +52,16 @@ class TrailingSpace(_CheckFunction):
             return ["{}:{}: line contains trailing whitespace"
                     .format(self.filename, lineno),
                     text]
+
+class Utf8Characters(_CheckFunction):
+    def is_ascii(self, s):
+        try:
+            return all(ord(c) < 128 for c in s)
+        except TypeError:
+            return False
+
+    def check_line(self, lineno, text):
+        if not self.is_ascii(text):
+            return ["{}:{}: line contains UTF-8 characters"
+                    .format(self.filename, lineno),
+                    text]
index 00efeb7fb285f2e4540a1179078eac387935e16e..9e9a045776588a6af00b0a5de9444db3b8114985 100644 (file)
@@ -11,6 +11,7 @@ from checkpackagelib.lib import ConsecutiveEmptyLines  # noqa: F401
 from checkpackagelib.lib import EmptyLastLine          # noqa: F401
 from checkpackagelib.lib import NewlineAtEof           # noqa: F401
 from checkpackagelib.lib import TrailingSpace          # noqa: F401
+from checkpackagelib.lib import Utf8Characters         # noqa: F401
 
 # used in more than one check
 start_conditional = ["ifdef", "ifeq", "ifndef", "ifneq"]