Debian Codegraph @

python/mozlint/test/linters/global_payload.py

raw
1 # This Source Code Form is subject to the terms of the Mozilla Public
2 # License, v. 2.0. If a copy of the MPL was not distributed with this
3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 import mozpack.path as mozpath
6 from external import external
7 from mozpack.files import FileFinder
8
9 from mozlint import result
10
11
12 def global_payload(_paths, config, **lintargs):
13 # A global linter that runs the external linter to actually lint.
14 finder = FileFinder(lintargs["root"])
15 files = [mozpath.join(lintargs["root"], p) for p, _ in finder.find("files/**")]
16 issues = external(files, config, **lintargs)
17 for issue in issues:
18 # Make issue look like it comes from this linter.
19 issue.linter = "global_payload"
20 return issues
21
22
23 def global_skipped(config, **lintargs):
24 # A global linter that always registers a lint error. Absence of
25 # this error shows that the path exclusion mechanism can cause
26 # global lint payloads to not be invoked at all. In particular,
27 # the `extensions` field means that nothing under `files/**` will
28 # match.
29
30 finder = FileFinder(lintargs["root"])
31 files = [mozpath.join(lintargs["root"], p) for p, _ in finder.find("files/**")]
32
33 issues = []
34 issues.append(
35 result.from_config(
36 config, path=files[0], lineno=1, column=1, rule="not-skipped"
37 )
38 )