lint: Run mypy as part of main linter.

To support this, we add a pass_targets option to the main linter
library, because with current mypy, it's generally counterproductive
to pass the list of files in (can produce spurious errors; isn't
faster).
This commit is contained in:
Tim Abbott 2018-12-16 20:58:06 -08:00
parent 3003517430
commit 6b69cc0b39
5 changed files with 16 additions and 11 deletions

View File

@ -99,12 +99,9 @@ following checks:
- Check HTML templates for matching tags and indentations.
- Check CSS for parsability and formatting.
- Check JavaScript code for addClass calls.
The remaining lint checks occur in `./tools/run-mypy`. It is probably somewhat
of an understatement to call "mypy" a "linter," as it performs static
code analysis of Python type annotations throughout our Python codebase.
Our [documentation on using mypy](../testing/mypy.html) covers mypy in more detail.
- Running `mypy` to check static types in Python code. Our
[documentation on using mypy](../testing/mypy.html) covers mypy in
more detail.
The rest of this document pertains to the checks that occur in `./tools/lint`.

View File

@ -6,7 +6,7 @@ echo "Test suite is running under $(python --version)."
set -e
set -x
./tools/lint --backend --no-gitlint # gitlint disabled because flaky
./tools/lint --backend --no-gitlint --no-mypy # gitlint disabled because flaky
./tools/test-tools
./tools/test-backend --coverage

View File

@ -27,6 +27,9 @@ def run():
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',
@ -98,6 +101,8 @@ def run():
linter_config.external_linter('urls', ['tools/check-urls'], ['py'])
linter_config.external_linter('swagger', ['node', 'tools/check-swagger'], ['yaml'])
linter_config.external_linter('shellcheck', ['shellcheck', '-x'], ['sh'])
if not args.no_mypy:
linter_config.external_linter('mypy', ['tools/run-mypy'], ['py'], pass_targets=False)
# Disabled check for imperative mood until it is stabilized
if not args.no_gitlint:

View File

@ -42,7 +42,6 @@ run ./tools/clean-repo
run ./tools/lint --backend $FORCEARG
run ./tools/test-tools
run ./tools/test-backend $FORCEARG
run ./tools/run-mypy $FORCEARG
run ./tools/test-migrations
# Not running SVG optimizing since it's low-churn
# run ./tools/setup/optimize-svg

View File

@ -57,8 +57,8 @@ class LinterConfig:
self.lint_functions[func.__name__] = func
return func
def external_linter(self, name, command, target_langs=[]):
# type: (str, List[str], List[str]) -> None
def external_linter(self, name, command, target_langs=[], pass_targets=True):
# type: (str, List[str], List[str], bool) -> None
"""Registers an external linter program to be run as part of the
linter. This program will be passed the subset of files being
linted that have extensions in target_langs. If there are no
@ -80,7 +80,11 @@ class LinterConfig:
# invoking the external linter.
return 0
p = subprocess.Popen(command + targets,
if pass_targets:
full_command = command + targets
else:
full_command = command
p = subprocess.Popen(full_command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)