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.

61 lines
1.6 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.search(r'\t', line):
  27. emit_error(filename, line_num, 'illegal \\t character')
  28. if re.search(r'\r', line):
  29. emit_error(filename, line_num, 'illegal \\r character')
  30. if re.search(r'\s+$', line):
  31. emit_error(filename, line_num, 'trailing whitespace')
  32. if re.match(r'\s*//\S', line):
  33. emit_error(filename, line_num, 'no space between // and comment')
  34. def main(args):
  35. this_dir = os.path.dirname(os.path.realpath(__file__))
  36. sneak_root = os.path.join(this_dir, '..', '..')
  37. os.chdir(sneak_root)
  38. csharp_files = sorted(glob.glob('**/*.cs', recursive=True))
  39. # Remove generated files (of which there's lots).
  40. for exclusion_pattern in FILES_TO_EXCLUDE:
  41. csharp_files = [x for x in csharp_files if exclusion_pattern not in x]
  42. print('checking %d files' % len(csharp_files))
  43. for filename in csharp_files:
  44. lint_csharp(filename)
  45. if __name__ == '__main__':
  46. main(sys.argv[1:])