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.

67 lines
1.9 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. def emit_error(filename, line_num, error):
  16. print('%s:%d: %s' % (filename, line_num, error))
  17. def lint_csharp(filename):
  18. errors = []
  19. with open(filename) as f:
  20. for i, line in enumerate(f):
  21. line_num = i + 1
  22. line = line[:-1] # Strip trailing newline.
  23. if len(line) > MAX_LINE_LENGTH:
  24. if not re.match(r'\s*// https?:', line):
  25. emit_error(filename, line_num, 'line too long')
  26. if re.match(r'\s*//\S', line):
  27. emit_error(filename, line_num, 'no space between // and comment')
  28. match = re.match(r'\s*const.* (\w+) =', line)
  29. if match:
  30. identifier = match.group(1)
  31. if not re.fullmatch(r'[A-Z_]+', identifier):
  32. emit_error(filename, line_num,
  33. 'const field %s should be in ALL_CAPS' % identifier)
  34. if re.search(r'\t', line):
  35. emit_error(filename, line_num, 'illegal \\t character')
  36. if re.search(r'\r', line):
  37. emit_error(filename, line_num, 'illegal \\r character')
  38. if re.search(r'\s+$', line):
  39. emit_error(filename, line_num, 'trailing whitespace')
  40. def main(args):
  41. this_dir = os.path.dirname(os.path.realpath(__file__))
  42. sneak_root = os.path.join(this_dir, '..', '..')
  43. os.chdir(sneak_root)
  44. csharp_files = sorted(glob.glob('**/*.cs', recursive=True))
  45. # Remove generated files (of which there's lots).
  46. for exclusion_pattern in FILES_TO_EXCLUDE:
  47. csharp_files = [x for x in csharp_files if exclusion_pattern not in x]
  48. print('checking %d files' % len(csharp_files))
  49. for filename in csharp_files:
  50. lint_csharp(filename)
  51. if __name__ == '__main__':
  52. main(sys.argv[1:])