lintChanges.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/usr/bin/python
  2. import sys
  3. import re
  4. def lintfile(fname):
  5. have_warned = []
  6. def warn(s):
  7. if not have_warned:
  8. have_warned.append(1)
  9. print fname,":"
  10. print "\t",s
  11. m = re.search(r'(\d{3,})', fname)
  12. if m:
  13. bugnum = m.group(1)
  14. else:
  15. bugnum = None
  16. with open(fname) as f:
  17. contents = f.read()
  18. if bugnum and bugnum not in contents:
  19. warn("bug number %s does not appear"%bugnum)
  20. lines = contents.split("\n")
  21. isBug = ("bug" in lines[0] or "fix" in lines[0])
  22. if not re.match(r'^ +o (.*)', contents):
  23. warn("header not in format expected")
  24. contents = " ".join(contents.split())
  25. if re.search(r'\#\d{2,}', contents):
  26. warn("don't use a # before ticket numbers")
  27. if isBug and not re.search(r'(\d+)', contents):
  28. warn("bugfix does not mention a number")
  29. elif isBug and not re.search(r'Fixes ([a-z ]*)bug (\d+)', contents):
  30. warn("bugfix does not say 'Fixes bug XXX'")
  31. if re.search(r'[bB]ug (\d+)', contents):
  32. if not re.search(r'[Bb]ugfix on ', contents):
  33. warn("bugfix does not say 'bugfix on X.Y.Z'")
  34. elif not re.search('[fF]ixes ([a-z ]*)bug (\d+); bugfix on ', contents):
  35. warn("bugfix incant is not semicoloned")
  36. if __name__=='__main__':
  37. for fname in sys.argv[1:]:
  38. if fname.endswith("~"):
  39. continue
  40. lintfile(fname)