lintChanges.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. contents = " ".join(contents.split())
  23. if isBug and not re.search(r'(\d+)', contents):
  24. warn("bugfix does not mention a number")
  25. elif isBug and not re.search(r'Fixes ([a-z ]*)bug (\d+)', contents):
  26. warn("bugfix does not say 'Fixes bug XXX'")
  27. if re.search(r'[bB]ug (\d+)', contents):
  28. if not re.search(r'[Bb]ugfix on ', contents):
  29. warn("bugfix does not say 'bugfix on X.Y.Z'")
  30. elif not re.search('[fF]ixes ([a-z ]*)bug (\d+); bugfix on ', contents):
  31. warn("bugfix incant is not semicoloned")
  32. if __name__=='__main__':
  33. for fname in sys.argv[1:]:
  34. if fname.endswith("~"):
  35. continue
  36. lintfile(fname)