1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 from mozlint
import result
17 def lint(files
, config
, **kwargs
):
19 tests_dir
= os
.path
.join(kwargs
["root"], "testing", "web-platform", "tests")
21 def process_line(line
):
23 data
= json
.loads(line
)
26 f
"Got non-JSON output: {line}",
31 data
["level"] = "error"
32 data
["path"] = os
.path
.relpath(
33 os
.path
.join(tests_dir
, data
["path"]), kwargs
["root"]
35 data
.setdefault("lineno", 0)
36 results
.append(result
.from_config(config
, **data
))
38 if files
== [tests_dir
]:
40 "No specific files specified, running the full wpt lint" " (this is slow)",
44 cmd
= ["python3", os
.path
.join(tests_dir
, "wpt"), "lint", "--json"] + files
45 log
.debug("Command: {}".format(" ".join(cmd
)))
47 proc
= subprocess
.Popen(
48 cmd
, env
=os
.environ
, stdout
=subprocess
.PIPE
, stderr
=subprocess
.STDOUT
, text
=True
51 for line
in proc
.stdout
:
52 process_line(line
.rstrip("\r\n"))
54 if proc
.returncode
!= 0:
58 message
="Lint process exited with return code %s" % proc
.returncode
,
61 except KeyboardInterrupt: