Browse Source

utils/check-package: warn about utf-8 characters in .mk files

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>
Peter Seiderer 6 years ago
parent
commit
8e352c32b0
2 changed files with 14 additions and 0 deletions
  1. 13 0
      utils/checkpackagelib/lib.py
  2. 1 0
      utils/checkpackagelib/lib_mk.py

+ 13 - 0
utils/checkpackagelib/lib.py

@@ -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]

+ 1 - 0
utils/checkpackagelib/lib_mk.py

@@ -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"]