From 6b73926e935e61edc7a146443c40a7c0a57a1a30 Mon Sep 17 00:00:00 2001 From: Aman Agrawal Date: Tue, 18 Jun 2019 19:29:24 +0530 Subject: [PATCH] lint: Add --skip arg to replace --no-gitlint/mypy. Use --skip=gitlint,mypy instead of --no-gitlint/mypy. --- tools/ci/backend | 2 +- tools/ci/frontend | 2 +- tools/lint | 10 ++-------- tools/pre-commit | 4 ++-- tools/zulint/command.py | 8 ++++++++ 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tools/ci/backend b/tools/ci/backend index 1c698fcdd7..1ea7251972 100755 --- a/tools/ci/backend +++ b/tools/ci/backend @@ -6,7 +6,7 @@ echo "Test suite is running under $(python --version)." set -e set -x -./tools/lint --backend --no-gitlint --no-mypy # gitlint disabled because flaky +./tools/lint --backend --skip=gitlint,mypy # gitlint disabled because flaky ./tools/test-tools # We need to pass a parallel level to test-backend because CircleCI's # docker setup means the auto-detection logic sees the ~36 processes diff --git a/tools/ci/frontend b/tools/ci/frontend index e78e4c5da8..22e0866f39 100755 --- a/tools/ci/frontend +++ b/tools/ci/frontend @@ -5,7 +5,7 @@ source tools/ci/activate-venv set -e set -x -./tools/lint --frontend --no-gitlint # gitlint disabled because flaky +./tools/lint --frontend --skip=gitlint # gitlint disabled because flaky # Run the node tests first, since they're fast and deterministic ./tools/test-js-with-node --coverage diff --git a/tools/lint b/tools/lint index 60412404de..bd58150e4a 100755 --- a/tools/lint +++ b/tools/lint @@ -25,12 +25,6 @@ def run(): parser.add_argument('--full', action='store_true', help='Check some things we typically ignore') - parser.add_argument('--no-gitlint', - action='store_true', - help='Disable gitlint') - parser.add_argument('--no-mypy', - action='store_true', - help='Disable mypy') limited_tests_group = parser.add_mutually_exclusive_group() limited_tests_group.add_argument('--frontend', action='store_true', @@ -96,14 +90,14 @@ def run(): linter_config.external_linter('templates', ['tools/check-templates'], ['handlebars', 'html']) linter_config.external_linter('swagger', ['node', 'tools/check-swagger'], ['yaml']) linter_config.external_linter('shellcheck', ['shellcheck', '-x'], ['sh']) - if not args.no_mypy: + if 'mypy' not in args.skip: command = ['tools/run-mypy'] if args.force: command.append('--force') linter_config.external_linter('mypy', command, ['py'], pass_targets=False) # Disabled check for imperative mood until it is stabilized - if not args.no_gitlint: + if 'gitlint' not in args.skip: linter_config.external_linter('commit_messages', ['tools/commit-message-lint']) @linter_config.lint diff --git a/tools/pre-commit b/tools/pre-commit index a2f25d927c..24eab091ec 100755 --- a/tools/pre-commit +++ b/tools/pre-commit @@ -19,10 +19,10 @@ if [ ${#changed_files} -eq 0 ]; then fi if [ -z "$VIRTUAL_ENV" ] && command -v vagrant > /dev/null && [ -e .vagrant ]; then - vcmd="/srv/zulip/tools/lint --no-gitlint --force $(printf '%q ' "${changed_files[@]}") || true" + vcmd="/srv/zulip/tools/lint --skip=gitlint --force $(printf '%q ' "${changed_files[@]}") || true" echo "Running lint using vagrant..." vagrant ssh -c "$vcmd" else - ./tools/lint --no-gitlint --force "${changed_files[@]}" || true + ./tools/lint --skip=gitlint --force "${changed_files[@]}" || true fi exit 0 diff --git a/tools/zulint/command.py b/tools/zulint/command.py index c88d3c2f8f..833edba15b 100644 --- a/tools/zulint/command.py +++ b/tools/zulint/command.py @@ -26,6 +26,14 @@ def add_default_linter_arguments(parser): parser.add_argument('targets', nargs='*', help='Specify directories to check') + parser.add_argument('--skip', + default=[], + type=split_arg_into_list, + help='Specify linters to skip, eg: --skip=mypy,gitlint') + +def split_arg_into_list(arg): + # type: (str) -> List[str] + return [linter for linter in arg.split(',')] def run_parallel(lint_functions): # type: (Dict[str, Callable[[], int]]) -> bool