wpt.lint 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. import json
  6. import os
  7. from mozprocess import ProcessHandler
  8. from mozlint import result
  9. top_src_dir = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)
  10. tests_dir = os.path.join(top_src_dir, "testing", "web-platform", "tests")
  11. results = []
  12. def process_line(line):
  13. try:
  14. data = json.loads(line)
  15. except ValueError:
  16. return
  17. data["level"] = "error"
  18. data["path"] = os.path.relpath(os.path.join(tests_dir, data["path"]), top_src_dir)
  19. results.append(result.from_linter(LINTER, **data))
  20. def run_process():
  21. path = os.path.join(tests_dir, "lint")
  22. proc = ProcessHandler([path, "--json"], env=os.environ,
  23. processOutputLine=process_line)
  24. proc.run()
  25. try:
  26. proc.wait()
  27. except KeyboardInterrupt:
  28. proc.kill()
  29. def lint(files, **kwargs):
  30. run_process()
  31. return results
  32. LINTER = {
  33. 'name': "wpt",
  34. 'description': "web-platform-tests lint",
  35. 'include': [
  36. 'testing/web-platform/tests',
  37. ],
  38. 'exclude': [],
  39. 'type': 'external',
  40. 'payload': lint,
  41. }