2017-07-06 18:56:46 -04:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
2019-08-02 00:10:06 -04:00
|
|
|
from __future__ import print_function
|
|
|
|
from __future__ import absolute_import
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
from zulint.command import add_default_linter_arguments, LinterConfig
|
2017-07-06 18:56:46 -04:00
|
|
|
|
2019-08-02 00:10:06 -04:00
|
|
|
from custom_check import python_rules, non_py_rules
|
|
|
|
from pep8 import check_pep8
|
2017-07-06 18:56:46 -04:00
|
|
|
|
|
|
|
EXCLUDED_FILES = [
|
|
|
|
# This is an external file that doesn't comply with our codestyle
|
2017-07-18 00:19:51 -04:00
|
|
|
'zulip/integrations/perforce/git_p4.py',
|
2017-07-06 18:56:46 -04:00
|
|
|
]
|
|
|
|
|
|
|
|
def run():
|
|
|
|
# type: () -> 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)
|
|
|
|
|
|
|
|
by_lang = linter_config.list_files(file_types=['py', 'sh', 'json', 'md', 'txt'],
|
|
|
|
exclude=EXCLUDED_FILES)
|
|
|
|
|
|
|
|
@linter_config.lint
|
|
|
|
def custom_py():
|
|
|
|
# type: () -> int
|
|
|
|
"""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
|
|
|
|
def custom_nonpy():
|
|
|
|
# type: () -> int
|
|
|
|
"""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.lint
|
|
|
|
def pep8():
|
|
|
|
# type: () -> int
|
|
|
|
"""Standard Python style linter on 50% of files (config: tools/linter_lib/pep8.py)"""
|
|
|
|
failed = check_pep8(by_lang['py'])
|
|
|
|
return 1 if failed else 0
|
|
|
|
|
|
|
|
linter_config.do_lint()
|
2017-07-06 18:56:46 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
run()
|