Exclude binary files from text checks
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/scripts/check-files.py b/tests/scripts/check-files.py
index 3992c46..b48f62b 100755
--- a/tests/scripts/check-files.py
+++ b/tests/scripts/check-files.py
@@ -92,6 +92,17 @@
logger.info(filename)
logger.info("")
+BINARY_FILE_PATH_RE_LIST = [
+ r'docs/.*\.pdf\Z',
+ r'programs/fuzz/corpuses/[^.]+\Z',
+ r'tests/data_files/[^.]+\Z',
+ r'tests/data_files/.*\.(crt|csr|db|der|key|pubkey)\Z',
+ r'tests/data_files/.*\.req\.[^/]+\Z',
+ r'tests/data_files/.*malformed[^/]+\Z',
+ r'tests/data_files/format_pkcs12\.fmt\Z',
+]
+BINARY_FILE_PATH_RE = re.compile('|'.join(BINARY_FILE_PATH_RE_LIST))
+
class LineIssueTracker(FileIssueTracker):
"""Base class for line-by-line issue tracking.
@@ -99,6 +110,9 @@
this class and implement `line_with_issue`.
"""
+ # Exclude binary files.
+ path_exemptions = BINARY_FILE_PATH_RE
+
def issue_with_line(self, line, filepath):
"""Check the specified line for the issue that this class is for.
@@ -145,6 +159,8 @@
heading = "Missing newline at end of file:"
+ path_exemptions = BINARY_FILE_PATH_RE
+
def check_file_for_issue(self, filepath):
with open(filepath, "rb") as f:
if not f.read().endswith(b"\n"):
@@ -158,6 +174,7 @@
heading = "UTF-8 BOM present:"
suffix_exemptions = frozenset([".vcxproj", ".sln"])
+ path_exemptions = BINARY_FILE_PATH_RE
def check_file_for_issue(self, filepath):
with open(filepath, "rb") as f: