mirror of https://github.com/zulip/zulip.git
lint: Disallow old-style type comments.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
8cdf2801f7
commit
caf64585e4
|
@ -270,11 +270,7 @@ python_rules = RuleList(
|
|||
'description': 'Use `is None` to check whether something is None',
|
||||
'good_lines': ['if foo is None'],
|
||||
'bad_lines': ['foo == None']},
|
||||
{'pattern': "type:[(]",
|
||||
'description': 'Missing whitespace after ":" in type annotation',
|
||||
'good_lines': ['# type: (Any, Any)', 'colon:separated:string:containing:type:as:keyword'],
|
||||
'bad_lines': ['# type:(Any, Any)']},
|
||||
{'pattern': r"type: ignore(?!\[[^][]+\] +# +\S)",
|
||||
{'pattern': r"#\s*type:\s*ignore(?!\[[^][]+\] +# +\S)",
|
||||
'exclude': {'tools/tests',
|
||||
'zerver/lib/test_runner.py',
|
||||
'zerver/tests'},
|
||||
|
@ -283,14 +279,6 @@ python_rules = RuleList(
|
|||
'bad_lines': ['foo = bar # type: ignore',
|
||||
'foo = bar # type: ignore[code]',
|
||||
'foo = bar # type: ignore # explanation']},
|
||||
{'pattern': "# type [(]",
|
||||
'description': 'Missing : after type in type annotation',
|
||||
'good_lines': ['foo = 42 # type: int', '# type: (str, int) -> None'],
|
||||
'bad_lines': ['# type (str, int) -> None']},
|
||||
{'pattern': "#type",
|
||||
'description': 'Missing whitespace after "#" in type annotation',
|
||||
'good_lines': ['foo = 42 # type: int'],
|
||||
'bad_lines': ['foo = 42 #type: int']},
|
||||
{'pattern': r'\b(if|else|while)[(]',
|
||||
'description': 'Put a space between statements like if, else, etc. and (.',
|
||||
'good_lines': ['if (1 == 2):', 'while (foo == bar):'],
|
||||
|
@ -410,13 +398,24 @@ python_rules = RuleList(
|
|||
'description': "Use `id` instead of `pk`.",
|
||||
'good_lines': ['if my_django_model.id == 42', 'self.user_profile._meta.pk'],
|
||||
'bad_lines': ['if my_django_model.pk == 42']},
|
||||
{'pattern': r'^[ ]*# type: \(',
|
||||
{'pattern': r'^\s*#\s*type:',
|
||||
'exclude': {
|
||||
# thumbor is (currently) python2 only
|
||||
'zthumbor/',
|
||||
},
|
||||
'description': 'Comment-style function type annotation. Use Python3 style annotations instead.',
|
||||
},
|
||||
{'pattern': r"\S\s*#\s*type:(?!\s*ignore)",
|
||||
'exclude': {'scripts/lib/hash_reqs.py',
|
||||
'scripts/lib/setup_venv.py',
|
||||
'scripts/lib/zulip_tools.py',
|
||||
'tools/lib/provision.py',
|
||||
'zproject/dev_settings.py',
|
||||
'zproject/prod_settings_template.py',
|
||||
'zthumbor'},
|
||||
'description': 'Comment-style variable type annotation. Use Python 3.6 style annotations instead.',
|
||||
'good_lines': ['a: List[int] = []'],
|
||||
'bad_lines': ['a = [] # type: List[int]']},
|
||||
{'pattern': r': *(?!Optional)[^ ].*= models[.].*null=True',
|
||||
'include_only': {"zerver/models.py"},
|
||||
'description': 'Model variable with null=true not annotated as Optional.',
|
||||
|
|
Loading…
Reference in New Issue