From 7b7e887386bcb7e1c17c2e5a7f69ffc790ab1276 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Fri, 21 Jun 2019 22:06:41 +0530 Subject: [PATCH] lint: Pass args to LinterConfig when initializing it. This makes it easy to use args inside LinterConfig. --- tools/lint | 5 +++-- tools/zulint/command.py | 29 +++++++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tools/lint b/tools/lint index 6a02a6bda9..25c50dafac 100755 --- a/tools/lint +++ b/tools/lint @@ -66,7 +66,7 @@ def run(): # Invoke the appropriate lint checker for each language, # and also check files for extra whitespace. - linter_config = LinterConfig(by_lang) + linter_config = LinterConfig(args, by_lang) linter_config.external_linter('add_class', ['tools/find-add-class'], ['js']) linter_config.external_linter('css', ['node', 'node_modules/.bin/stylelint'], ['css', 'scss']) linter_config.external_linter('eslint', ['node', 'node_modules/.bin/eslint', @@ -117,7 +117,8 @@ def run(): # type: () -> int failed = check_pep8(list(python_part2)) return 1 if failed else 0 - linter_config.do_lint(args) + + linter_config.do_lint() if __name__ == '__main__': run() diff --git a/tools/zulint/command.py b/tools/zulint/command.py index 9ee5228b01..5bfc03b4a1 100644 --- a/tools/zulint/command.py +++ b/tools/zulint/command.py @@ -66,9 +66,10 @@ def run_parallel(lint_functions): class LinterConfig: lint_functions = {} # type: Dict[str, Callable[[], int]] - def __init__(self, by_lang): - # type: (Any) -> None - self.by_lang = by_lang + def __init__(self, args, by_lang): + # type: (argparse.Namespace, Any) -> None + self.args = args + self.by_lang = by_lang # type: Dict[str, List[str]] def lint(self, func): # type: (Callable[[], int]) -> Callable[[], int] @@ -114,26 +115,26 @@ class LinterConfig: self.lint_functions[name] = run_linter - def set_logger(self, verbose_timing): - # type: (bool) -> None + def set_logger(self): + # type: () -> None logging.basicConfig(format="%(asctime)s %(message)s") logger = logging.getLogger() - if verbose_timing: + if self.args.verbose_timing: logger.setLevel(logging.INFO) else: logger.setLevel(logging.WARNING) - def do_lint(self, args): - # type: (argparse.Namespace) -> None - assert not args.only or not args.skip, "Only one of --only or --skip can be used at once." - if args.only: - self.lint_functions = {linter: self.lint_functions[linter] for linter in args.only} - for linter in args.skip: + def do_lint(self): + # type: () -> None + assert not self.args.only or not self.args.skip, "Only one of --only or --skip can be used at once." + if self.args.only: + self.lint_functions = {linter: self.lint_functions[linter] for linter in self.args.only} + for linter in self.args.skip: del self.lint_functions[linter] - if args.list: + if self.args.list: print("\n".join(self.lint_functions.keys())) sys.exit() - self.set_logger(args.verbose_timing) + self.set_logger() failed = run_parallel(self.lint_functions) sys.exit(1 if failed else 0)