lib.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # See utils/checkpackagelib/readme.txt before editing this file.
  2. from checkpackagelib.base import _CheckFunction
  3. class ConsecutiveEmptyLines(_CheckFunction):
  4. def before(self):
  5. self.lastline = "non empty"
  6. def check_line(self, lineno, text):
  7. if text.strip() == "" == self.lastline.strip():
  8. return ["{}:{}: consecutive empty lines"
  9. .format(self.filename, lineno)]
  10. self.lastline = text
  11. class EmptyLastLine(_CheckFunction):
  12. def before(self):
  13. self.lastlineno = 0
  14. self.lastline = "non empty"
  15. def check_line(self, lineno, text):
  16. self.lastlineno = lineno
  17. self.lastline = text
  18. def after(self):
  19. if self.lastline.strip() == "":
  20. return ["{}:{}: empty line at end of file"
  21. .format(self.filename, self.lastlineno)]
  22. class NewlineAtEof(_CheckFunction):
  23. def before(self):
  24. self.lastlineno = 0
  25. self.lastline = "\n"
  26. def check_line(self, lineno, text):
  27. self.lastlineno = lineno
  28. self.lastline = text
  29. def after(self):
  30. if self.lastline == self.lastline.rstrip("\r\n"):
  31. return ["{}:{}: missing newline at end of file"
  32. .format(self.filename, self.lastlineno),
  33. self.lastline]
  34. class TrailingSpace(_CheckFunction):
  35. def check_line(self, lineno, text):
  36. line = text.rstrip("\r\n")
  37. if line != line.rstrip():
  38. return ["{}:{}: line contains trailing whitespace"
  39. .format(self.filename, lineno),
  40. text]