From 544b8d24649b5b58c1e370fc01b9f9e70357a4b8 Mon Sep 17 00:00:00 2001 From: Colin McMillen Date: Tue, 25 Feb 2020 20:42:55 -0500 Subject: [PATCH] lint: print # errors and return 1 if any errors found GitOrigin-RevId: bab4a38d64540385b1a4dc509ba8ffc48feb9293 --- tools/scripts/lint.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/scripts/lint.py b/tools/scripts/lint.py index 9bd054f..9ebc335 100644 --- a/tools/scripts/lint.py +++ b/tools/scripts/lint.py @@ -19,12 +19,16 @@ FILES_TO_EXCLUDE = [ 'Shared/Levels.cs'] +num_errors = 0 + + def emit_error(filename, line_num, error): + global num_errors + num_errors += 1 print('%s:%d: %s' % (filename, line_num, error)) def lint_csharp(filename): - errors = [] with open(filename) as f: for i, line in enumerate(f): line_num = i + 1 @@ -57,11 +61,17 @@ def main(args): # Remove generated files (of which there's lots). for exclusion_pattern in FILES_TO_EXCLUDE: csharp_files = [x for x in csharp_files if exclusion_pattern not in x] - print('checking %d files' % len(csharp_files)) for filename in csharp_files: lint_csharp(filename) + print('checked %d files and found %d errors' % ( + len(csharp_files), num_errors)) + + if num_errors: + return 1 + return 0 + if __name__ == '__main__': - main(sys.argv[1:]) + sys.exit(main(sys.argv[1:]))