-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
example-lint
executable file
·69 lines (56 loc) · 1.83 KB
/
example-lint
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
#!/usr/bin/env python3
import argparse
import sys
from typing import List
from zulint.command import LinterConfig, add_default_linter_arguments
from zulint.custom_rules import RuleList
def run() -> None:
parser = argparse.ArgumentParser()
# Add custom parser arguments here.
add_default_linter_arguments(parser)
args = parser.parse_args()
linter_config = LinterConfig(args)
# Linters will be run on these file types.
# eg: file_types = ['py', 'html', 'css', 'js']
file_types = ["py"]
excluded_files: List[str] = [
# No linters will be run on files in this list.
# eg: 'path/to/file.py'
]
by_lang = linter_config.list_files(file_types, exclude=excluded_files)
linter_config.external_linter(
"mypy",
[sys.executable, "tools/run-mypy"],
["py"],
pass_targets=False,
description="Static type checker for Python",
)
linter_config.external_linter(
"ruff",
["ruff", "check", "--quiet"],
["py"],
fix_arg="--fix",
description="Python linter",
)
linter_config.external_linter(
"ruff-format",
["ruff", "format", "--quiet"],
["py"],
check_arg="--check",
description="Python linter",
)
@linter_config.lint
def check_custom_rules() -> int:
"""Check trailing whitespace for specified files"""
trailing_whitespace_rule = RuleList(
langs=file_types,
rules=[
{"pattern": r"[\t ]+$", "description": "Fix trailing whitespace"},
{"pattern": r"[^\n]\Z", "description": "Missing trailing newline"},
],
)
failed = trailing_whitespace_rule.check(by_lang, verbose=args.verbose)
return 1 if failed else 0
linter_config.do_lint()
if __name__ == "__main__":
run()