diff --git a/fiasko_bro/repository_info.py b/fiasko_bro/repository_info.py index 3a40223..1ffa55e 100644 --- a/fiasko_bro/repository_info.py +++ b/fiasko_bro/repository_info.py @@ -41,6 +41,9 @@ def is_in_whitelist(self, whitelist): def is_syntax_correct(self): return self.ast_tree is not None + def get_name_with_line(self, line_number): + return '{}:{}'.format(self.name, line_number) + def __str__(self): return self.name diff --git a/fiasko_bro/validators/code_inclusion.py b/fiasko_bro/validators/code_inclusion.py index beb459b..5fbb96e 100644 --- a/fiasko_bro/validators/code_inclusion.py +++ b/fiasko_bro/validators/code_inclusion.py @@ -26,5 +26,5 @@ def is_nesting_too_deep(project_folder, tab_size, max_indentation_level, deep_ne # make sure it's not a line continuation and indentation_spaces_amount - previous_line_indent == tab_size ): - return 'too_nested', '{}:{}'.format(parsed_file.name, line_number) + return 'too_nested', parsed_file.get_name_with_line(line_number) previous_line_indent = indentation_spaces_amount diff --git a/fiasko_bro/validators/other_languages.py b/fiasko_bro/validators/other_languages.py index c8b8ee6..cc88a69 100644 --- a/fiasko_bro/validators/other_languages.py +++ b/fiasko_bro/validators/other_languages.py @@ -17,7 +17,7 @@ def has_no_return_with_parenthesis(project_folder, *args, **kwargs): ) and line.strip().endswith(')') ): - return 'return_with_parenthesis', '{}:{}'.format(parsed_file.name, line_num) + return 'return_with_parenthesis', parsed_file.get_name_with_line(line_num) def has_no_lines_ends_with_semicolon(project_folder, *args, **kwargs): diff --git a/fiasko_bro/validators/pythonic.py b/fiasko_bro/validators/pythonic.py index cc61db2..6eb2352 100644 --- a/fiasko_bro/validators/pythonic.py +++ b/fiasko_bro/validators/pythonic.py @@ -27,7 +27,7 @@ def has_no_range_from_zero(project_folder, *args, **kwargs): len(call.args) == 2 and isinstance(call.args[0], ast.Num) and call.args[0].n == 0 ): - return 'manual_zero_in_range', '{}:{}'.format(parsed_file.name, call.lineno) + return 'manual_zero_in_range', parsed_file.get_name_with_line(call.lineno) def has_no_try_without_exception(project_folder, *args, **kwargs): @@ -69,7 +69,7 @@ def has_no_nonpythonic_empty_list_validations(project_folder, *args, **kwargs): isinstance(n, ast.If) and isinstance(n.test, ast.Compare)] for compare in ifs_compare_tests: if ast_nodes_validators.is_len_compared_to_zero(compare): - return 'nonpythonic_empty_list_validation', '{}:{}'.format(parsed_file.name, compare.lineno) + return 'nonpythonic_empty_list_validation', parsed_file.get_name_with_line(compare.lineno) def has_no_exit_calls_in_functions(project_folder, functions_allowed_to_have_exit_calls, *args, **kwargs): @@ -86,7 +86,7 @@ def not_validates_response_status_by_comparing_to_200(project_folder, *args, **k for parsed_file in project_folder.get_parsed_py_files(): for compare in ast_helpers.get_nodes_of_type(parsed_file.ast_tree, ast.Compare): if ast_nodes_validators.is_status_code_compared_to_200(compare): - return 'compare_response_status_to_200', '{}:{}'.format(parsed_file.name, compare.lineno) + return 'compare_response_status_to_200', parsed_file.get_name_with_line(compare.lineno) def has_no_mutable_default_arguments(project_folder, *args, **kwargs): @@ -95,7 +95,7 @@ def has_no_mutable_default_arguments(project_folder, *args, **kwargs): for parsed_file in project_folder.get_parsed_py_files(): for funcdef in ast_helpers.get_nodes_of_type(parsed_file.ast_tree, funcdef_types): if ast_helpers.is_funcdef_has_arguments_of_types(funcdef, mutable_types): - return 'mutable_default_arguments', '{}:{}'.format(parsed_file.name, funcdef.lineno) + return 'mutable_default_arguments', parsed_file.get_name_with_line(funcdef.lineno) def has_no_slices_starts_from_zero(project_folder, *args, **kwargs): @@ -109,7 +109,7 @@ def has_no_cast_input_result_to_str(project_folder, *args, **kwargs): calls = ast_helpers.get_nodes_of_type(parsed_file.ast_tree, ast.Call) for call in calls: if ast_helpers.is_str_call_of_input(call): - return 'str_conversion_of_input_result', '{}:{}'.format(parsed_file.name, call.lineno) + return 'str_conversion_of_input_result', parsed_file.get_name_with_line(call.lineno) def has_no_string_literal_sums(project_folder, *args, **kwargs): @@ -121,7 +121,7 @@ def has_no_string_literal_sums(project_folder, *args, **kwargs): isinstance(node.left, ast.Str) and isinstance(node.right, ast.Str) ): - return 'has_string_sum', '{}: {}'.format(parsed_file.name, node.lineno) + return 'has_string_sum', parsed_file.get_name_with_line(node.lineno) def has_no_calls_with_constants(project_folder, valid_calls_with_constants, *args, **kwargs): diff --git a/fiasko_bro/validators/syntax.py b/fiasko_bro/validators/syntax.py index 88a7f05..b01f9b0 100644 --- a/fiasko_bro/validators/syntax.py +++ b/fiasko_bro/validators/syntax.py @@ -25,4 +25,4 @@ def has_indents_of_spaces(project_folder, tab_size, *args, **kwargs): node_types_to_validate, tab_size, ): - return 'indent_not_four_spaces', '{}:{}'.format(parsed_file.name, node.lineno) + return 'indent_not_four_spaces', parsed_file.get_name_with_line(node.lineno)