mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 06:53:25 +00:00
linter: Add example lines for several python rules.
This commit is contained in:
@@ -280,19 +280,29 @@ def build_custom_checkers(by_lang):
|
|||||||
'exclude': set(['tools/tests',
|
'exclude': set(['tools/tests',
|
||||||
'zerver/lib/test_runner.py',
|
'zerver/lib/test_runner.py',
|
||||||
'zerver/tests']),
|
'zerver/tests']),
|
||||||
'description': '"type: ignore" should always end with "# type: ignore # explanation for why"'},
|
'description': '"type: ignore" should always end with "# type: ignore # explanation for why"',
|
||||||
|
'good_lines': ['foo = bar # type: ignore # explanation'],
|
||||||
|
'bad_lines': ['foo = bar # type: ignore']},
|
||||||
{'pattern': "# type [(]",
|
{'pattern': "# type [(]",
|
||||||
'description': 'Missing : after type in type annotation'},
|
'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",
|
{'pattern': "#type",
|
||||||
'description': 'Missing whitespace after "#" in type annotation'},
|
'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)[(]',
|
{'pattern': r'\b(if|else|while)[(]',
|
||||||
'description': 'Put a space between statements like if, else, etc. and (.',
|
'description': 'Put a space between statements like if, else, etc. and (.',
|
||||||
'good_lines': ['if (1 == 2):', 'while (foo == bar):'],
|
'good_lines': ['if (1 == 2):', 'while (foo == bar):'],
|
||||||
'bad_lines': ['if(1 == 2):', 'while(foo == bar):']},
|
'bad_lines': ['if(1 == 2):', 'while(foo == bar):']},
|
||||||
{'pattern': ", [)]",
|
{'pattern': ", [)]",
|
||||||
'description': 'Unnecessary whitespace between "," and ")"'},
|
'description': 'Unnecessary whitespace between "," and ")"',
|
||||||
|
'good_lines': ['foo = (1, 2, 3,)', 'foo(bar, 42)'],
|
||||||
|
'bad_lines': ['foo = (1, 2, 3, )']},
|
||||||
{'pattern': "% [(]",
|
{'pattern': "% [(]",
|
||||||
'description': 'Unnecessary whitespace between "%" and "("'},
|
'description': 'Unnecessary whitespace between "%" and "("',
|
||||||
|
'good_lines': ['"foo %s bar" % ("baz",)'],
|
||||||
|
'bad_lines': ['"foo %s bar" % ("baz",)']},
|
||||||
# This next check could have false positives, but it seems pretty
|
# This next check could have false positives, but it seems pretty
|
||||||
# rare; if we find any, they can be added to the exclude list for
|
# rare; if we find any, they can be added to the exclude list for
|
||||||
# this rule.
|
# this rule.
|
||||||
@@ -300,20 +310,31 @@ def build_custom_checkers(by_lang):
|
|||||||
'exclude_line': set([
|
'exclude_line': set([
|
||||||
('tools/tests/test_template_parser.py', '{% foo'),
|
('tools/tests/test_template_parser.py', '{% foo'),
|
||||||
]),
|
]),
|
||||||
'description': 'Used % comprehension without a tuple'},
|
'description': 'Used % comprehension without a tuple',
|
||||||
|
'good_lines': ['"foo %s bar" % ("baz",)'],
|
||||||
|
'bad_lines': ['"foo %s bar" % "baz"']},
|
||||||
{'pattern': '.*%s.* % \([a-zA-Z0-9_."\']*\)$',
|
{'pattern': '.*%s.* % \([a-zA-Z0-9_."\']*\)$',
|
||||||
'description': 'Used % comprehension without a tuple'},
|
'description': 'Used % comprehension without a tuple',
|
||||||
|
'good_lines': ['"foo %s bar" % ("baz",)"'],
|
||||||
|
'bad_lines': ['"foo %s bar" % ("baz")']},
|
||||||
{'pattern': 'django.utils.translation',
|
{'pattern': 'django.utils.translation',
|
||||||
'include_only': set(['test/']),
|
'include_only': set(['test/']),
|
||||||
'description': 'Test strings should not be tagged for translationx'},
|
'description': 'Test strings should not be tagged for translation',
|
||||||
|
'good_lines': [''],
|
||||||
|
'bad_lines': ['django.utils.translation']},
|
||||||
{'pattern': 'userid',
|
{'pattern': 'userid',
|
||||||
'description': 'We prefer user_id over userid.'},
|
'description': 'We prefer user_id over userid.',
|
||||||
|
'good_lines': ['id = alice.user_id'],
|
||||||
|
'bad_lines': ['id = alice.userid']},
|
||||||
{'pattern': 'json_success\({}\)',
|
{'pattern': 'json_success\({}\)',
|
||||||
'description': 'Use json_success() to return nothing'},
|
'description': 'Use json_success() to return nothing',
|
||||||
# To avoid json_error(_variable) and json_error(_(variable))
|
'good_lines': ['return json_success()'],
|
||||||
|
'bad_lines': ['return json_success({})']},
|
||||||
{'pattern': '\Wjson_error\(_\(?\w+\)',
|
{'pattern': '\Wjson_error\(_\(?\w+\)',
|
||||||
'exclude': set(['zerver/tests']),
|
'exclude': set(['zerver/tests']),
|
||||||
'description': 'Argument to json_error should be a literal string enclosed by _()'},
|
'description': 'Argument to json_error should be a literal string enclosed by _()',
|
||||||
|
'good_lines': ['return json_error(_("string"))'],
|
||||||
|
'bad_lines': ['return json_error(_variable)', 'return json_error(_(variable))']},
|
||||||
{'pattern': '\Wjson_error\([\'"].+[),]$',
|
{'pattern': '\Wjson_error\([\'"].+[),]$',
|
||||||
'exclude': set(['zerver/tests']),
|
'exclude': set(['zerver/tests']),
|
||||||
'exclude_line': set([
|
'exclude_line': set([
|
||||||
|
|||||||
Reference in New Issue
Block a user