diff --git a/docs/source/add_validators.rst b/docs/source/add_validators.rst index f20b25e..734285f 100644 --- a/docs/source/add_validators.rst +++ b/docs/source/add_validators.rst @@ -207,20 +207,20 @@ Consider the example: validate( '/Users/project', error_validator_groups=validator_groups, - warning_validators_groups=defaults.WARNING_VALIDATOR_GROUPS + post_error_validator_groups=defaults.POST_ERROR_VALIDATOR_GROUPS ) ) As you can see, we simply copy the default validators structure, modify it to suit our needs and pass to the ``validate`` method. -The minor issue is that since we pass our own error validators, the default warning validators have to be restored by hand. +The minor issue is that since we pass our own error validators, the default post error validators have to be restored by hand. We did so by passing them as an argument too. The intricacies ~~~~~~~~~~~~~~~ -The are two kinds of validators: error validators and warning validators. -The difference between them is that warning validators don't halt the validation process, while the error validators do. +The are two kinds of validators: error validators and post error validators. +The difference between them is that post error validators don't halt the validation process, while the error validators do. The error validators are expected to be grouped according to their purpose, like so:: ERROR_VALIDATOR_GROUPS = OrderedDict( @@ -250,10 +250,10 @@ because the order in which the validator groups run matters. In each group, every single validator is executed. If one of the validators in the group fails, the ``validate`` method executes the rest of the group and then returns the error list without proceeding to the next group. -If all the validators in the error group succeed, the warning validators for this group are executed. -Here's the structure of the warnings validators:: +If all the validators in the error group succeed, the post error validators for this group are executed. +Here's the structure of the post error validators:: - WARNING_VALIDATOR_GROUPS = { + POST_ERROR_VALIDATOR_GROUPS = { 'commits': [ validators.commit_message_from_blacklist, ], @@ -263,7 +263,7 @@ Here's the structure of the warnings validators:: ] } -The ``commits`` warning validator group is executed only if the ``commits`` error validator group passes successfully. +The ``commits`` post error validator group is executed only if the ``commits`` error validator group passes successfully. Warning validators are not executed if none of the error validators are failed. They just add more error messages in case the validation fails. diff --git a/fiasko_bro/code_validator.py b/fiasko_bro/code_validator.py index aa6cec0..0f23b26 100644 --- a/fiasko_bro/code_validator.py +++ b/fiasko_bro/code_validator.py @@ -54,18 +54,18 @@ def _construct_validator_arguments(project_path, **kwargs): def determine_validators(**kwargs): pre_validation_checks = kwargs.pop('pre_validation_checks', None) or defaults.PRE_VALIDATION_CHECKS error_validator_groups = kwargs.pop('error_validator_groups', None) - warning_validator_groups = kwargs.pop('warning_validator_groups', None) or {} + post_error_validator_group = kwargs.pop('post_error_validator_groups', None) or {} if not error_validator_groups: error_validator_groups = defaults.ERROR_VALIDATOR_GROUPS # use default warning groups only with default error groups - if not warning_validator_groups: - warning_validator_groups = defaults.WARNING_VALIDATOR_GROUPS - return pre_validation_checks, error_validator_groups, warning_validator_groups + if not post_error_validator_group: + post_error_validator_group = defaults.POST_ERROR_VALIDATOR_GROUPS + return pre_validation_checks, error_validator_groups, post_error_validator_group def validate(project_path, original_project_path=None, **kwargs): ensure_repo_tokens_mutually_exclusive(**kwargs) - pre_validation_checks, error_validator_groups, warning_validator_groups = determine_validators(**kwargs) + pre_validation_checks, error_validator_groups, post_error_validator_groups = determine_validators(**kwargs) validator_arguments = _construct_validator_arguments( project_path, original_project_path=original_project_path, @@ -88,7 +88,7 @@ def validate(project_path, original_project_path=None, **kwargs): return run_validator_group( validator_group=error_validator_groups, validator_arguments=validator_arguments, - post_error_validator_group=warning_validator_groups + post_error_validator_group=post_error_validator_groups ) @@ -98,11 +98,11 @@ def traverse_validator_groups(validator_groups, func): func(validator) -def get_error_slugs(pre_validation_checks=None, error_validator_groups=None, warning_validator_groups=None): +def get_error_slugs(pre_validation_checks=None, error_validator_groups=None, post_error_validator_groups=None): validators = determine_validators( pre_validation_checks=pre_validation_checks, error_validator_groups=error_validator_groups, - warning_validator_groups=warning_validator_groups + post_error_validator_groups=post_error_validator_groups ) error_slugs = set() for validator_groups in validators: diff --git a/fiasko_bro/defaults.py b/fiasko_bro/defaults.py index 4a9a67d..5c6d944 100644 --- a/fiasko_bro/defaults.py +++ b/fiasko_bro/defaults.py @@ -10,16 +10,16 @@ { 'readme_filename': 'README.md', 'allowed_max_pep8_violations': 5, - 'max_complexity': 7, - 'minimum_name_length': 2, - 'min_percent_of_another_language': 30, + 'max_mccabe_complexity': 7, + 'min_variable_name_length': 2, + 'min_percent_of_another_language_in_readme': 30, 'last_commits_to_check_amount': 5, 'tab_size': 4, 'functions_with_docstrings_percent_limit': 80, 'max_pep8_line_length': 100, 'max_number_of_lines': 200, 'max_indentation_level': 4, - 'max_num_of_py_files': 100, + 'max_num_of_py_files_in_project': 100, 'directories_to_skip': frozenset( [ 'build', @@ -268,7 +268,7 @@ ) ) -WARNING_VALIDATOR_GROUPS = MappingProxyType( +POST_ERROR_VALIDATOR_GROUPS = MappingProxyType( { 'commits': ( validators.commit_messages_from_blacklist, @@ -280,5 +280,5 @@ } ) -for name in WARNING_VALIDATOR_GROUPS: +for name in POST_ERROR_VALIDATOR_GROUPS: assert name in ERROR_VALIDATOR_GROUPS.keys() diff --git a/fiasko_bro/pre_validation_checks/repo_size.py b/fiasko_bro/pre_validation_checks/repo_size.py index f8bb4ba..47a66dc 100644 --- a/fiasko_bro/pre_validation_checks/repo_size.py +++ b/fiasko_bro/pre_validation_checks/repo_size.py @@ -6,15 +6,15 @@ def repo_is_too_large( project_path, directories_to_skip, - max_num_of_py_files, + max_num_of_py_files_in_project, original_project_path=None, *args, **kwargs ): - if code_helpers.is_repo_too_large(project_path, directories_to_skip, max_num_of_py_files): + if code_helpers.is_repo_too_large(project_path, directories_to_skip, max_num_of_py_files_in_project): return '' if original_project_path: - if code_helpers.is_repo_too_large(original_project_path, directories_to_skip, max_num_of_py_files): + if code_helpers.is_repo_too_large(original_project_path, directories_to_skip, max_num_of_py_files_in_project): return '' diff --git a/fiasko_bro/utils/configparser_helpers.py b/fiasko_bro/utils/configparser_helpers.py index c9ac489..0c9995f 100644 --- a/fiasko_bro/utils/configparser_helpers.py +++ b/fiasko_bro/utils/configparser_helpers.py @@ -17,16 +17,16 @@ def _process_section_to_dict_config(config_section): config_processors = { 'readme_filename': lambda x: x, 'allowed_max_pep8_violations': int, - 'max_complexity': int, + 'max_mccabe_complexity': int, 'minimum_name_length': int, - 'min_percent_of_another_language': int, + 'min_percent_of_another_language_in_readme': int, 'last_commits_to_check_amount': int, 'tab_size': int, 'functions_with_docstrings_percent_limit': int, 'max_pep8_line_length': int, 'max_number_of_lines': int, 'max_indentation_level': int, - 'max_num_of_py_files': int, + 'max_num_of_py_files_in_project': int, 'directories_to_skip': lambda x: x.split(',') } result_config = {} diff --git a/fiasko_bro/validators/code_inclusion.py b/fiasko_bro/validators/code_inclusion.py index d546c13..bbd1fa6 100644 --- a/fiasko_bro/validators/code_inclusion.py +++ b/fiasko_bro/validators/code_inclusion.py @@ -1,10 +1,10 @@ from ..utils import code_helpers -def too_difficult_by_mccabe(project_folder, max_complexity, *args, **kwargs): +def too_difficult_by_mccabe(project_folder, max_mccabe_complexity, *args, **kwargs): violations = [] for parsed_file in project_folder.get_parsed_py_files(): - violations += code_helpers.get_mccabe_violations_for_file(parsed_file.path, max_complexity) + violations += code_helpers.get_mccabe_violations_for_file(parsed_file.path, max_mccabe_complexity) if violations: return ','.join(violations) diff --git a/fiasko_bro/validators/naming.py b/fiasko_bro/validators/naming.py index cd77f65..20ceb84 100644 --- a/fiasko_bro/validators/naming.py +++ b/fiasko_bro/validators/naming.py @@ -20,12 +20,12 @@ def has_local_var_named_as_global(project_folder, local_var_named_as_global_path return message -def short_variable_name(project_folder, minimum_name_length, valid_short_variable_names, *args, **kwargs): +def short_variable_name(project_folder, min_variable_name_length, valid_short_variable_names, *args, **kwargs): short_names = [] for parsed_file in project_folder.get_parsed_py_files(): names = ast_helpers.get_all_defined_names(parsed_file.ast_tree) short_names += [n for n in names - if len(n) < minimum_name_length and n not in valid_short_variable_names] + if len(n) < min_variable_name_length and n not in valid_short_variable_names] if short_names: return ', '.join(list(set(short_names))) diff --git a/fiasko_bro/validators/readme.py b/fiasko_bro/validators/readme.py index 1af56cf..119ffc3 100644 --- a/fiasko_bro/validators/readme.py +++ b/fiasko_bro/validators/readme.py @@ -25,7 +25,7 @@ def readme_not_changed(project_folder, readme_filename, original_project_folder= return '' -def bilingual_readme(project_folder, readme_filename, min_percent_of_another_language, *args, **kwargs): +def bilingual_readme(project_folder, readme_filename, min_percent_of_another_language_in_readme, *args, **kwargs): raw_readme = project_folder.get_file(readme_filename) readme_no_code = re.sub(r'\s```[#!A-Za-z]*\n[\s\S]*?\n```\s', '', raw_readme) clean_readme = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', '', readme_no_code) @@ -35,5 +35,5 @@ def bilingual_readme(project_folder, readme_filename, min_percent_of_another_lan return another_language_percent = min([ru_letters_amount, en_letters_amount]) * 100 another_language_percent /= (ru_letters_amount + en_letters_amount) - if another_language_percent > min_percent_of_another_language: + if another_language_percent > min_percent_of_another_language_in_readme: return '' diff --git a/tests/test_general_validators/test_has_no_short_variable_names.py b/tests/test_general_validators/test_has_no_short_variable_names.py index a0f4c41..f4dfabb 100644 --- a/tests/test_general_validators/test_has_no_short_variable_names.py +++ b/tests/test_general_validators/test_has_no_short_variable_names.py @@ -4,20 +4,20 @@ def test_short_variable_name_fail(test_repo): expected_output = 'sv' - minimum_name_length = 3 + min_variable_name_length = 3 output = validators.short_variable_name( project_folder=test_repo, valid_short_variable_names=defaults.VALIDATION_PARAMETERS['valid_short_variable_names'], - minimum_name_length=minimum_name_length, + min_variable_name_length=min_variable_name_length, ) assert output == expected_output def test_short_variable_name_ok(test_repo): - minimum_name_length = 3 + min_variable_name_length = 3 output = validators.short_variable_name( project_folder=test_repo, valid_short_variable_names=['sv'], - minimum_name_length=minimum_name_length, + min_variable_name_length=min_variable_name_length, ) assert output is None diff --git a/tests/test_general_validators/test_has_readme_in_single_language.py b/tests/test_general_validators/test_has_readme_in_single_language.py index 1938753..05f28d9 100644 --- a/tests/test_general_validators/test_has_readme_in_single_language.py +++ b/tests/test_general_validators/test_has_readme_in_single_language.py @@ -5,12 +5,12 @@ def test_bilingual_readme_succeeds(test_repo): readme_filename = 'readme_in_single_language.md' min_percent = defaults.VALIDATION_PARAMETERS[ - 'min_percent_of_another_language' + 'min_percent_of_another_language_in_readme' ] output = validators.bilingual_readme( project_folder=test_repo, readme_filename=readme_filename, - min_percent_of_another_language=min_percent, + min_percent_of_another_language_in_readme=min_percent, ) assert output is None @@ -19,11 +19,11 @@ def test_bilingual_readme_fails(test_repo): readme_filename = 'bilingual_readme.md' expected_output = '' min_percent = defaults.VALIDATION_PARAMETERS[ - 'min_percent_of_another_language' + 'min_percent_of_another_language_in_readme' ] output = validators.bilingual_readme( project_folder=test_repo, readme_filename=readme_filename, - min_percent_of_another_language=min_percent, + min_percent_of_another_language_in_readme=min_percent, ) assert output == expected_output diff --git a/tests/test_general_validators/test_mccabe_difficulty.py b/tests/test_general_validators/test_mccabe_difficulty.py index 4c1d5b5..69da90a 100644 --- a/tests/test_general_validators/test_mccabe_difficulty.py +++ b/tests/test_general_validators/test_mccabe_difficulty.py @@ -6,6 +6,6 @@ def test_mccabe_difficulty(test_repo): expected_output = 'function_with_big_complexity' output = validators.too_difficult_by_mccabe( project_folder=test_repo, - max_complexity=max_complexity + max_mccabe_complexity=max_complexity ) assert output == expected_output