Add whitespace check to code format test

This commit is contained in:
Eren Dogan 2022-07-22 18:22:40 +03:00
parent 64c72ee19d
commit 2a778dca82
1 changed files with 23 additions and 0 deletions

View File

@ -28,6 +28,7 @@ class code_format_test(openram_test):
continue continue
errors += check_file_format_tab(code) errors += check_file_format_tab(code)
errors += check_file_format_carriage(code) errors += check_file_format_carriage(code)
errors += check_file_format_whitespace(code)
for code in source_codes: for code in source_codes:
if re.search("gdsMill", code): if re.search("gdsMill", code):
@ -99,6 +100,28 @@ def check_file_format_carriage(file_name):
return len(key_positions) return len(key_positions)
def check_file_format_whitespace(file_name):
"""
Check if file contains a line with whitespace at the end
and return the number of these lines.
"""
f = open(file_name, "r")
key_positions = []
for num, line in enumerate(f.readlines()):
if re.match(r".*[ \t]$", line):
key_positions.append(num)
if len(key_positions) > 0:
if len(key_positions) > 10:
line_numbers = key_positions[:10] + [" ..."]
else:
line_numbers = key_positions
debug.info(0, "\nFound " + str(len(key_positions)) + " ending whitespace in " +
str(file_name) + " (lines " + ",".join(str(x) for x in line_numbers) + ")")
f.close()
return len(key_positions)
def check_print_output(file_name): def check_print_output(file_name):
"""Check if any files (except debug.py) call the _print_ function. We should """Check if any files (except debug.py) call the _print_ function. We should
use the debug output with verbosity instead!""" use the debug output with verbosity instead!"""