rules.py 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import os
  2. import six
  3. def style_required(path, data, skip_links=True):
  4. if get_skip_reason(path, data, skip_links):
  5. return False
  6. return True
  7. def get_skip_reason(path, data, skip_links=True):
  8. return _path_skip_reason(path, skip_links) or _content_skip_reason(path, data)
  9. def _path_skip_reason(path, skip_links=True):
  10. if '/generated/' in path:
  11. return "path '{}' contains '/generated/'".format(path)
  12. if path and '/contrib/' in path:
  13. return "path '{}' contains '/contrib/'".format(path)
  14. if path and '/vendor/' in path:
  15. return "path '{}' contains '/vendor/'".format(path)
  16. if skip_links and os.path.islink(path):
  17. return "path '{}' is a symlink".format(path)
  18. def _content_skip_reason(path, data):
  19. if not isinstance(data, six.string_types):
  20. data = data.decode()
  21. for substr in [
  22. '# DO_NOT_STYLE',
  23. '// DO_NOT_STYLE',
  24. 'THIS SOFTWARE',
  25. 'WITHOUT WARRANTY',
  26. ]:
  27. if substr in data:
  28. return "file '{}' contains '{}'".format(path, substr)