lint: Add lint rule for scripts importing typing improperly.

This is a common bug that users might be tempated to introduce.

And also fix two instances of this bug that were present in our
codebase, including an important one in our upgrade code path.
This commit is contained in:
Tim Abbott
2018-12-17 10:44:24 -08:00
parent 47c4a2d21a
commit bce90a3340
3 changed files with 20 additions and 4 deletions

View File

@@ -479,6 +479,21 @@ def build_custom_checkers(by_lang):
'description': 'Most scripts are intended to run on systems without sudo.',
'good_lines': ['subprocess.check_call(["ls"])'],
'bad_lines': ['subprocess.check_call(["sudo", "ls"])']},
{'pattern': '^from typing import',
'strip': '\n',
'include_only': set([
'scripts/',
'puppet/',
]),
'exclude': set([
# Not important, but should fix
'scripts/lib/process-mobile-i18n',
# Uses setup_path_on_import before importing.
'puppet/zulip/files/nagios_plugins/zulip_app_frontend/check_send_receive_time',
]),
'description': 'For scripts run as part of installer, cannot rely on typing existing; use `if False` workaround.',
'good_lines': ['subprocess.check_call(["ls"])'],
'bad_lines': ['subprocess.check_call(["sudo", "ls"])']},
{'pattern': 'django.utils.translation',
'include_only': set(['test/']),
'description': 'Test strings should not be tagged for translation',