-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmdlint
executable file
·81 lines (58 loc) · 1.8 KB
/
mdlint
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
# Copyright 2020 The ChromiumOS Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Run markdownlint with our settings."""
from pathlib import Path
import sys
import libdot
def filter_known_files(paths: list[Path]) -> list[Path]:
"""Figure out what files this linter supports."""
ret = []
for path in paths:
path = Path(path)
if path.suffix[1:] in {"md"}:
ret += [path]
return [str(x) for x in ret]
def setup():
"""Initialize the tool settings."""
libdot.node_and_npm_setup()
def run(argv=(), **kwargs):
"""Run the tool directly."""
setup()
return libdot.node.run(["markdownlint"] + list(argv), **kwargs)
def perform(
argv=(), paths=(), fix=False, gerrit_comments_file=None
): # pylint: disable=unused-argument
"""Run high level tool logic."""
argv = list(argv)
paths = list(paths)
if fix:
argv += ["--fix"]
# TODO(vapier): Add support for Gerrit comments.
result = run(argv + paths, check=False)
return result.returncode == 0
def get_parser():
"""Get a command line parser."""
parser = libdot.ArgumentParser(description=__doc__, short_options=False)
parser.add_argument(
"--gerrit-comments-file",
help="Save errors for posting files to Gerrit.",
)
parser.add_argument("paths", nargs="*", help="Paths to lint.")
return parser
def main(argv):
"""The main func!"""
parser = get_parser()
opts, args = parser.parse_known_args(argv)
return (
0
if perform(
argv=args,
paths=opts.paths,
gerrit_comments_file=opts.gerrit_comments_file,
)
else 1
)
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))