A stealth-based 2D platformer where you don't have to kill anyone unless you want to. https://www.semicolin.games
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0 KiB

  1. #!/usr/bin/env python3
  2. import glob
  3. import os
  4. import re
  5. import sys
  6. MAX_LINE_LENGTH = 100
  7. # Files with any of these as a substring of their filename are excluded from
  8. # consideration.
  9. FILES_TO_EXCLUDE = [
  10. '/obj/',
  11. '/bin/',
  12. '/AssemblyInfo.cs',
  13. '/Resource.Designer.cs',
  14. 'Shared/Levels.cs']
  15. num_errors = 0
  16. def emit_error(filename, line_num, error):
  17. global num_errors
  18. num_errors += 1
  19. print('%s:%d: %s' % (filename, line_num, error))
  20. def lint_csharp(filename):
  21. with open(filename) as f:
  22. for i, line in enumerate(f):
  23. line_num = i + 1
  24. line = line[:-1] # Strip trailing newline.
  25. if len(line) > MAX_LINE_LENGTH:
  26. if not re.match(r'\s*// https?:', line):
  27. emit_error(filename, line_num, 'line too long')
  28. if re.match(r'\s*//\S', line):
  29. emit_error(filename, line_num, 'no space between // and comment')
  30. match = re.match(r'\s*const.* (\w+) =', line)
  31. if match:
  32. identifier = match.group(1)
  33. if not re.fullmatch(r'[A-Z_]+', identifier):
  34. emit_error(filename, line_num,
  35. 'const field %s should be in ALL_CAPS' % identifier)
  36. if re.search(r'\t', line):
  37. emit_error(filename, line_num, 'illegal \\t character')
  38. if re.search(r'\r', line):
  39. emit_error(filename, line_num, 'illegal \\r character')
  40. if re.search(r'\s+$', line):
  41. emit_error(filename, line_num, 'trailing whitespace')
  42. def main(args):
  43. this_dir = os.path.dirname(os.path.realpath(__file__))
  44. sneak_root = os.path.join(this_dir, '..', '..')
  45. os.chdir(sneak_root)
  46. csharp_files = sorted(glob.glob('**/*.cs', recursive=True))
  47. # Remove generated files (of which there's lots).
  48. for exclusion_pattern in FILES_TO_EXCLUDE:
  49. csharp_files = [x for x in csharp_files if exclusion_pattern not in x]
  50. for filename in csharp_files:
  51. lint_csharp(filename)
  52. print('lint.py checked %d files and found %d errors' % (
  53. len(csharp_files), num_errors))
  54. if num_errors:
  55. return 1
  56. return 0
  57. if __name__ == '__main__':
  58. sys.exit(main(sys.argv[1:]))