2020-04-03 05:11:02 -04:00
|
|
|
#! /usr/bin/env python3
|
2017-07-06 18:56:46 -04:00
|
|
|
|
2019-08-02 00:10:06 -04:00
|
|
|
import argparse
|
2021-03-02 03:52:12 -05:00
|
|
|
import sys
|
2019-08-02 00:10:06 -04:00
|
|
|
|
2021-05-28 05:00:04 -04:00
|
|
|
from zulint.command import LinterConfig, add_default_linter_arguments
|
2017-07-06 18:56:46 -04:00
|
|
|
|
2021-05-28 05:00:04 -04:00
|
|
|
from custom_check import non_py_rules, python_rules
|
2017-07-06 18:56:46 -04:00
|
|
|
|
|
|
|
EXCLUDED_FILES = [
|
|
|
|
# This is an external file that doesn't comply with our codestyle
|
2021-05-28 05:05:11 -04:00
|
|
|
"zulip/integrations/perforce/git_p4.py",
|
2017-07-06 18:56:46 -04:00
|
|
|
]
|
|
|
|
|
2021-05-28 05:03:46 -04:00
|
|
|
|
2020-04-18 18:59:12 -04:00
|
|
|
def run() -> None:
|
2019-08-02 00:10:06 -04:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
add_default_linter_arguments(parser)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
linter_config = LinterConfig(args)
|
|
|
|
|
2021-05-28 05:03:46 -04:00
|
|
|
by_lang = linter_config.list_files(
|
2021-05-28 05:05:11 -04:00
|
|
|
file_types=["py", "sh", "json", "md", "txt"], exclude=EXCLUDED_FILES
|
2021-05-28 05:03:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
linter_config.external_linter(
|
2021-05-28 05:05:11 -04:00
|
|
|
"mypy",
|
|
|
|
[sys.executable, "tools/run-mypy"],
|
|
|
|
["py"],
|
2021-05-28 05:03:46 -04:00
|
|
|
pass_targets=False,
|
|
|
|
description="Static type checker for Python (config: mypy.ini)",
|
|
|
|
)
|
|
|
|
linter_config.external_linter(
|
2021-05-28 05:05:11 -04:00
|
|
|
"flake8", ["flake8"], ["py"], description="Standard Python linter (config: .flake8)"
|
2021-05-28 05:03:46 -04:00
|
|
|
)
|
|
|
|
linter_config.external_linter(
|
2021-05-28 05:05:11 -04:00
|
|
|
"gitlint", ["tools/lint-commits"], description="Git Lint for commit messages"
|
2021-05-28 05:03:46 -04:00
|
|
|
)
|
2021-05-28 05:06:00 -04:00
|
|
|
linter_config.external_linter(
|
|
|
|
"isort",
|
|
|
|
["isort"],
|
|
|
|
["py"],
|
|
|
|
description="Sorts Python import statements",
|
|
|
|
check_arg=["--check-only", "--diff"],
|
|
|
|
)
|
2021-02-24 23:13:09 -05:00
|
|
|
|
2019-08-02 00:10:06 -04:00
|
|
|
@linter_config.lint
|
2020-04-18 18:59:12 -04:00
|
|
|
def custom_py() -> int:
|
2019-08-02 00:10:06 -04:00
|
|
|
"""Runs custom checks for python files (config: tools/linter_lib/custom_check.py)"""
|
|
|
|
failed = python_rules.check(by_lang, verbose=args.verbose)
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
|
|
|
@linter_config.lint
|
2020-04-18 18:59:12 -04:00
|
|
|
def custom_nonpy() -> int:
|
2019-08-02 00:10:06 -04:00
|
|
|
"""Runs custom checks for non-python files (config: tools/linter_lib/custom_check.py)"""
|
|
|
|
failed = False
|
|
|
|
for rule in non_py_rules:
|
|
|
|
failed = failed or rule.check(by_lang, verbose=args.verbose)
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
|
|
|
linter_config.do_lint()
|
2017-07-06 18:56:46 -04:00
|
|
|
|
2021-05-28 05:03:46 -04:00
|
|
|
|
2021-05-28 05:05:11 -04:00
|
|
|
if __name__ == "__main__":
|
2017-07-06 18:56:46 -04:00
|
|
|
run()
|