forked from zulip/zulint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-lint
executable file
·64 lines (51 loc) · 2.11 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
#!/usr/bin/env python3
import argparse
import sys
from typing import List, Tuple
from zulint.command import LinterConfig, add_default_linter_arguments
from zulint.custom_rules import RuleList
from zulint.linters import run_pyflakes
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 = [
# No linters will be run on files in this list.
# eg: 'path/to/file.py'
] # type: List[str]
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('isort', ['isort'], ['py'],
check_arg=['--check-only', '--diff'],
description="Sorts Python import statements")
@linter_config.lint
def check_custom_rules() -> int:
"""Check trailing whitespace for specified files"""
trailing_whitespace_rule = RuleList(
langs=file_types,
rules=[{
'pattern': r'\s+$',
'strip': '\n',
'description': 'Fix trailing whitespace'
}]
)
failed = trailing_whitespace_rule.check(by_lang, verbose=args.verbose)
return 1 if failed else 0
@linter_config.lint
def pyflakes() -> int:
suppress_patterns = [
# Error patters in this list will be will not be reported by the linter.
# syntax: ('File Path', 'Error message')
# eg: ('path/to/file.py', 'imported but unused')
] # type: List[Tuple[str, str]]
failed = run_pyflakes(by_lang['py'], args, suppress_patterns)
return 1 if failed else 0
linter_config.do_lint()
if __name__ == '__main__':
run()