From 6d040d330cc628ddb98920df9f228820529d16ff Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Tue, 18 Jun 2019 16:38:20 +0000 Subject: [PATCH] lint: Add --list arg which lists all the registered linters. --- tools/lint | 3 +-- tools/zulint/command.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/lint b/tools/lint index fab27f75a2..2f20e52a51 100755 --- a/tools/lint +++ b/tools/lint @@ -130,8 +130,7 @@ def run(): # type: () -> int failed = check_pep8(list(python_part2)) return 1 if failed else 0 - - linter_config.do_lint(skip=args.skip, only=args.only) + linter_config.do_lint(skip=args.skip, only=args.only, only_list=args.list) if __name__ == '__main__': run() diff --git a/tools/zulint/command.py b/tools/zulint/command.py index b24582a98a..bbcbe044f7 100644 --- a/tools/zulint/command.py +++ b/tools/zulint/command.py @@ -34,6 +34,9 @@ def add_default_linter_arguments(parser): default=[], type=split_arg_into_list, help='Specify linters to run, eg: --only=mypy,gitlint') + parser.add_argument('--list', '-l', + action='store_true', + help='List all the registered linters') def split_arg_into_list(arg): # type: (str) -> List[str] @@ -111,13 +114,16 @@ class LinterConfig: self.lint_functions[name] = run_linter - def do_lint(self, only=[], skip=[]): - # type: (List[str], List[str]) -> None + def do_lint(self, only=[], skip=[], only_list=False): + # type: (List[str], List[str], bool) -> None assert not only or not skip, "Only one of --only or --skip can be used at once." if only: self.lint_functions = {linter: self.lint_functions[linter] for linter in only} for linter in skip: del self.lint_functions[linter] + if only_list: + print("\n".join(self.lint_functions.keys())) + sys.exit() failed = run_parallel(self.lint_functions) sys.exit(1 if failed else 0)