check_whitespace: Enforce an 80 column limit on source code

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-02-27 14:19:15 -05:00
parent 1b064b5a5d
commit 5dc487faf9
1 changed files with 4 additions and 0 deletions

View File

@ -27,6 +27,7 @@ def check_file(filename):
# Empty files are okay # Empty files are okay
return return
# Do checks # Do checks
is_source_code = any([filename.endswith(s) for s in ['.c', '.h', '.py']])
lineno = 0 lineno = 0
for lineno, line in enumerate(data.split('\n')): for lineno, line in enumerate(data.split('\n')):
# Verify line is valid utf-8 # Verify line is valid utf-8
@ -49,6 +50,9 @@ def check_file(filename):
# Check for trailing space # Check for trailing space
if line.endswith(' '): if line.endswith(' '):
report_error(filename, lineno, "Line has trailing spaces") report_error(filename, lineno, "Line has trailing spaces")
# Check for more than 80 characters
if is_source_code and len(line) > 80:
report_error(filename, lineno, "Line longer than 80 characters")
if not data.endswith('\n'): if not data.endswith('\n'):
report_error(filename, lineno, "No newline at end of file") report_error(filename, lineno, "No newline at end of file")
if data.endswith('\n\n'): if data.endswith('\n\n'):