diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py index 479f00cae9..e1c2b491f9 100644 --- a/tools/linter_lib/custom_check.py +++ b/tools/linter_lib/custom_check.py @@ -280,19 +280,29 @@ def build_custom_checkers(by_lang): 'exclude': set(['tools/tests', 'zerver/lib/test_runner.py', '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 [(]", - '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", - '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)[(]', 'description': 'Put a space between statements like if, else, etc. and (.', 'good_lines': ['if (1 == 2):', 'while (foo == bar):'], 'bad_lines': ['if(1 == 2):', 'while(foo == bar):']}, {'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': "% [(]", - '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 # rare; if we find any, they can be added to the exclude list for # this rule. @@ -300,20 +310,31 @@ def build_custom_checkers(by_lang): 'exclude_line': set([ ('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_."\']*\)$', - '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', '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', - '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\({}\)', - 'description': 'Use json_success() to return nothing'}, - # To avoid json_error(_variable) and json_error(_(variable)) + 'description': 'Use json_success() to return nothing', + 'good_lines': ['return json_success()'], + 'bad_lines': ['return json_success({})']}, {'pattern': '\Wjson_error\(_\(?\w+\)', '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\([\'"].+[),]$', 'exclude': set(['zerver/tests']), 'exclude_line': set([