Skip to content

Commit

Permalink
Put name:line format into the common place
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Vergeev committed Apr 30, 2018
1 parent 9322739 commit 2ff25f0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions fiasko_bro/repository_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion fiasko_bro/validators/code_inclusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion fiasko_bro/validators/other_languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 6 additions & 6 deletions fiasko_bro/validators/pythonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion fiasko_bro/validators/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2ff25f0

Please sign in to comment.