lint: Add --only agr to run only the specified linters.

This commit is contained in:
Aman Agrawal
2019-06-18 22:41:26 +05:30
committed by Tim Abbott
parent cf8653945f
commit 995b357cde
2 changed files with 10 additions and 3 deletions

View File

@@ -135,7 +135,7 @@ def run():
failed = check_pep8(list(python_part2))
return 1 if failed else 0
linter_config.do_lint()
linter_config.do_lint(only=args.only)
if __name__ == '__main__':
run()

View File

@@ -30,6 +30,10 @@ def add_default_linter_arguments(parser):
default=[],
type=split_arg_into_list,
help='Specify linters to skip, eg: --skip=mypy,gitlint')
parser.add_argument('--only',
default=[],
type=split_arg_into_list,
help='Specify linters to run, eg: --only=mypy,gitlint')
def split_arg_into_list(arg):
# type: (str) -> List[str]
@@ -107,7 +111,10 @@ class LinterConfig:
self.lint_functions[name] = run_linter
def do_lint(self):
# type: () -> None
def do_lint(self, only=[]):
# type: (List[str]) -> None
if only:
self.lint_functions = {linter: self.lint_functions[linter] for linter in only}
failed = run_parallel(self.lint_functions)
sys.exit(1 if failed else 0)