lint: print # errors and return 1 if any errors found

GitOrigin-RevId: bab4a38d64540385b1a4dc509ba8ffc48feb9293
This commit is contained in:
Colin McMillen 2020-02-25 20:42:55 -05:00
parent 6b95a66859
commit 544b8d2464

View File

@ -19,12 +19,16 @@ FILES_TO_EXCLUDE = [
'Shared/Levels.cs'] 'Shared/Levels.cs']
num_errors = 0
def emit_error(filename, line_num, error): def emit_error(filename, line_num, error):
global num_errors
num_errors += 1
print('%s:%d: %s' % (filename, line_num, error)) print('%s:%d: %s' % (filename, line_num, error))
def lint_csharp(filename): def lint_csharp(filename):
errors = []
with open(filename) as f: with open(filename) as f:
for i, line in enumerate(f): for i, line in enumerate(f):
line_num = i + 1 line_num = i + 1
@ -57,11 +61,17 @@ def main(args):
# Remove generated files (of which there's lots). # Remove generated files (of which there's lots).
for exclusion_pattern in FILES_TO_EXCLUDE: for exclusion_pattern in FILES_TO_EXCLUDE:
csharp_files = [x for x in csharp_files if exclusion_pattern not in x] 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: for filename in csharp_files:
lint_csharp(filename) 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__': if __name__ == '__main__':
main(sys.argv[1:]) sys.exit(main(sys.argv[1:]))