From bd0fa3e77b2e66f034a720dea3ac96a06f635f46 Mon Sep 17 00:00:00 2001 From: Eklavya Sharma Date: Sun, 24 Jul 2016 18:07:56 +0530 Subject: [PATCH] Annotate tools/lint-all. --- tools/lint-all | 43 +++++++++++++++++++++++++++++-------------- tools/run-mypy | 1 - 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/tools/lint-all b/tools/lint-all index 618ca329c0..944302be7f 100755 --- a/tools/lint-all +++ b/tools/lint-all @@ -9,6 +9,7 @@ import subprocess import traceback try: import lister + from typing import cast, Any, Callable, Dict, List, Optional except ImportError as e: print("ImportError: {}".format(e)) print("You need to run the Zulip linters inside a Zulip dev environment.") @@ -50,9 +51,9 @@ puppet/apt/README.md static/locale """.split() -by_lang = lister.list_files(args, modified_only=options.modified, use_shebang=True, +by_lang = cast(Dict[str, List[str]], lister.list_files(args, modified_only=options.modified, ftypes=['py', 'sh', 'js', 'pp', 'css', 'handlebars', 'html', 'json', 'md', 'txt', 'text'], - group_by_ftype=True, exclude=exclude) + use_shebang=True, group_by_ftype=True, exclude=exclude)) # Invoke the appropriate lint checker for each language, # and also check files for extra whitespace. @@ -66,6 +67,7 @@ else: logger.setLevel(logging.WARNING) def check_pyflakes(): + # type: () -> bool if not by_lang['py']: return False failed = False @@ -92,7 +94,10 @@ def check_pyflakes(): failed = True return failed +RuleList = List[Dict[str, Any]] + def custom_check_file(fn, rules, skip_rules=None, max_length=None): + # type: (str, RuleList, Optional[Any], Optional[int]) -> bool failed = False lineFlag = False for i, line in enumerate(open(fn)): @@ -144,7 +149,7 @@ whitespace_rules = [ 'strip': '\n', 'exclude': set(['zerver/lib/bugdown/codehilite.py']), 'description': 'Fix tab-based whitespace'}, - ] + ] # type: RuleList markdown_whitespace_rules = list([rule for rule in whitespace_rules if rule['pattern'] != '\s+$']) + [ # Two spaces trailing a line with other content is okay--it's a markdown line break. # This rule finds one space trailing a non-space, three or more trailing spaces, and @@ -152,8 +157,8 @@ markdown_whitespace_rules = list([rule for rule in whitespace_rules if rule['pat {'pattern': '((? bool failed = False for fn in by_lang['py']: @@ -310,6 +316,7 @@ def check_custom_checks_py(): return failed def check_custom_checks_nonpy(): + # type: () -> bool failed = False for fn in by_lang['js']: @@ -346,9 +353,10 @@ def check_custom_checks_nonpy(): return failed -lint_functions = {} +lint_functions = {} # type: Dict[str, Callable[[], int]] def run_parallel(): + # type: () -> bool pids = [] for name, func in lint_functions.items(): pid = os.fork() @@ -367,6 +375,7 @@ def run_parallel(): return failed def lint(func): + # type: (Callable[[], int]) -> Callable[[], int] lint_functions[func.__name__] = func return func @@ -377,6 +386,7 @@ try: @lint def templates(): + # type: () -> int args = ['tools/check-templates'] if options.modified: args.append('-m') @@ -385,12 +395,14 @@ try: @lint def jslint(): + # type: () -> int result = subprocess.call(['tools/node', 'tools/jslint/check-all.js'] + by_lang['js']) return result @lint def puppet(): + # type: () -> int if not by_lang['pp']: return 0 result = subprocess.call(['puppet', 'parser', 'validate'] + by_lang['pp']) @@ -398,16 +410,19 @@ try: @lint def custom_py(): + # type: () -> int failed = check_custom_checks_py() return 1 if failed else 0 @lint def custom_nonpy(): + # type: () -> int failed = check_custom_checks_nonpy() return 1 if failed else 0 @lint def pyflakes(): + # type: () -> int failed = check_pyflakes() return 1 if failed else 0 diff --git a/tools/run-mypy b/tools/run-mypy index d3970d567c..754c7de5df 100755 --- a/tools/run-mypy +++ b/tools/run-mypy @@ -64,7 +64,6 @@ tools/compile-handlebars-templates tools/deprecated/inject-messages/inject-messages tools/deprecated/review tools/get-handlebar-vars -tools/lint-all tools/minify-js tools/test-js-with-casper tools/test-run-dev