From 59155ce9f6682e20c0a0c7e0038c430e65d9cbe3 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 9 Jan 2023 01:39:51 -0500 Subject: [PATCH] Rename `checks` and `plugins` to `rules` (#1739) --- README.md | 2 +- ruff.schema.json | 2 +- scripts/add_check.py | 4 +- scripts/add_plugin.py | 8 +- src/checkers/ast.rs | 603 +++++++++--------- src/checkers/imports.rs | 2 +- src/checkers/lines.rs | 6 +- src/checkers/tokens.rs | 12 +- src/eradicate/mod.rs | 4 +- src/eradicate/{checks.rs => rules.rs} | 0 src/flake8_2020/mod.rs | 4 +- src/flake8_2020/{plugins.rs => rules.rs} | 0 src/flake8_annotations/mod.rs | 2 +- .../{plugins.rs => rules.rs} | 0 src/flake8_bandit/mod.rs | 4 +- .../{checks => rules}/assert_used.rs | 0 .../{checks => rules}/bad_file_permissions.rs | 0 .../{checks => rules}/exec_used.rs | 0 .../hardcoded_bind_all_interfaces.rs | 0 .../hardcoded_password_default.rs | 0 .../hardcoded_password_func_arg.rs | 0 .../hardcoded_password_string.rs | 0 .../hardcoded_tmp_directory.rs | 0 .../hashlib_insecure_hash_functions.rs | 0 src/flake8_bandit/{checks => rules}/mod.rs | 0 .../request_with_no_cert_validation.rs | 0 .../request_without_timeout.rs | 0 .../{checks => rules}/unsafe_yaml_load.rs | 0 src/flake8_blind_except/mod.rs | 4 +- .../{plugins.rs => rules.rs} | 0 src/flake8_boolean_trap/mod.rs | 4 +- .../{plugins.rs => rules.rs} | 0 src/flake8_bugbear/mod.rs | 4 +- .../{plugins => rules}/abstract_base_class.rs | 0 .../{plugins => rules}/assert_false.rs | 0 .../assert_raises_exception.rs | 0 .../assignment_to_os_environ.rs | 0 .../cached_instance_method.rs | 0 .../cannot_raise_literal.rs | 0 .../duplicate_exceptions.rs | 0 .../{plugins => rules}/f_string_docstring.rs | 0 .../function_call_argument_default.rs | 2 +- .../function_uses_loop_variable.rs | 0 .../getattr_with_constant.rs | 0 .../jump_statement_in_finally.rs | 0 .../loop_variable_overrides_iterator.rs | 0 src/flake8_bugbear/{plugins => rules}/mod.rs | 0 .../mutable_argument_default.rs | 0 .../raise_without_from_inside_except.rs | 0 .../redundant_tuple_in_exception_handler.rs | 0 .../setattr_with_constant.rs | 0 .../star_arg_unpacking_after_keyword_arg.rs | 0 .../strip_with_multi_characters.rs | 0 .../unary_prefix_increment.rs | 0 .../unreliable_callable_check.rs | 0 .../unused_loop_control_variable.rs | 0 .../{plugins => rules}/useless_comparison.rs | 0 .../useless_contextlib_suppress.rs | 0 .../{plugins => rules}/useless_expression.rs | 0 .../zip_without_explicit_strict.rs | 0 src/flake8_builtins/mod.rs | 4 +- src/flake8_builtins/{checks.rs => rules.rs} | 0 src/flake8_comprehensions/mod.rs | 4 +- .../{checks.rs => rules.rs} | 0 src/flake8_datetimez/mod.rs | 4 +- src/flake8_datetimez/{plugins.rs => rules.rs} | 0 src/flake8_debugger/mod.rs | 4 +- src/flake8_debugger/{checks.rs => rules.rs} | 0 src/flake8_errmsg/mod.rs | 2 +- src/flake8_errmsg/{plugins.rs => rules.rs} | 0 src/flake8_implicit_str_concat/mod.rs | 4 +- .../{checks.rs => rules.rs} | 0 src/flake8_import_conventions/mod.rs | 2 +- .../{checks.rs => rules.rs} | 0 src/flake8_pie/mod.rs | 4 +- src/flake8_pie/{plugins.rs => rules.rs} | 0 src/flake8_print/mod.rs | 4 +- src/flake8_print/{plugins => rules}/mod.rs | 0 .../{plugins => rules}/print_call.rs | 0 src/flake8_pytest_style/mod.rs | 2 +- .../{plugins => rules}/assertion.rs | 0 .../{plugins => rules}/fail.rs | 0 .../{plugins => rules}/fixture.rs | 0 .../{plugins => rules}/helpers.rs | 0 .../{plugins => rules}/imports.rs | 0 .../{plugins => rules}/marks.rs | 0 .../{plugins => rules}/mod.rs | 0 .../{plugins => rules}/parametrize.rs | 0 .../{plugins => rules}/patch.rs | 0 .../{plugins => rules}/raises.rs | 0 .../{plugins => rules}/unittest_assert.rs | 0 src/flake8_quotes/mod.rs | 2 +- src/flake8_quotes/{checks.rs => rules.rs} | 0 src/flake8_return/mod.rs | 4 +- src/flake8_return/{plugins.rs => rules.rs} | 0 src/flake8_simplify/mod.rs | 4 +- .../{plugins => rules}/ast_bool_op.rs | 0 .../{plugins => rules}/ast_for.rs | 0 .../{plugins => rules}/ast_if.rs | 0 .../{plugins => rules}/ast_ifexp.rs | 0 .../{plugins => rules}/ast_unary_op.rs | 0 .../{plugins => rules}/ast_with.rs | 0 .../{plugins => rules}/key_in_dict.rs | 0 src/flake8_simplify/{plugins => rules}/mod.rs | 0 .../return_in_try_except_finally.rs | 0 .../use_contextlib_suppress.rs | 0 .../{plugins => rules}/yoda_conditions.rs | 0 src/flake8_tidy_imports/mod.rs | 2 +- .../{checks.rs => rules.rs} | 0 src/flake8_unused_arguments/mod.rs | 4 +- .../{plugins.rs => rules.rs} | 0 src/isort/mod.rs | 2 +- src/isort/{plugins.rs => rules.rs} | 0 src/mccabe/mod.rs | 2 +- src/mccabe/{checks.rs => rules.rs} | 2 +- src/pandas_vet/mod.rs | 2 +- src/pandas_vet/{checks.rs => rules.rs} | 0 src/pep8_naming/mod.rs | 5 +- src/pep8_naming/plugins.rs | 57 -- src/pep8_naming/{checks.rs => rules.rs} | 52 ++ src/pycodestyle/checks.rs | 269 -------- src/pycodestyle/mod.rs | 5 +- src/pycodestyle/{plugins.rs => rules.rs} | 268 +++++++- src/pydocstyle/mod.rs | 4 +- src/pydocstyle/{plugins.rs => rules.rs} | 0 src/pyflakes/mod.rs | 5 +- src/pyflakes/plugins/assert_tuple.rs | 12 - src/pyflakes/plugins/if_tuple.rs | 12 - src/pyflakes/plugins/mod.rs | 28 - src/pyflakes/rules/assert_tuple.rs | 18 + .../f_string_missing_placeholders.rs | 0 src/pyflakes/rules/if_tuple.rs | 18 + .../invalid_literal_comparisons.rs | 0 .../invalid_print_syntax.rs | 0 src/pyflakes/{checks.rs => rules/mod.rs} | 49 +- .../raise_not_implemented.rs | 0 .../{plugins => rules}/repeated_keys.rs | 0 src/pyflakes/{plugins => rules}/strings.rs | 0 .../{plugins => rules}/unused_annotation.rs | 0 .../{plugins => rules}/unused_variable.rs | 0 src/pygrep_hooks/mod.rs | 4 +- .../{plugins => rules}/blanket_noqa.rs | 0 .../{plugins => rules}/blanket_type_ignore.rs | 0 .../{plugins => rules}/deprecated_log_warn.rs | 0 src/pygrep_hooks/{plugins => rules}/mod.rs | 0 .../{plugins => rules}/no_eval.rs | 0 src/pylint/mod.rs | 4 +- .../{plugins => rules}/await_outside_async.rs | 0 .../{plugins => rules}/merge_isinstance.rs | 0 .../misplaced_comparison_constant.rs | 0 src/pylint/{plugins => rules}/mod.rs | 0 .../property_with_parameters.rs | 0 .../unnecessary_direct_lambda_call.rs | 0 .../{plugins => rules}/use_from_import.rs | 0 src/pylint/{plugins => rules}/use_sys_exit.rs | 0 .../used_prior_global_declaration.rs | 0 .../useless_else_on_loop.rs | 0 .../useless_import_alias.rs | 0 src/pyupgrade/checks.rs | 255 -------- src/pyupgrade/mod.rs | 5 +- src/pyupgrade/plugins/mod.rs | 55 -- src/pyupgrade/plugins/type_of_primitive.rs | 27 - .../plugins/unnecessary_lru_cache_params.rs | 21 - .../plugins/useless_object_inheritance.rs | 30 - ...convert_named_tuple_functional_to_class.rs | 0 .../convert_typed_dict_functional_to_class.rs | 0 .../{plugins => rules}/datetime_utc_alias.rs | 0 .../deprecated_unittest_alias.rs | 0 src/pyupgrade/rules/mod.rs | 161 +++++ .../{plugins => rules}/native_literals.rs | 0 .../{plugins => rules}/open_alias.rs | 0 .../{plugins => rules}/os_error_alias.rs | 0 .../redundant_open_modes.rs | 0 .../{plugins => rules}/remove_six_compat.rs | 0 .../replace_stdout_stderr.rs | 0 .../replace_universal_newlines.rs | 0 .../rewrite_c_element_tree.rs | 0 .../{plugins => rules}/rewrite_mock_import.rs | 0 .../rewrite_unicode_literal.rs | 0 .../{plugins => rules}/rewrite_yield_from.rs | 0 .../super_call_with_parameters.rs | 4 +- src/pyupgrade/rules/type_of_primitive.rs | 51 ++ .../typing_text_str_alias.rs | 0 .../unnecessary_builtin_import.rs | 0 .../unnecessary_encode_utf8.rs | 0 .../unnecessary_future_import.rs | 0 .../rules/unnecessary_lru_cache_params.rs | 88 +++ .../unpack_list_comprehension.rs | 0 .../use_pep585_annotation.rs | 0 .../use_pep604_annotation.rs | 0 .../useless_metaclass_type.rs | 26 +- .../rules/useless_object_inheritance.rs | 60 ++ src/ruff/mod.rs | 4 +- src/ruff/{checks.rs => rules.rs} | 0 src/settings/options.rs | 2 +- 195 files changed, 1132 insertions(+), 1192 deletions(-) rename src/eradicate/{checks.rs => rules.rs} (100%) rename src/flake8_2020/{plugins.rs => rules.rs} (100%) rename src/flake8_annotations/{plugins.rs => rules.rs} (100%) rename src/flake8_bandit/{checks => rules}/assert_used.rs (100%) rename src/flake8_bandit/{checks => rules}/bad_file_permissions.rs (100%) rename src/flake8_bandit/{checks => rules}/exec_used.rs (100%) rename src/flake8_bandit/{checks => rules}/hardcoded_bind_all_interfaces.rs (100%) rename src/flake8_bandit/{checks => rules}/hardcoded_password_default.rs (100%) rename src/flake8_bandit/{checks => rules}/hardcoded_password_func_arg.rs (100%) rename src/flake8_bandit/{checks => rules}/hardcoded_password_string.rs (100%) rename src/flake8_bandit/{checks => rules}/hardcoded_tmp_directory.rs (100%) rename src/flake8_bandit/{checks => rules}/hashlib_insecure_hash_functions.rs (100%) rename src/flake8_bandit/{checks => rules}/mod.rs (100%) rename src/flake8_bandit/{checks => rules}/request_with_no_cert_validation.rs (100%) rename src/flake8_bandit/{checks => rules}/request_without_timeout.rs (100%) rename src/flake8_bandit/{checks => rules}/unsafe_yaml_load.rs (100%) rename src/flake8_blind_except/{plugins.rs => rules.rs} (100%) rename src/flake8_boolean_trap/{plugins.rs => rules.rs} (100%) rename src/flake8_bugbear/{plugins => rules}/abstract_base_class.rs (100%) rename src/flake8_bugbear/{plugins => rules}/assert_false.rs (100%) rename src/flake8_bugbear/{plugins => rules}/assert_raises_exception.rs (100%) rename src/flake8_bugbear/{plugins => rules}/assignment_to_os_environ.rs (100%) rename src/flake8_bugbear/{plugins => rules}/cached_instance_method.rs (100%) rename src/flake8_bugbear/{plugins => rules}/cannot_raise_literal.rs (100%) rename src/flake8_bugbear/{plugins => rules}/duplicate_exceptions.rs (100%) rename src/flake8_bugbear/{plugins => rules}/f_string_docstring.rs (100%) rename src/flake8_bugbear/{plugins => rules}/function_call_argument_default.rs (97%) rename src/flake8_bugbear/{plugins => rules}/function_uses_loop_variable.rs (100%) rename src/flake8_bugbear/{plugins => rules}/getattr_with_constant.rs (100%) rename src/flake8_bugbear/{plugins => rules}/jump_statement_in_finally.rs (100%) rename src/flake8_bugbear/{plugins => rules}/loop_variable_overrides_iterator.rs (100%) rename src/flake8_bugbear/{plugins => rules}/mod.rs (100%) rename src/flake8_bugbear/{plugins => rules}/mutable_argument_default.rs (100%) rename src/flake8_bugbear/{plugins => rules}/raise_without_from_inside_except.rs (100%) rename src/flake8_bugbear/{plugins => rules}/redundant_tuple_in_exception_handler.rs (100%) rename src/flake8_bugbear/{plugins => rules}/setattr_with_constant.rs (100%) rename src/flake8_bugbear/{plugins => rules}/star_arg_unpacking_after_keyword_arg.rs (100%) rename src/flake8_bugbear/{plugins => rules}/strip_with_multi_characters.rs (100%) rename src/flake8_bugbear/{plugins => rules}/unary_prefix_increment.rs (100%) rename src/flake8_bugbear/{plugins => rules}/unreliable_callable_check.rs (100%) rename src/flake8_bugbear/{plugins => rules}/unused_loop_control_variable.rs (100%) rename src/flake8_bugbear/{plugins => rules}/useless_comparison.rs (100%) rename src/flake8_bugbear/{plugins => rules}/useless_contextlib_suppress.rs (100%) rename src/flake8_bugbear/{plugins => rules}/useless_expression.rs (100%) rename src/flake8_bugbear/{plugins => rules}/zip_without_explicit_strict.rs (100%) rename src/flake8_builtins/{checks.rs => rules.rs} (100%) rename src/flake8_comprehensions/{checks.rs => rules.rs} (100%) rename src/flake8_datetimez/{plugins.rs => rules.rs} (100%) rename src/flake8_debugger/{checks.rs => rules.rs} (100%) rename src/flake8_errmsg/{plugins.rs => rules.rs} (100%) rename src/flake8_implicit_str_concat/{checks.rs => rules.rs} (100%) rename src/flake8_import_conventions/{checks.rs => rules.rs} (100%) rename src/flake8_pie/{plugins.rs => rules.rs} (100%) rename src/flake8_print/{plugins => rules}/mod.rs (100%) rename src/flake8_print/{plugins => rules}/print_call.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/assertion.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/fail.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/fixture.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/helpers.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/imports.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/marks.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/mod.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/parametrize.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/patch.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/raises.rs (100%) rename src/flake8_pytest_style/{plugins => rules}/unittest_assert.rs (100%) rename src/flake8_quotes/{checks.rs => rules.rs} (100%) rename src/flake8_return/{plugins.rs => rules.rs} (100%) rename src/flake8_simplify/{plugins => rules}/ast_bool_op.rs (100%) rename src/flake8_simplify/{plugins => rules}/ast_for.rs (100%) rename src/flake8_simplify/{plugins => rules}/ast_if.rs (100%) rename src/flake8_simplify/{plugins => rules}/ast_ifexp.rs (100%) rename src/flake8_simplify/{plugins => rules}/ast_unary_op.rs (100%) rename src/flake8_simplify/{plugins => rules}/ast_with.rs (100%) rename src/flake8_simplify/{plugins => rules}/key_in_dict.rs (100%) rename src/flake8_simplify/{plugins => rules}/mod.rs (100%) rename src/flake8_simplify/{plugins => rules}/return_in_try_except_finally.rs (100%) rename src/flake8_simplify/{plugins => rules}/use_contextlib_suppress.rs (100%) rename src/flake8_simplify/{plugins => rules}/yoda_conditions.rs (100%) rename src/flake8_tidy_imports/{checks.rs => rules.rs} (100%) rename src/flake8_unused_arguments/{plugins.rs => rules.rs} (100%) rename src/isort/{plugins.rs => rules.rs} (100%) rename src/mccabe/{checks.rs => rules.rs} (99%) rename src/pandas_vet/{checks.rs => rules.rs} (100%) delete mode 100644 src/pep8_naming/plugins.rs rename src/pep8_naming/{checks.rs => rules.rs} (84%) delete mode 100644 src/pycodestyle/checks.rs rename src/pycodestyle/{plugins.rs => rules.rs} (57%) rename src/pydocstyle/{plugins.rs => rules.rs} (100%) delete mode 100644 src/pyflakes/plugins/assert_tuple.rs delete mode 100644 src/pyflakes/plugins/if_tuple.rs delete mode 100644 src/pyflakes/plugins/mod.rs create mode 100644 src/pyflakes/rules/assert_tuple.rs rename src/pyflakes/{plugins => rules}/f_string_missing_placeholders.rs (100%) create mode 100644 src/pyflakes/rules/if_tuple.rs rename src/pyflakes/{plugins => rules}/invalid_literal_comparisons.rs (100%) rename src/pyflakes/{plugins => rules}/invalid_print_syntax.rs (100%) rename src/pyflakes/{checks.rs => rules/mod.rs} (80%) rename src/pyflakes/{plugins => rules}/raise_not_implemented.rs (100%) rename src/pyflakes/{plugins => rules}/repeated_keys.rs (100%) rename src/pyflakes/{plugins => rules}/strings.rs (100%) rename src/pyflakes/{plugins => rules}/unused_annotation.rs (100%) rename src/pyflakes/{plugins => rules}/unused_variable.rs (100%) rename src/pygrep_hooks/{plugins => rules}/blanket_noqa.rs (100%) rename src/pygrep_hooks/{plugins => rules}/blanket_type_ignore.rs (100%) rename src/pygrep_hooks/{plugins => rules}/deprecated_log_warn.rs (100%) rename src/pygrep_hooks/{plugins => rules}/mod.rs (100%) rename src/pygrep_hooks/{plugins => rules}/no_eval.rs (100%) rename src/pylint/{plugins => rules}/await_outside_async.rs (100%) rename src/pylint/{plugins => rules}/merge_isinstance.rs (100%) rename src/pylint/{plugins => rules}/misplaced_comparison_constant.rs (100%) rename src/pylint/{plugins => rules}/mod.rs (100%) rename src/pylint/{plugins => rules}/property_with_parameters.rs (100%) rename src/pylint/{plugins => rules}/unnecessary_direct_lambda_call.rs (100%) rename src/pylint/{plugins => rules}/use_from_import.rs (100%) rename src/pylint/{plugins => rules}/use_sys_exit.rs (100%) rename src/pylint/{plugins => rules}/used_prior_global_declaration.rs (100%) rename src/pylint/{plugins => rules}/useless_else_on_loop.rs (100%) rename src/pylint/{plugins => rules}/useless_import_alias.rs (100%) delete mode 100644 src/pyupgrade/checks.rs delete mode 100644 src/pyupgrade/plugins/mod.rs delete mode 100644 src/pyupgrade/plugins/type_of_primitive.rs delete mode 100644 src/pyupgrade/plugins/unnecessary_lru_cache_params.rs delete mode 100644 src/pyupgrade/plugins/useless_object_inheritance.rs rename src/pyupgrade/{plugins => rules}/convert_named_tuple_functional_to_class.rs (100%) rename src/pyupgrade/{plugins => rules}/convert_typed_dict_functional_to_class.rs (100%) rename src/pyupgrade/{plugins => rules}/datetime_utc_alias.rs (100%) rename src/pyupgrade/{plugins => rules}/deprecated_unittest_alias.rs (100%) create mode 100644 src/pyupgrade/rules/mod.rs rename src/pyupgrade/{plugins => rules}/native_literals.rs (100%) rename src/pyupgrade/{plugins => rules}/open_alias.rs (100%) rename src/pyupgrade/{plugins => rules}/os_error_alias.rs (100%) rename src/pyupgrade/{plugins => rules}/redundant_open_modes.rs (100%) rename src/pyupgrade/{plugins => rules}/remove_six_compat.rs (100%) rename src/pyupgrade/{plugins => rules}/replace_stdout_stderr.rs (100%) rename src/pyupgrade/{plugins => rules}/replace_universal_newlines.rs (100%) rename src/pyupgrade/{plugins => rules}/rewrite_c_element_tree.rs (100%) rename src/pyupgrade/{plugins => rules}/rewrite_mock_import.rs (100%) rename src/pyupgrade/{plugins => rules}/rewrite_unicode_literal.rs (100%) rename src/pyupgrade/{plugins => rules}/rewrite_yield_from.rs (100%) rename src/pyupgrade/{plugins => rules}/super_call_with_parameters.rs (88%) create mode 100644 src/pyupgrade/rules/type_of_primitive.rs rename src/pyupgrade/{plugins => rules}/typing_text_str_alias.rs (100%) rename src/pyupgrade/{plugins => rules}/unnecessary_builtin_import.rs (100%) rename src/pyupgrade/{plugins => rules}/unnecessary_encode_utf8.rs (100%) rename src/pyupgrade/{plugins => rules}/unnecessary_future_import.rs (100%) create mode 100644 src/pyupgrade/rules/unnecessary_lru_cache_params.rs rename src/pyupgrade/{plugins => rules}/unpack_list_comprehension.rs (100%) rename src/pyupgrade/{plugins => rules}/use_pep585_annotation.rs (100%) rename src/pyupgrade/{plugins => rules}/use_pep604_annotation.rs (100%) rename src/pyupgrade/{plugins => rules}/useless_metaclass_type.rs (62%) create mode 100644 src/pyupgrade/rules/useless_object_inheritance.rs rename src/ruff/{checks.rs => rules.rs} (100%) diff --git a/README.md b/README.md index d829725ac1..270ed10656 100644 --- a/README.md +++ b/README.md @@ -1903,7 +1903,7 @@ extend-select = ["B", "Q"] A list of check codes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented -in Ruff. +by Ruff. **Default value**: `[]` diff --git a/ruff.schema.json b/ruff.schema.json index 796198c252..eebc671701 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -77,7 +77,7 @@ } }, "external": { - "description": "A list of check codes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented in Ruff.", + "description": "A list of check codes that are unsupported by Ruff, but should be preserved when (e.g.) validating `# noqa` directives. Useful for retaining `# noqa` directives that cover plugins not yet implemented by Ruff.", "type": [ "array", "null" diff --git a/scripts/add_check.py b/scripts/add_check.py index 018530a9c2..6092e078fb 100644 --- a/scripts/add_check.py +++ b/scripts/add_check.py @@ -43,8 +43,8 @@ def main(*, name: str, code: str, plugin: str) -> None: with open(os.path.join(ROOT_DIR, f"src/{dir_name(plugin)}/mod.rs"), "w") as fp: for line in content.splitlines(): - if line.strip() == "fn diagnostics(check_code: RuleCode, path: &Path) -> Result<()> {": - indent = line.split("fn diagnostics(check_code: RuleCode, path: &Path) -> Result<()> {")[0] + if line.strip() == "fn rules(check_code: RuleCode, path: &Path) -> Result<()> {": + indent = line.split("fn rules(check_code: RuleCode, path: &Path) -> Result<()> {")[0] fp.write(f'{indent}#[test_case(RuleCode::{code}, Path::new("{code}.py"); "{code}")]') fp.write("\n") diff --git a/scripts/add_plugin.py b/scripts/add_plugin.py index 9838375e86..ecddd97b3f 100644 --- a/scripts/add_plugin.py +++ b/scripts/add_plugin.py @@ -31,10 +31,10 @@ def main(*, plugin: str, url: str) -> None: # Create the Rust module. os.makedirs(os.path.join(ROOT_DIR, f"src/{dir_name(plugin)}"), exist_ok=True) - with open(os.path.join(ROOT_DIR, f"src/{dir_name(plugin)}/plugins.rs"), "a"): + with open(os.path.join(ROOT_DIR, f"src/{dir_name(plugin)}/rules"), "a"): pass - with open(os.path.join(ROOT_DIR, f"src/{dir_name(plugin)}/mod.rs"), "w+") as fp: - fp.write("pub mod plugins;\n") + with open(os.path.join(ROOT_DIR, f"src/{dir_name(plugin)}/rules"), "w+") as fp: + fp.write("pub mod rules;\n") fp.write("\n") fp.write( """#[cfg(test)] @@ -49,7 +49,7 @@ mod tests { use crate::linter::test_path; use crate::settings; - fn diagnostics(check_code: RuleCode, path: &Path) -> Result<()> { + fn rules(check_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", check_code.as_ref(), path.to_string_lossy()); let diagnostics =test_path( Path::new("./resources/test/fixtures/%s") diff --git a/src/checkers/ast.rs b/src/checkers/ast.rs index 0d6a88f7c5..429f9207cc 100644 --- a/src/checkers/ast.rs +++ b/src/checkers/ast.rs @@ -277,7 +277,7 @@ where if self.settings.enabled.contains(&RuleCode::E741) { self.diagnostics .extend(names.iter().zip(ranges.iter()).filter_map(|(name, range)| { - pycodestyle::checks::ambiguous_variable_name(name, *range) + pycodestyle::rules::ambiguous_variable_name(name, *range) })); } } @@ -325,13 +325,13 @@ where if self.settings.enabled.contains(&RuleCode::E741) { self.diagnostics .extend(names.iter().zip(ranges.iter()).filter_map(|(name, range)| { - pycodestyle::checks::ambiguous_variable_name(name, *range) + pycodestyle::rules::ambiguous_variable_name(name, *range) })); } } StmtKind::Break => { if self.settings.enabled.contains(&RuleCode::F701) { - if let Some(diagnostic) = pyflakes::checks::break_outside_loop( + if let Some(diagnostic) = pyflakes::rules::break_outside_loop( stmt, &mut self .parents @@ -346,7 +346,7 @@ where } StmtKind::Continue => { if self.settings.enabled.contains(&RuleCode::F702) { - if let Some(diagnostic) = pyflakes::checks::continue_outside_loop( + if let Some(diagnostic) = pyflakes::rules::continue_outside_loop( stmt, &mut self .parents @@ -377,7 +377,7 @@ where } => { if self.settings.enabled.contains(&RuleCode::E743) { if let Some(diagnostic) = - pycodestyle::checks::ambiguous_function_name(name, || { + pycodestyle::rules::ambiguous_function_name(name, || { helpers::identifier_range(stmt, self.locator) }) { @@ -386,7 +386,7 @@ where } if self.settings.enabled.contains(&RuleCode::N802) { - if let Some(diagnostic) = pep8_naming::checks::invalid_function_name( + if let Some(diagnostic) = pep8_naming::rules::invalid_function_name( stmt, name, &self.settings.pep8_naming.ignore_names, @@ -398,7 +398,7 @@ where if self.settings.enabled.contains(&RuleCode::N804) { if let Some(diagnostic) = - pep8_naming::checks::invalid_first_argument_name_for_class_method( + pep8_naming::rules::invalid_first_argument_name_for_class_method( self.current_scope(), name, decorator_list, @@ -414,7 +414,7 @@ where if self.settings.enabled.contains(&RuleCode::N805) { if let Some(diagnostic) = - pep8_naming::checks::invalid_first_argument_name_for_method( + pep8_naming::rules::invalid_first_argument_name_for_method( self.current_scope(), name, decorator_list, @@ -429,7 +429,7 @@ where } if self.settings.enabled.contains(&RuleCode::N807) { - if let Some(diagnostic) = pep8_naming::checks::dunder_function_name( + if let Some(diagnostic) = pep8_naming::rules::dunder_function_name( self.current_scope(), stmt, name, @@ -442,15 +442,15 @@ where if self.settings.enabled.contains(&RuleCode::UP011) && self.settings.target_version >= PythonVersion::Py38 { - pyupgrade::plugins::unnecessary_lru_cache_params(self, decorator_list); + pyupgrade::rules::unnecessary_lru_cache_params(self, decorator_list); } if self.settings.enabled.contains(&RuleCode::B018) { - flake8_bugbear::plugins::useless_expression(self, body); + flake8_bugbear::rules::useless_expression(self, body); } if self.settings.enabled.contains(&RuleCode::B019) { - flake8_bugbear::plugins::cached_instance_method(self, decorator_list); + flake8_bugbear::rules::cached_instance_method(self, decorator_list); } if self.settings.enabled.contains(&RuleCode::RET501) @@ -462,11 +462,11 @@ where || self.settings.enabled.contains(&RuleCode::RET507) || self.settings.enabled.contains(&RuleCode::RET508) { - flake8_return::plugins::function(self, body); + flake8_return::rules::function(self, body); } if self.settings.enabled.contains(&RuleCode::C901) { - if let Some(diagnostic) = mccabe::checks::function_is_too_complex( + if let Some(diagnostic) = mccabe::rules::function_is_too_complex( stmt, name, body, @@ -479,11 +479,11 @@ where if self.settings.enabled.contains(&RuleCode::S107) { self.diagnostics - .extend(flake8_bandit::checks::hardcoded_password_default(args)); + .extend(flake8_bandit::rules::hardcoded_password_default(args)); } if self.settings.enabled.contains(&RuleCode::PLR0206) { - pylint::plugins::property_with_parameters(self, stmt, decorator_list, args); + pylint::rules::property_with_parameters(self, stmt, decorator_list, args); } if self.settings.enabled.contains(&RuleCode::PT001) @@ -498,7 +498,7 @@ where || self.settings.enabled.contains(&RuleCode::PT024) || self.settings.enabled.contains(&RuleCode::PT025) { - flake8_pytest_style::plugins::fixture( + flake8_pytest_style::rules::fixture( self, stmt, name, @@ -511,13 +511,13 @@ where if self.settings.enabled.contains(&RuleCode::PT006) || self.settings.enabled.contains(&RuleCode::PT007) { - flake8_pytest_style::plugins::parametrize(self, decorator_list); + flake8_pytest_style::rules::parametrize(self, decorator_list); } if self.settings.enabled.contains(&RuleCode::PT023) || self.settings.enabled.contains(&RuleCode::PT026) { - flake8_pytest_style::plugins::marks(self, decorator_list); + flake8_pytest_style::rules::marks(self, decorator_list); } self.check_builtin_shadowing(name, stmt, true); @@ -594,31 +594,27 @@ where body, } => { if self.settings.enabled.contains(&RuleCode::UP004) { - pyupgrade::plugins::useless_object_inheritance( - self, stmt, name, bases, keywords, - ); + pyupgrade::rules::useless_object_inheritance(self, stmt, name, bases, keywords); } if self.settings.enabled.contains(&RuleCode::E742) { - if let Some(diagnostic) = - pycodestyle::checks::ambiguous_class_name(name, || { - helpers::identifier_range(stmt, self.locator) - }) - { + if let Some(diagnostic) = pycodestyle::rules::ambiguous_class_name(name, || { + helpers::identifier_range(stmt, self.locator) + }) { self.diagnostics.push(diagnostic); } } if self.settings.enabled.contains(&RuleCode::N801) { if let Some(diagnostic) = - pep8_naming::checks::invalid_class_name(stmt, name, self.locator) + pep8_naming::rules::invalid_class_name(stmt, name, self.locator) { self.diagnostics.push(diagnostic); } } if self.settings.enabled.contains(&RuleCode::N818) { - if let Some(diagnostic) = pep8_naming::checks::error_suffix_on_exception_name( + if let Some(diagnostic) = pep8_naming::rules::error_suffix_on_exception_name( stmt, bases, name, @@ -629,23 +625,23 @@ where } if self.settings.enabled.contains(&RuleCode::B018) { - flake8_bugbear::plugins::useless_expression(self, body); + flake8_bugbear::rules::useless_expression(self, body); } if self.settings.enabled.contains(&RuleCode::B024) || self.settings.enabled.contains(&RuleCode::B027) { - flake8_bugbear::plugins::abstract_base_class( + flake8_bugbear::rules::abstract_base_class( self, stmt, name, bases, keywords, body, ); } if self.settings.enabled.contains(&RuleCode::PT023) { - flake8_pytest_style::plugins::marks(self, decorator_list); + flake8_pytest_style::rules::marks(self, decorator_list); } if self.settings.enabled.contains(&RuleCode::PIE794) { - flake8_pie::plugins::dupe_class_field_definitions(self, bases, body); + flake8_pie::rules::dupe_class_field_definitions(self, bases, body); } self.check_builtin_shadowing(name, stmt, false); @@ -679,10 +675,10 @@ where } } if self.settings.enabled.contains(&RuleCode::UP023) { - pyupgrade::plugins::replace_c_element_tree(self, stmt); + pyupgrade::rules::replace_c_element_tree(self, stmt); } if self.settings.enabled.contains(&RuleCode::UP026) { - pyupgrade::plugins::rewrite_mock_import(self, stmt); + pyupgrade::rules::rewrite_mock_import(self, stmt); } for alias in names { @@ -748,7 +744,7 @@ where // flake8-debugger if self.settings.enabled.contains(&RuleCode::T100) { if let Some(diagnostic) = - flake8_debugger::checks::debugger_import(stmt, None, &alias.node.name) + flake8_debugger::rules::debugger_import(stmt, None, &alias.node.name) { self.diagnostics.push(diagnostic); } @@ -757,7 +753,7 @@ where // flake8_tidy_imports if self.settings.enabled.contains(&RuleCode::TID251) { if let Some(diagnostic) = - flake8_tidy_imports::checks::name_or_parent_is_banned( + flake8_tidy_imports::rules::name_or_parent_is_banned( alias, &alias.node.name, &self.settings.flake8_tidy_imports.banned_api, @@ -769,10 +765,10 @@ where // pylint if self.settings.enabled.contains(&RuleCode::PLC0414) { - pylint::plugins::useless_import_alias(self, alias); + pylint::rules::useless_import_alias(self, alias); } if self.settings.enabled.contains(&RuleCode::PLR0402) { - pylint::plugins::use_from_import(self, alias); + pylint::rules::use_from_import(self, alias); } if let Some(asname) = &alias.node.asname { @@ -785,7 +781,7 @@ where let name = alias.node.name.split('.').last().unwrap(); if self.settings.enabled.contains(&RuleCode::N811) { if let Some(diagnostic) = - pep8_naming::checks::constant_imported_as_non_constant( + pep8_naming::rules::constant_imported_as_non_constant( stmt, name, asname, @@ -798,7 +794,7 @@ where if self.settings.enabled.contains(&RuleCode::N812) { if let Some(diagnostic) = - pep8_naming::checks::lowercase_imported_as_non_lowercase( + pep8_naming::rules::lowercase_imported_as_non_lowercase( stmt, name, asname, @@ -811,7 +807,7 @@ where if self.settings.enabled.contains(&RuleCode::N813) { if let Some(diagnostic) = - pep8_naming::checks::camelcase_imported_as_lowercase( + pep8_naming::rules::camelcase_imported_as_lowercase( stmt, name, asname, @@ -824,7 +820,7 @@ where if self.settings.enabled.contains(&RuleCode::N814) { if let Some(diagnostic) = - pep8_naming::checks::camelcase_imported_as_constant( + pep8_naming::rules::camelcase_imported_as_constant( stmt, name, asname, @@ -837,7 +833,7 @@ where if self.settings.enabled.contains(&RuleCode::N817) { if let Some(diagnostic) = - pep8_naming::checks::camelcase_imported_as_acronym( + pep8_naming::rules::camelcase_imported_as_acronym( stmt, name, asname, @@ -851,7 +847,7 @@ where if self.settings.enabled.contains(&RuleCode::ICN001) { if let Some(diagnostic) = - flake8_import_conventions::checks::check_conventional_import( + flake8_import_conventions::rules::check_conventional_import( stmt, &alias.node.name, alias.node.asname.as_deref(), @@ -863,7 +859,7 @@ where } if self.settings.enabled.contains(&RuleCode::PT013) { - if let Some(diagnostic) = flake8_pytest_style::plugins::import( + if let Some(diagnostic) = flake8_pytest_style::rules::import( stmt, &alias.node.name, alias.node.asname.as_deref(), @@ -881,7 +877,7 @@ where // Track `import from` statements, to ensure that we can correctly attribute // references like `from typing import Union`. if self.settings.enabled.contains(&RuleCode::UP023) { - pyupgrade::plugins::replace_c_element_tree(self, stmt); + pyupgrade::rules::replace_c_element_tree(self, stmt); } if level.map(|level| level == 0).unwrap_or(true) { if let Some(module) = module { @@ -908,22 +904,22 @@ where if self.settings.enabled.contains(&RuleCode::UP010) { if let Some("__future__") = module.as_deref() { - pyupgrade::plugins::unnecessary_future_import(self, stmt, names); + pyupgrade::rules::unnecessary_future_import(self, stmt, names); } } if self.settings.enabled.contains(&RuleCode::UP026) { - pyupgrade::plugins::rewrite_mock_import(self, stmt); + pyupgrade::rules::rewrite_mock_import(self, stmt); } if self.settings.enabled.contains(&RuleCode::UP029) { if let Some(module) = module.as_deref() { - pyupgrade::plugins::unnecessary_builtin_import(self, stmt, module, names); + pyupgrade::rules::unnecessary_builtin_import(self, stmt, module, names); } } if self.settings.enabled.contains(&RuleCode::TID251) { if let Some(module) = module { for name in names { - if let Some(diagnostic) = flake8_tidy_imports::checks::name_is_banned( + if let Some(diagnostic) = flake8_tidy_imports::rules::name_is_banned( module, name, &self.settings.flake8_tidy_imports.banned_api, @@ -932,7 +928,7 @@ where } } if let Some(diagnostic) = - flake8_tidy_imports::checks::name_or_parent_is_banned( + flake8_tidy_imports::rules::name_or_parent_is_banned( stmt, module, &self.settings.flake8_tidy_imports.banned_api, @@ -944,7 +940,7 @@ where } if self.settings.enabled.contains(&RuleCode::PT013) { - if let Some(diagnostic) = flake8_pytest_style::plugins::import_from( + if let Some(diagnostic) = flake8_pytest_style::rules::import_from( stmt, module.as_deref(), level.as_ref(), @@ -1080,20 +1076,18 @@ where } if self.settings.enabled.contains(&RuleCode::TID252) { - if let Some(diagnostic) = - flake8_tidy_imports::checks::banned_relative_import( - stmt, - level.as_ref(), - &self.settings.flake8_tidy_imports.ban_relative_imports, - ) - { + if let Some(diagnostic) = flake8_tidy_imports::rules::banned_relative_import( + stmt, + level.as_ref(), + &self.settings.flake8_tidy_imports.ban_relative_imports, + ) { self.diagnostics.push(diagnostic); } } // flake8-debugger if self.settings.enabled.contains(&RuleCode::T100) { - if let Some(diagnostic) = flake8_debugger::checks::debugger_import( + if let Some(diagnostic) = flake8_debugger::rules::debugger_import( stmt, module.as_deref(), &alias.node.name, @@ -1105,7 +1099,7 @@ where if let Some(asname) = &alias.node.asname { if self.settings.enabled.contains(&RuleCode::N811) { if let Some(diagnostic) = - pep8_naming::checks::constant_imported_as_non_constant( + pep8_naming::rules::constant_imported_as_non_constant( stmt, &alias.node.name, asname, @@ -1118,7 +1112,7 @@ where if self.settings.enabled.contains(&RuleCode::N812) { if let Some(diagnostic) = - pep8_naming::checks::lowercase_imported_as_non_lowercase( + pep8_naming::rules::lowercase_imported_as_non_lowercase( stmt, &alias.node.name, asname, @@ -1131,7 +1125,7 @@ where if self.settings.enabled.contains(&RuleCode::N813) { if let Some(diagnostic) = - pep8_naming::checks::camelcase_imported_as_lowercase( + pep8_naming::rules::camelcase_imported_as_lowercase( stmt, &alias.node.name, asname, @@ -1144,7 +1138,7 @@ where if self.settings.enabled.contains(&RuleCode::N814) { if let Some(diagnostic) = - pep8_naming::checks::camelcase_imported_as_constant( + pep8_naming::rules::camelcase_imported_as_constant( stmt, &alias.node.name, asname, @@ -1157,7 +1151,7 @@ where if self.settings.enabled.contains(&RuleCode::N817) { if let Some(diagnostic) = - pep8_naming::checks::camelcase_imported_as_acronym( + pep8_naming::rules::camelcase_imported_as_acronym( stmt, &alias.node.name, asname, @@ -1170,7 +1164,7 @@ where // pylint if self.settings.enabled.contains(&RuleCode::PLC0414) { - pylint::plugins::useless_import_alias(self, alias); + pylint::rules::useless_import_alias(self, alias); } } } @@ -1178,12 +1172,12 @@ where StmtKind::Raise { exc, .. } => { if self.settings.enabled.contains(&RuleCode::F901) { if let Some(expr) = exc { - pyflakes::plugins::raise_not_implemented(self, expr); + pyflakes::rules::raise_not_implemented(self, expr); } } if self.settings.enabled.contains(&RuleCode::B016) { if let Some(exc) = exc { - flake8_bugbear::plugins::cannot_raise_literal(self, exc); + flake8_bugbear::rules::cannot_raise_literal(self, exc); } } if self.settings.enabled.contains(&RuleCode::EM101) @@ -1191,12 +1185,12 @@ where || self.settings.enabled.contains(&RuleCode::EM103) { if let Some(exc) = exc { - flake8_errmsg::plugins::string_in_exception(self, exc); + flake8_errmsg::rules::string_in_exception(self, exc); } } if self.settings.enabled.contains(&RuleCode::UP024) { if let Some(item) = exc { - pyupgrade::plugins::os_error_alias(self, item); + pyupgrade::rules::os_error_alias(self, item); } } } @@ -1205,16 +1199,16 @@ where } StmtKind::If { test, .. } => { if self.settings.enabled.contains(&RuleCode::F634) { - pyflakes::plugins::if_tuple(self, stmt, test); + pyflakes::rules::if_tuple(self, stmt, test); } if self.settings.enabled.contains(&RuleCode::SIM102) { - flake8_simplify::plugins::nested_if_statements(self, stmt); + flake8_simplify::rules::nested_if_statements(self, stmt); } if self.settings.enabled.contains(&RuleCode::SIM103) { - flake8_simplify::plugins::return_bool_condition_directly(self, stmt); + flake8_simplify::rules::return_bool_condition_directly(self, stmt); } if self.settings.enabled.contains(&RuleCode::SIM108) { - flake8_simplify::plugins::use_ternary_operator( + flake8_simplify::rules::use_ternary_operator( self, stmt, self.current_stmt_parent().map(|parent| parent.0), @@ -1223,10 +1217,10 @@ where } StmtKind::Assert { test, msg } => { if self.settings.enabled.contains(&RuleCode::F631) { - pyflakes::plugins::assert_tuple(self, stmt, test); + pyflakes::rules::assert_tuple(self, stmt, test); } if self.settings.enabled.contains(&RuleCode::B011) { - flake8_bugbear::plugins::assert_false( + flake8_bugbear::rules::assert_false( self, stmt, test, @@ -1235,17 +1229,16 @@ where } if self.settings.enabled.contains(&RuleCode::S101) { self.diagnostics - .push(flake8_bandit::checks::assert_used(stmt)); + .push(flake8_bandit::rules::assert_used(stmt)); } if self.settings.enabled.contains(&RuleCode::PT015) { - if let Some(diagnostic) = flake8_pytest_style::plugins::assert_falsy(stmt, test) - { + if let Some(diagnostic) = flake8_pytest_style::rules::assert_falsy(stmt, test) { self.diagnostics.push(diagnostic); } } if self.settings.enabled.contains(&RuleCode::PT018) { if let Some(diagnostic) = - flake8_pytest_style::plugins::composite_condition(stmt, test) + flake8_pytest_style::rules::composite_condition(stmt, test) { self.diagnostics.push(diagnostic); } @@ -1253,21 +1246,21 @@ where } StmtKind::With { items, body, .. } | StmtKind::AsyncWith { items, body, .. } => { if self.settings.enabled.contains(&RuleCode::B017) { - flake8_bugbear::plugins::assert_raises_exception(self, stmt, items); + flake8_bugbear::rules::assert_raises_exception(self, stmt, items); } if self.settings.enabled.contains(&RuleCode::PT012) { - flake8_pytest_style::plugins::complex_raises(self, stmt, items, body); + flake8_pytest_style::rules::complex_raises(self, stmt, items, body); } if self.settings.enabled.contains(&RuleCode::SIM117) { - flake8_simplify::plugins::multiple_with_statements(self, stmt); + flake8_simplify::rules::multiple_with_statements(self, stmt); } } StmtKind::While { body, orelse, .. } => { if self.settings.enabled.contains(&RuleCode::B023) { - flake8_bugbear::plugins::function_uses_loop_variable(self, &Node::Stmt(stmt)); + flake8_bugbear::rules::function_uses_loop_variable(self, &Node::Stmt(stmt)); } if self.settings.enabled.contains(&RuleCode::PLW0120) { - pylint::plugins::useless_else_on_loop(self, stmt, body, orelse); + pylint::rules::useless_else_on_loop(self, stmt, body, orelse); } } StmtKind::For { @@ -1285,19 +1278,19 @@ where .. } => { if self.settings.enabled.contains(&RuleCode::B007) { - flake8_bugbear::plugins::unused_loop_control_variable(self, target, body); + flake8_bugbear::rules::unused_loop_control_variable(self, target, body); } if self.settings.enabled.contains(&RuleCode::B020) { - flake8_bugbear::plugins::loop_variable_overrides_iterator(self, target, iter); + flake8_bugbear::rules::loop_variable_overrides_iterator(self, target, iter); } if self.settings.enabled.contains(&RuleCode::B023) { - flake8_bugbear::plugins::function_uses_loop_variable(self, &Node::Stmt(stmt)); + flake8_bugbear::rules::function_uses_loop_variable(self, &Node::Stmt(stmt)); } if self.settings.enabled.contains(&RuleCode::PLW0120) { - pylint::plugins::useless_else_on_loop(self, stmt, body, orelse); + pylint::rules::useless_else_on_loop(self, stmt, body, orelse); } if self.settings.enabled.contains(&RuleCode::SIM118) { - flake8_simplify::plugins::key_in_dict_for(self, target, iter); + flake8_simplify::rules::key_in_dict_for(self, target, iter); } } StmtKind::Try { @@ -1309,7 +1302,7 @@ where } => { if self.settings.enabled.contains(&RuleCode::F707) { if let Some(diagnostic) = - pyflakes::checks::default_except_not_last(handlers, self.locator) + pyflakes::rules::default_except_not_last(handlers, self.locator) { self.diagnostics.push(diagnostic); } @@ -1317,26 +1310,26 @@ where if self.settings.enabled.contains(&RuleCode::B014) || self.settings.enabled.contains(&RuleCode::B025) { - flake8_bugbear::plugins::duplicate_exceptions(self, handlers); + flake8_bugbear::rules::duplicate_exceptions(self, handlers); } if self.settings.enabled.contains(&RuleCode::B013) { - flake8_bugbear::plugins::redundant_tuple_in_exception_handler(self, handlers); + flake8_bugbear::rules::redundant_tuple_in_exception_handler(self, handlers); } if self.settings.enabled.contains(&RuleCode::UP024) { - pyupgrade::plugins::os_error_alias(self, handlers); + pyupgrade::rules::os_error_alias(self, handlers); } if self.settings.enabled.contains(&RuleCode::PT017) { self.diagnostics.extend( - flake8_pytest_style::plugins::assert_in_exception_handler(handlers), + flake8_pytest_style::rules::assert_in_exception_handler(handlers), ); } if self.settings.enabled.contains(&RuleCode::SIM105) { - flake8_simplify::plugins::use_contextlib_suppress( + flake8_simplify::rules::use_contextlib_suppress( self, stmt, handlers, orelse, finalbody, ); } if self.settings.enabled.contains(&RuleCode::SIM107) { - flake8_simplify::plugins::return_in_try_except_finally( + flake8_simplify::rules::return_in_try_except_finally( self, body, handlers, finalbody, ); } @@ -1344,41 +1337,41 @@ where StmtKind::Assign { targets, value, .. } => { if self.settings.enabled.contains(&RuleCode::E731) { if let [target] = &targets[..] { - pycodestyle::plugins::do_not_assign_lambda(self, target, value, stmt); + pycodestyle::rules::do_not_assign_lambda(self, target, value, stmt); } } if self.settings.enabled.contains(&RuleCode::B003) { - flake8_bugbear::plugins::assignment_to_os_environ(self, targets); + flake8_bugbear::rules::assignment_to_os_environ(self, targets); } if self.settings.enabled.contains(&RuleCode::S105) { if let Some(diagnostic) = - flake8_bandit::checks::assign_hardcoded_password_string(value, targets) + flake8_bandit::rules::assign_hardcoded_password_string(value, targets) { self.diagnostics.push(diagnostic); } } if self.settings.enabled.contains(&RuleCode::UP001) { - pyupgrade::plugins::useless_metaclass_type(self, stmt, value, targets); + pyupgrade::rules::useless_metaclass_type(self, stmt, value, targets); } if self.settings.enabled.contains(&RuleCode::UP013) { - pyupgrade::plugins::convert_typed_dict_functional_to_class( + pyupgrade::rules::convert_typed_dict_functional_to_class( self, stmt, targets, value, ); } if self.settings.enabled.contains(&RuleCode::UP014) { - pyupgrade::plugins::convert_named_tuple_functional_to_class( + pyupgrade::rules::convert_named_tuple_functional_to_class( self, stmt, targets, value, ); } if self.settings.enabled.contains(&RuleCode::UP027) { - pyupgrade::plugins::unpack_list_comprehension(self, targets, value); + pyupgrade::rules::unpack_list_comprehension(self, targets, value); } if self.settings.enabled.contains(&RuleCode::PD901) { - if let Some(diagnostic) = pandas_vet::checks::assignment_to_df(targets) { + if let Some(diagnostic) = pandas_vet::rules::assignment_to_df(targets) { self.diagnostics.push(diagnostic); } } @@ -1386,14 +1379,14 @@ where StmtKind::AnnAssign { target, value, .. } => { if self.settings.enabled.contains(&RuleCode::E731) { if let Some(value) = value { - pycodestyle::plugins::do_not_assign_lambda(self, target, value, stmt); + pycodestyle::rules::do_not_assign_lambda(self, target, value, stmt); } } } StmtKind::Delete { .. } => {} StmtKind::Expr { value, .. } => { if self.settings.enabled.contains(&RuleCode::B015) { - flake8_bugbear::plugins::useless_comparison(self, value); + flake8_bugbear::rules::useless_comparison(self, value); } } _ => {} @@ -1417,7 +1410,7 @@ where .. } => { if self.settings.enabled.contains(&RuleCode::B021) { - flake8_bugbear::plugins::f_string_docstring(self, body); + flake8_bugbear::rules::f_string_docstring(self, body); } let definition = docstrings::extraction::extract( &self.visible_scope, @@ -1426,7 +1419,7 @@ where &Documentable::Function, ); if self.settings.enabled.contains(&RuleCode::UP028) { - pyupgrade::plugins::rewrite_yield_from(self, stmt); + pyupgrade::rules::rewrite_yield_from(self, stmt); } let scope = transition_scope(&self.visible_scope, stmt, &Documentable::Function); self.definitions @@ -1478,7 +1471,7 @@ where .. } => { if self.settings.enabled.contains(&RuleCode::B021) { - flake8_bugbear::plugins::f_string_docstring(self, body); + flake8_bugbear::rules::f_string_docstring(self, body); } let definition = docstrings::extraction::extract( &self.visible_scope, @@ -1530,7 +1523,7 @@ where } => { self.except_handlers.push(extract_handler_names(handlers)); if self.settings.enabled.contains(&RuleCode::B012) { - flake8_bugbear::plugins::jump_statement_in_finally(self, finalbody); + flake8_bugbear::rules::jump_statement_in_finally(self, finalbody); } self.visit_body(body); self.except_handlers.pop(); @@ -1638,7 +1631,7 @@ where && !self.settings.pyupgrade.keep_runtime_typing && self.annotations_future_enabled)) { - pyupgrade::plugins::use_pep604_annotation(self, expr, value, slice); + pyupgrade::rules::use_pep604_annotation(self, expr, value, slice); } if self.match_typing_expr(value, "Literal") { @@ -1650,7 +1643,7 @@ where || self.settings.enabled.contains(&RuleCode::YTT301) || self.settings.enabled.contains(&RuleCode::YTT303) { - flake8_2020::plugins::subscript(self, value, slice); + flake8_2020::rules::subscript(self, value, slice); } } ExprKind::Tuple { elts, ctx } | ExprKind::List { elts, ctx } => { @@ -1659,7 +1652,7 @@ where self.settings.enabled.contains(&RuleCode::F621); let check_two_starred_expressions = self.settings.enabled.contains(&RuleCode::F622); - if let Some(diagnostic) = pyflakes::checks::starred_expressions( + if let Some(diagnostic) = pyflakes::rules::starred_expressions( elts, check_too_many_expressions, check_two_starred_expressions, @@ -1673,7 +1666,7 @@ where match ctx { ExprContext::Load => { if self.settings.enabled.contains(&RuleCode::UP019) { - pyupgrade::plugins::typing_text_str_alias(self, expr); + pyupgrade::rules::typing_text_str_alias(self, expr); } // Ex) List[...] @@ -1690,14 +1683,14 @@ where &self.import_aliases, ) { - pyupgrade::plugins::use_pep585_annotation(self, expr, id); + pyupgrade::rules::use_pep585_annotation(self, expr, id); } self.handle_node_load(expr); } ExprContext::Store => { if self.settings.enabled.contains(&RuleCode::E741) { - if let Some(diagnostic) = pycodestyle::checks::ambiguous_variable_name( + if let Some(diagnostic) = pycodestyle::rules::ambiguous_variable_name( id, Range::from_located(expr), ) { @@ -1713,11 +1706,11 @@ where } if self.settings.enabled.contains(&RuleCode::YTT202) { - flake8_2020::plugins::name_or_attribute(self, expr); + flake8_2020::rules::name_or_attribute(self, expr); } if self.settings.enabled.contains(&RuleCode::PLE0118) { - pylint::plugins::used_prior_global_declaration(self, id, expr); + pylint::rules::used_prior_global_declaration(self, id, expr); } } ExprKind::Attribute { attr, value, .. } => { @@ -1730,27 +1723,27 @@ where && self.in_annotation)) && typing::is_pep585_builtin(expr, &self.from_imports, &self.import_aliases) { - pyupgrade::plugins::use_pep585_annotation(self, expr, attr); + pyupgrade::rules::use_pep585_annotation(self, expr, attr); } if self.settings.enabled.contains(&RuleCode::UP016) { - pyupgrade::plugins::remove_six_compat(self, expr); + pyupgrade::rules::remove_six_compat(self, expr); } if self.settings.enabled.contains(&RuleCode::UP017) && self.settings.target_version >= PythonVersion::Py311 { - pyupgrade::plugins::datetime_utc_alias(self, expr); + pyupgrade::rules::datetime_utc_alias(self, expr); } if self.settings.enabled.contains(&RuleCode::UP019) { - pyupgrade::plugins::typing_text_str_alias(self, expr); + pyupgrade::rules::typing_text_str_alias(self, expr); } if self.settings.enabled.contains(&RuleCode::UP026) { - pyupgrade::plugins::rewrite_mock_attribute(self, expr); + pyupgrade::rules::rewrite_mock_attribute(self, expr); } if self.settings.enabled.contains(&RuleCode::YTT202) { - flake8_2020::plugins::name_or_attribute(self, expr); + flake8_2020::rules::name_or_attribute(self, expr); } for (code, name) in vec![ @@ -1798,7 +1791,7 @@ where } if self.settings.enabled.contains(&RuleCode::TID251) { - flake8_tidy_imports::checks::banned_attribute_access( + flake8_tidy_imports::rules::banned_attribute_access( self, &dealias_call_path(collect_call_paths(expr), &self.import_aliases), expr, @@ -1840,26 +1833,26 @@ where } Ok(summary) => { if self.settings.enabled.contains(&RuleCode::F522) { - pyflakes::plugins::string_dot_format_extra_named_arguments(self, - &summary, keywords, location, + pyflakes::rules::string_dot_format_extra_named_arguments(self, + &summary, keywords, location, ); } if self.settings.enabled.contains(&RuleCode::F523) { - pyflakes::plugins::string_dot_format_extra_positional_arguments( + pyflakes::rules::string_dot_format_extra_positional_arguments( self, &summary, args, location, ); } if self.settings.enabled.contains(&RuleCode::F524) { - pyflakes::plugins::string_dot_format_missing_argument( + pyflakes::rules::string_dot_format_missing_argument( self, &summary, args, keywords, location, ); } if self.settings.enabled.contains(&RuleCode::F525) { - pyflakes::plugins::string_dot_format_mixing_automatic( + pyflakes::rules::string_dot_format_mixing_automatic( self, &summary, location, ); } @@ -1872,83 +1865,81 @@ where // pyupgrade if self.settings.enabled.contains(&RuleCode::UP003) { - pyupgrade::plugins::type_of_primitive(self, expr, func, args); + pyupgrade::rules::type_of_primitive(self, expr, func, args); } if self.settings.enabled.contains(&RuleCode::UP005) { - pyupgrade::plugins::deprecated_unittest_alias(self, func); + pyupgrade::rules::deprecated_unittest_alias(self, func); } if self.settings.enabled.contains(&RuleCode::UP008) { - pyupgrade::plugins::super_call_with_parameters(self, expr, func, args); + pyupgrade::rules::super_call_with_parameters(self, expr, func, args); } if self.settings.enabled.contains(&RuleCode::UP012) { - pyupgrade::plugins::unnecessary_encode_utf8(self, expr, func, args, keywords); + pyupgrade::rules::unnecessary_encode_utf8(self, expr, func, args, keywords); } if self.settings.enabled.contains(&RuleCode::UP015) { - pyupgrade::plugins::redundant_open_modes(self, expr); + pyupgrade::rules::redundant_open_modes(self, expr); } if self.settings.enabled.contains(&RuleCode::UP016) { - pyupgrade::plugins::remove_six_compat(self, expr); + pyupgrade::rules::remove_six_compat(self, expr); } if self.settings.enabled.contains(&RuleCode::UP018) { - pyupgrade::plugins::native_literals(self, expr, func, args, keywords); + pyupgrade::rules::native_literals(self, expr, func, args, keywords); } if self.settings.enabled.contains(&RuleCode::UP020) { - pyupgrade::plugins::open_alias(self, expr, func); + pyupgrade::rules::open_alias(self, expr, func); } if self.settings.enabled.contains(&RuleCode::UP021) { - pyupgrade::plugins::replace_universal_newlines(self, expr, keywords); + pyupgrade::rules::replace_universal_newlines(self, expr, keywords); } if self.settings.enabled.contains(&RuleCode::UP022) { - pyupgrade::plugins::replace_stdout_stderr(self, expr, keywords); + pyupgrade::rules::replace_stdout_stderr(self, expr, keywords); } if self.settings.enabled.contains(&RuleCode::UP024) { - pyupgrade::plugins::os_error_alias(self, expr); + pyupgrade::rules::os_error_alias(self, expr); } // flake8-print if self.settings.enabled.contains(&RuleCode::T201) || self.settings.enabled.contains(&RuleCode::T203) { - flake8_print::plugins::print_call(self, func, keywords); + flake8_print::rules::print_call(self, func, keywords); } // flake8-bugbear if self.settings.enabled.contains(&RuleCode::B004) { - flake8_bugbear::plugins::unreliable_callable_check(self, expr, func, args); + flake8_bugbear::rules::unreliable_callable_check(self, expr, func, args); } if self.settings.enabled.contains(&RuleCode::B005) { - flake8_bugbear::plugins::strip_with_multi_characters(self, expr, func, args); + flake8_bugbear::rules::strip_with_multi_characters(self, expr, func, args); } if self.settings.enabled.contains(&RuleCode::B009) { - flake8_bugbear::plugins::getattr_with_constant(self, expr, func, args); + flake8_bugbear::rules::getattr_with_constant(self, expr, func, args); } if self.settings.enabled.contains(&RuleCode::B010) { - flake8_bugbear::plugins::setattr_with_constant(self, expr, func, args); + flake8_bugbear::rules::setattr_with_constant(self, expr, func, args); } if self.settings.enabled.contains(&RuleCode::B022) { - flake8_bugbear::plugins::useless_contextlib_suppress(self, expr, args); + flake8_bugbear::rules::useless_contextlib_suppress(self, expr, args); } if self.settings.enabled.contains(&RuleCode::B026) { - flake8_bugbear::plugins::star_arg_unpacking_after_keyword_arg( + flake8_bugbear::rules::star_arg_unpacking_after_keyword_arg( self, args, keywords, ); } if self.settings.enabled.contains(&RuleCode::B905) && self.settings.target_version >= PythonVersion::Py310 { - flake8_bugbear::plugins::zip_without_explicit_strict( - self, expr, func, keywords, - ); + flake8_bugbear::rules::zip_without_explicit_strict(self, expr, func, keywords); } // flake8-bandit if self.settings.enabled.contains(&RuleCode::S102) { - if let Some(diagnostic) = flake8_bandit::checks::exec_used(expr, func) { + if let Some(diagnostic) = flake8_bandit::rules::exec_used(expr, func) { self.diagnostics.push(diagnostic); } } if self.settings.enabled.contains(&RuleCode::S103) { - if let Some(diagnostic) = flake8_bandit::checks::bad_file_permissions( + if let Some(diagnostic) = flake8_bandit::rules::bad_file_permissions( func, args, keywords, @@ -1959,7 +1950,7 @@ where } } if self.settings.enabled.contains(&RuleCode::S501) { - if let Some(diagnostic) = flake8_bandit::checks::request_with_no_cert_validation( + if let Some(diagnostic) = flake8_bandit::rules::request_with_no_cert_validation( func, args, keywords, @@ -1970,7 +1961,7 @@ where } } if self.settings.enabled.contains(&RuleCode::S506) { - if let Some(diagnostic) = flake8_bandit::checks::unsafe_yaml_load( + if let Some(diagnostic) = flake8_bandit::rules::unsafe_yaml_load( func, args, keywords, @@ -1982,10 +1973,10 @@ where } if self.settings.enabled.contains(&RuleCode::S106) { self.diagnostics - .extend(flake8_bandit::checks::hardcoded_password_func_arg(keywords)); + .extend(flake8_bandit::rules::hardcoded_password_func_arg(keywords)); } if self.settings.enabled.contains(&RuleCode::S324) { - if let Some(diagnostic) = flake8_bandit::checks::hashlib_insecure_hash_functions( + if let Some(diagnostic) = flake8_bandit::rules::hashlib_insecure_hash_functions( func, args, keywords, @@ -1996,7 +1987,7 @@ where } } if self.settings.enabled.contains(&RuleCode::S113) { - if let Some(diagnostic) = flake8_bandit::checks::request_without_timeout( + if let Some(diagnostic) = flake8_bandit::rules::request_without_timeout( func, args, keywords, @@ -2010,7 +2001,7 @@ where // flake8-comprehensions if self.settings.enabled.contains(&RuleCode::C400) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_generator_list( + flake8_comprehensions::rules::unnecessary_generator_list( expr, func, args, @@ -2025,7 +2016,7 @@ where } if self.settings.enabled.contains(&RuleCode::C401) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_generator_set( + flake8_comprehensions::rules::unnecessary_generator_set( expr, func, args, @@ -2040,7 +2031,7 @@ where } if self.settings.enabled.contains(&RuleCode::C402) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_generator_dict( + flake8_comprehensions::rules::unnecessary_generator_dict( expr, func, args, @@ -2055,7 +2046,7 @@ where } if self.settings.enabled.contains(&RuleCode::C403) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_list_comprehension_set( + flake8_comprehensions::rules::unnecessary_list_comprehension_set( expr, func, args, @@ -2070,7 +2061,7 @@ where } if self.settings.enabled.contains(&RuleCode::C404) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_list_comprehension_dict( + flake8_comprehensions::rules::unnecessary_list_comprehension_dict( expr, func, args, @@ -2084,7 +2075,7 @@ where }; } if self.settings.enabled.contains(&RuleCode::C405) { - if let Some(diagnostic) = flake8_comprehensions::checks::unnecessary_literal_set( + if let Some(diagnostic) = flake8_comprehensions::rules::unnecessary_literal_set( expr, func, args, @@ -2097,23 +2088,21 @@ where }; } if self.settings.enabled.contains(&RuleCode::C406) { - if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_literal_dict( - expr, - func, - args, - keywords, - self.locator, - self.patch(&RuleCode::C406), - Range::from_located(expr), - ) - { + if let Some(diagnostic) = flake8_comprehensions::rules::unnecessary_literal_dict( + expr, + func, + args, + keywords, + self.locator, + self.patch(&RuleCode::C406), + Range::from_located(expr), + ) { self.diagnostics.push(diagnostic); }; } if self.settings.enabled.contains(&RuleCode::C408) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_collection_call( + flake8_comprehensions::rules::unnecessary_collection_call( expr, func, args, @@ -2128,7 +2117,7 @@ where } if self.settings.enabled.contains(&RuleCode::C409) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_literal_within_tuple_call( + flake8_comprehensions::rules::unnecessary_literal_within_tuple_call( expr, func, args, @@ -2142,7 +2131,7 @@ where } if self.settings.enabled.contains(&RuleCode::C410) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_literal_within_list_call( + flake8_comprehensions::rules::unnecessary_literal_within_list_call( expr, func, args, @@ -2155,7 +2144,7 @@ where }; } if self.settings.enabled.contains(&RuleCode::C411) { - if let Some(diagnostic) = flake8_comprehensions::checks::unnecessary_list_call( + if let Some(diagnostic) = flake8_comprehensions::rules::unnecessary_list_call( expr, func, args, @@ -2168,7 +2157,7 @@ where } if self.settings.enabled.contains(&RuleCode::C413) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_call_around_sorted( + flake8_comprehensions::rules::unnecessary_call_around_sorted( expr, func, args, @@ -2182,7 +2171,7 @@ where } if self.settings.enabled.contains(&RuleCode::C414) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_double_cast_or_process( + flake8_comprehensions::rules::unnecessary_double_cast_or_process( func, args, Range::from_located(expr), @@ -2193,7 +2182,7 @@ where } if self.settings.enabled.contains(&RuleCode::C415) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_subscript_reversal( + flake8_comprehensions::rules::unnecessary_subscript_reversal( func, args, Range::from_located(expr), @@ -2203,7 +2192,7 @@ where }; } if self.settings.enabled.contains(&RuleCode::C417) { - if let Some(diagnostic) = flake8_comprehensions::checks::unnecessary_map( + if let Some(diagnostic) = flake8_comprehensions::rules::unnecessary_map( func, args, Range::from_located(expr), @@ -2214,7 +2203,7 @@ where // flake8-boolean-trap if self.settings.enabled.contains(&RuleCode::FBT003) { - flake8_boolean_trap::plugins::check_boolean_positional_value_in_function_call( + flake8_boolean_trap::rules::check_boolean_positional_value_in_function_call( self, args, func, ); } @@ -2228,7 +2217,7 @@ where // flake8-debugger if self.settings.enabled.contains(&RuleCode::T100) { - if let Some(diagnostic) = flake8_debugger::checks::debugger_call( + if let Some(diagnostic) = flake8_debugger::rules::debugger_call( expr, func, &self.from_imports, @@ -2241,7 +2230,7 @@ where // pandas-vet if self.settings.enabled.contains(&RuleCode::PD002) { self.diagnostics - .extend(pandas_vet::checks::inplace_argument(keywords).into_iter()); + .extend(pandas_vet::rules::inplace_argument(keywords).into_iter()); } for (code, name) in vec![ (RuleCode::PD003, "isnull"), @@ -2292,14 +2281,14 @@ where } } if self.settings.enabled.contains(&RuleCode::PD015) { - if let Some(diagnostic) = pandas_vet::checks::use_of_pd_merge(func) { + if let Some(diagnostic) = pandas_vet::rules::use_of_pd_merge(func) { self.diagnostics.push(diagnostic); }; } // flake8-datetimez if self.settings.enabled.contains(&RuleCode::DTZ001) { - flake8_datetimez::plugins::call_datetime_without_tzinfo( + flake8_datetimez::rules::call_datetime_without_tzinfo( self, func, args, @@ -2308,28 +2297,28 @@ where ); } if self.settings.enabled.contains(&RuleCode::DTZ002) { - flake8_datetimez::plugins::call_datetime_today( + flake8_datetimez::rules::call_datetime_today( self, func, Range::from_located(expr), ); } if self.settings.enabled.contains(&RuleCode::DTZ003) { - flake8_datetimez::plugins::call_datetime_utcnow( + flake8_datetimez::rules::call_datetime_utcnow( self, func, Range::from_located(expr), ); } if self.settings.enabled.contains(&RuleCode::DTZ004) { - flake8_datetimez::plugins::call_datetime_utcfromtimestamp( + flake8_datetimez::rules::call_datetime_utcfromtimestamp( self, func, Range::from_located(expr), ); } if self.settings.enabled.contains(&RuleCode::DTZ005) { - flake8_datetimez::plugins::call_datetime_now_without_tzinfo( + flake8_datetimez::rules::call_datetime_now_without_tzinfo( self, func, args, @@ -2338,7 +2327,7 @@ where ); } if self.settings.enabled.contains(&RuleCode::DTZ006) { - flake8_datetimez::plugins::call_datetime_fromtimestamp( + flake8_datetimez::rules::call_datetime_fromtimestamp( self, func, args, @@ -2347,7 +2336,7 @@ where ); } if self.settings.enabled.contains(&RuleCode::DTZ007) { - flake8_datetimez::plugins::call_datetime_strptime_without_zone( + flake8_datetimez::rules::call_datetime_strptime_without_zone( self, func, args, @@ -2355,14 +2344,10 @@ where ); } if self.settings.enabled.contains(&RuleCode::DTZ011) { - flake8_datetimez::plugins::call_date_today( - self, - func, - Range::from_located(expr), - ); + flake8_datetimez::rules::call_date_today(self, func, Range::from_located(expr)); } if self.settings.enabled.contains(&RuleCode::DTZ012) { - flake8_datetimez::plugins::call_date_fromtimestamp( + flake8_datetimez::rules::call_date_fromtimestamp( self, func, Range::from_located(expr), @@ -2371,30 +2356,30 @@ where // pygrep-hooks if self.settings.enabled.contains(&RuleCode::PGH001) { - pygrep_hooks::plugins::no_eval(self, func); + pygrep_hooks::rules::no_eval(self, func); } if self.settings.enabled.contains(&RuleCode::PGH002) { - pygrep_hooks::plugins::deprecated_log_warn(self, func); + pygrep_hooks::rules::deprecated_log_warn(self, func); } // pylint if self.settings.enabled.contains(&RuleCode::PLC3002) { - pylint::plugins::unnecessary_direct_lambda_call(self, expr, func); + pylint::rules::unnecessary_direct_lambda_call(self, expr, func); } if self.settings.enabled.contains(&RuleCode::PLR1722) { - pylint::plugins::use_sys_exit(self, func); + pylint::rules::use_sys_exit(self, func); } // flake8-pytest-style if self.settings.enabled.contains(&RuleCode::PT008) { if let Some(diagnostic) = - flake8_pytest_style::plugins::patch_with_lambda(func, args, keywords) + flake8_pytest_style::rules::patch_with_lambda(func, args, keywords) { self.diagnostics.push(diagnostic); } } if self.settings.enabled.contains(&RuleCode::PT009) { - if let Some(diagnostic) = flake8_pytest_style::plugins::unittest_assertion( + if let Some(diagnostic) = flake8_pytest_style::rules::unittest_assertion( self, expr, func, args, keywords, ) { self.diagnostics.push(diagnostic); @@ -2404,17 +2389,17 @@ where if self.settings.enabled.contains(&RuleCode::PT010) || self.settings.enabled.contains(&RuleCode::PT011) { - flake8_pytest_style::plugins::raises_call(self, func, args, keywords); + flake8_pytest_style::rules::raises_call(self, func, args, keywords); } if self.settings.enabled.contains(&RuleCode::PT016) { - flake8_pytest_style::plugins::fail_call(self, func, args, keywords); + flake8_pytest_style::rules::fail_call(self, func, args, keywords); } // ruff if self.settings.enabled.contains(&RuleCode::RUF004) { self.diagnostics - .extend(ruff::checks::keyword_argument_before_star_argument( + .extend(ruff::rules::keyword_argument_before_star_argument( args, keywords, )); } @@ -2423,7 +2408,7 @@ where if self.settings.enabled.contains(&RuleCode::F601) || self.settings.enabled.contains(&RuleCode::F602) { - pyflakes::plugins::repeated_keys(self, keys, values); + pyflakes::rules::repeated_keys(self, keys, values); } } ExprKind::Yield { .. } => { @@ -2459,12 +2444,12 @@ where } } if self.settings.enabled.contains(&RuleCode::PLE1142) { - pylint::plugins::await_outside_async(self, expr); + pylint::rules::await_outside_async(self, expr); } } ExprKind::JoinedStr { values } => { if self.settings.enabled.contains(&RuleCode::F541) { - pyflakes::plugins::f_string_missing_placeholders(expr, values, self); + pyflakes::rules::f_string_missing_placeholders(expr, values, self); } } ExprKind::BinOp { @@ -2473,7 +2458,7 @@ where .. } => { if self.settings.enabled.contains(&RuleCode::F633) { - pyflakes::plugins::invalid_print_syntax(self, left); + pyflakes::rules::invalid_print_syntax(self, left); } } ExprKind::BinOp { @@ -2519,37 +2504,37 @@ where } Ok(summary) => { if self.settings.enabled.contains(&RuleCode::F502) { - pyflakes::plugins::percent_format_expected_mapping( + pyflakes::rules::percent_format_expected_mapping( self, &summary, right, location, ); } if self.settings.enabled.contains(&RuleCode::F503) { - pyflakes::plugins::percent_format_expected_sequence( + pyflakes::rules::percent_format_expected_sequence( self, &summary, right, location, ); } if self.settings.enabled.contains(&RuleCode::F504) { - pyflakes::plugins::percent_format_extra_named_arguments( + pyflakes::rules::percent_format_extra_named_arguments( self, &summary, right, location, ); } if self.settings.enabled.contains(&RuleCode::F505) { - pyflakes::plugins::percent_format_missing_arguments( + pyflakes::rules::percent_format_missing_arguments( self, &summary, right, location, ); } if self.settings.enabled.contains(&RuleCode::F506) { - pyflakes::plugins::percent_format_mixed_positional_and_named( + pyflakes::rules::percent_format_mixed_positional_and_named( self, &summary, location, ); } if self.settings.enabled.contains(&RuleCode::F507) { - pyflakes::plugins::percent_format_positional_count_mismatch( + pyflakes::rules::percent_format_positional_count_mismatch( self, &summary, right, location, ); } if self.settings.enabled.contains(&RuleCode::F508) { - pyflakes::plugins::percent_format_star_requires_sequence( + pyflakes::rules::percent_format_star_requires_sequence( self, &summary, right, location, ); } @@ -2562,7 +2547,7 @@ where op: Operator::Add, .. } => { if self.settings.enabled.contains(&RuleCode::ISC003) { - if let Some(diagnostic) = flake8_implicit_str_concat::checks::explicit(expr) { + if let Some(diagnostic) = flake8_implicit_str_concat::rules::explicit(expr) { self.diagnostics.push(diagnostic); } } @@ -2571,7 +2556,7 @@ where let check_not_in = self.settings.enabled.contains(&RuleCode::E713); let check_not_is = self.settings.enabled.contains(&RuleCode::E714); if check_not_in || check_not_is { - pycodestyle::plugins::not_tests( + pycodestyle::rules::not_tests( self, expr, op, @@ -2582,17 +2567,17 @@ where } if self.settings.enabled.contains(&RuleCode::B002) { - flake8_bugbear::plugins::unary_prefix_increment(self, expr, op, operand); + flake8_bugbear::rules::unary_prefix_increment(self, expr, op, operand); } if self.settings.enabled.contains(&RuleCode::SIM201) { - flake8_simplify::plugins::negation_with_equal_op(self, expr, op, operand); + flake8_simplify::rules::negation_with_equal_op(self, expr, op, operand); } if self.settings.enabled.contains(&RuleCode::SIM202) { - flake8_simplify::plugins::negation_with_not_equal_op(self, expr, op, operand); + flake8_simplify::rules::negation_with_not_equal_op(self, expr, op, operand); } if self.settings.enabled.contains(&RuleCode::SIM208) { - flake8_simplify::plugins::double_negation(self, expr, op, operand); + flake8_simplify::rules::double_negation(self, expr, op, operand); } } ExprKind::Compare { @@ -2603,7 +2588,7 @@ where let check_none_comparisons = self.settings.enabled.contains(&RuleCode::E711); let check_true_false_comparisons = self.settings.enabled.contains(&RuleCode::E712); if check_none_comparisons || check_true_false_comparisons { - pycodestyle::plugins::literal_comparisons( + pycodestyle::rules::literal_comparisons( self, expr, left, @@ -2615,7 +2600,7 @@ where } if self.settings.enabled.contains(&RuleCode::F632) { - pyflakes::plugins::invalid_literal_comparison( + pyflakes::rules::invalid_literal_comparison( self, left, ops, @@ -2625,12 +2610,11 @@ where } if self.settings.enabled.contains(&RuleCode::E721) { - self.diagnostics - .extend(pycodestyle::checks::type_comparison( - ops, - comparators, - Range::from_located(expr), - )); + self.diagnostics.extend(pycodestyle::rules::type_comparison( + ops, + comparators, + Range::from_located(expr), + )); } if self.settings.enabled.contains(&RuleCode::YTT103) @@ -2639,12 +2623,12 @@ where || self.settings.enabled.contains(&RuleCode::YTT204) || self.settings.enabled.contains(&RuleCode::YTT302) { - flake8_2020::plugins::compare(self, left, ops, comparators); + flake8_2020::rules::compare(self, left, ops, comparators); } if self.settings.enabled.contains(&RuleCode::S105) { self.diagnostics.extend( - flake8_bandit::checks::compare_to_hardcoded_password_string( + flake8_bandit::rules::compare_to_hardcoded_password_string( left, comparators, ), @@ -2652,7 +2636,7 @@ where } if self.settings.enabled.contains(&RuleCode::PLC2201) { - pylint::plugins::misplaced_comparison_constant( + pylint::rules::misplaced_comparison_constant( self, expr, left, @@ -2662,17 +2646,11 @@ where } if self.settings.enabled.contains(&RuleCode::SIM118) { - flake8_simplify::plugins::key_in_dict_compare( - self, - expr, - left, - ops, - comparators, - ); + flake8_simplify::rules::key_in_dict_compare(self, expr, left, ops, comparators); } if self.settings.enabled.contains(&RuleCode::SIM300) { - flake8_simplify::plugins::yoda_conditions(self, expr, left, ops, comparators); + flake8_simplify::rules::yoda_conditions(self, expr, left, ops, comparators); } } ExprKind::Constant { @@ -2688,7 +2666,7 @@ where )); } if self.settings.enabled.contains(&RuleCode::S104) { - if let Some(diagnostic) = flake8_bandit::checks::hardcoded_bind_all_interfaces( + if let Some(diagnostic) = flake8_bandit::rules::hardcoded_bind_all_interfaces( value, &Range::from_located(expr), ) { @@ -2696,7 +2674,7 @@ where } } if self.settings.enabled.contains(&RuleCode::S108) { - if let Some(diagnostic) = flake8_bandit::checks::hardcoded_tmp_directory( + if let Some(diagnostic) = flake8_bandit::rules::hardcoded_tmp_directory( expr, value, &self.settings.flake8_bandit.hardcoded_tmp_directory, @@ -2705,12 +2683,12 @@ where } } if self.settings.enabled.contains(&RuleCode::UP025) { - pyupgrade::plugins::rewrite_unicode_literal(self, expr, kind.as_deref()); + pyupgrade::rules::rewrite_unicode_literal(self, expr, kind.as_deref()); } } ExprKind::Lambda { args, body, .. } => { if self.settings.enabled.contains(&RuleCode::PIE807) { - flake8_pie::plugins::prefer_list_builtin(self, expr); + flake8_pie::rules::prefer_list_builtin(self, expr); } // Visit the arguments, but avoid the body, which will be deferred. @@ -2749,25 +2727,23 @@ where } ExprKind::IfExp { test, body, orelse } => { if self.settings.enabled.contains(&RuleCode::SIM210) { - flake8_simplify::plugins::explicit_true_false_in_ifexpr( + flake8_simplify::rules::explicit_true_false_in_ifexpr( self, expr, test, body, orelse, ); } if self.settings.enabled.contains(&RuleCode::SIM211) { - flake8_simplify::plugins::explicit_false_true_in_ifexpr( + flake8_simplify::rules::explicit_false_true_in_ifexpr( self, expr, test, body, orelse, ); } if self.settings.enabled.contains(&RuleCode::SIM212) { - flake8_simplify::plugins::twisted_arms_in_ifexpr( - self, expr, test, body, orelse, - ); + flake8_simplify::rules::twisted_arms_in_ifexpr(self, expr, test, body, orelse); } } ExprKind::ListComp { elt, generators } | ExprKind::SetComp { elt, generators } => { if self.settings.enabled.contains(&RuleCode::C416) { if let Some(diagnostic) = - flake8_comprehensions::checks::unnecessary_comprehension( + flake8_comprehensions::rules::unnecessary_comprehension( expr, elt, generators, @@ -2780,37 +2756,37 @@ where }; } if self.settings.enabled.contains(&RuleCode::B023) { - flake8_bugbear::plugins::function_uses_loop_variable(self, &Node::Expr(expr)); + flake8_bugbear::rules::function_uses_loop_variable(self, &Node::Expr(expr)); } self.push_scope(Scope::new(ScopeKind::Generator)); } ExprKind::GeneratorExp { .. } | ExprKind::DictComp { .. } => { if self.settings.enabled.contains(&RuleCode::B023) { - flake8_bugbear::plugins::function_uses_loop_variable(self, &Node::Expr(expr)); + flake8_bugbear::rules::function_uses_loop_variable(self, &Node::Expr(expr)); } self.push_scope(Scope::new(ScopeKind::Generator)); } ExprKind::BoolOp { op, values } => { if self.settings.enabled.contains(&RuleCode::PLR1701) { - pylint::plugins::merge_isinstance(self, expr, op, values); + pylint::rules::merge_isinstance(self, expr, op, values); } if self.settings.enabled.contains(&RuleCode::SIM101) { - flake8_simplify::plugins::duplicate_isinstance_call(self, expr); + flake8_simplify::rules::duplicate_isinstance_call(self, expr); } if self.settings.enabled.contains(&RuleCode::SIM109) { - flake8_simplify::plugins::compare_with_tuple(self, expr); + flake8_simplify::rules::compare_with_tuple(self, expr); } if self.settings.enabled.contains(&RuleCode::SIM220) { - flake8_simplify::plugins::a_and_not_a(self, expr); + flake8_simplify::rules::a_and_not_a(self, expr); } if self.settings.enabled.contains(&RuleCode::SIM221) { - flake8_simplify::plugins::a_or_not_a(self, expr); + flake8_simplify::rules::a_or_not_a(self, expr); } if self.settings.enabled.contains(&RuleCode::SIM222) { - flake8_simplify::plugins::or_true(self, expr); + flake8_simplify::rules::or_true(self, expr); } if self.settings.enabled.contains(&RuleCode::SIM223) { - flake8_simplify::plugins::and_false(self, expr); + flake8_simplify::rules::and_false(self, expr); } } _ => {} @@ -3049,7 +3025,7 @@ where type_, name, body, .. } => { if self.settings.enabled.contains(&RuleCode::E722) { - if let Some(diagnostic) = pycodestyle::checks::do_not_use_bare_except( + if let Some(diagnostic) = pycodestyle::rules::do_not_use_bare_except( type_.as_deref(), body, excepthandler, @@ -3059,10 +3035,10 @@ where } } if self.settings.enabled.contains(&RuleCode::B904) { - flake8_bugbear::plugins::raise_without_from_inside_except(self, body); + flake8_bugbear::rules::raise_without_from_inside_except(self, body); } if self.settings.enabled.contains(&RuleCode::BLE001) { - flake8_blind_except::plugins::blind_except( + flake8_blind_except::rules::blind_except( self, type_.as_deref(), name.as_deref(), @@ -3072,7 +3048,7 @@ where match name { Some(name) => { if self.settings.enabled.contains(&RuleCode::E741) { - if let Some(diagnostic) = pycodestyle::checks::ambiguous_variable_name( + if let Some(diagnostic) = pycodestyle::rules::ambiguous_variable_name( name, helpers::excepthandler_name_range(excepthandler, self.locator) .expect("Failed to find `name` range"), @@ -3173,7 +3149,7 @@ where fn visit_comprehension(&mut self, comprehension: &'b Comprehension) { if self.settings.enabled.contains(&RuleCode::SIM118) { - flake8_simplify::plugins::key_in_dict_for( + flake8_simplify::rules::key_in_dict_for( self, &comprehension.target, &comprehension.iter, @@ -3184,18 +3160,18 @@ where fn visit_arguments(&mut self, arguments: &'b Arguments) { if self.settings.enabled.contains(&RuleCode::B006) { - flake8_bugbear::plugins::mutable_argument_default(self, arguments); + flake8_bugbear::rules::mutable_argument_default(self, arguments); } if self.settings.enabled.contains(&RuleCode::B008) { - flake8_bugbear::plugins::function_call_argument_default(self, arguments); + flake8_bugbear::rules::function_call_argument_default(self, arguments); } // flake8-boolean-trap if self.settings.enabled.contains(&RuleCode::FBT001) { - flake8_boolean_trap::plugins::check_positional_boolean_in_def(self, arguments); + flake8_boolean_trap::rules::check_positional_boolean_in_def(self, arguments); } if self.settings.enabled.contains(&RuleCode::FBT002) { - flake8_boolean_trap::plugins::check_boolean_default_value_in_function_definition( + flake8_boolean_trap::rules::check_boolean_default_value_in_function_definition( self, arguments, ); } @@ -3233,16 +3209,15 @@ where ); if self.settings.enabled.contains(&RuleCode::E741) { - if let Some(diagnostic) = pycodestyle::checks::ambiguous_variable_name( - &arg.node.arg, - Range::from_located(arg), - ) { + if let Some(diagnostic) = + pycodestyle::rules::ambiguous_variable_name(&arg.node.arg, Range::from_located(arg)) + { self.diagnostics.push(diagnostic); } } if self.settings.enabled.contains(&RuleCode::N803) { - if let Some(diagnostic) = pep8_naming::checks::invalid_argument_name(&arg.node.arg, arg) + if let Some(diagnostic) = pep8_naming::rules::invalid_argument_name(&arg.node.arg, arg) { self.diagnostics.push(diagnostic); } @@ -3253,7 +3228,7 @@ where fn visit_body(&mut self, body: &'b [Stmt]) { if self.settings.enabled.contains(&RuleCode::PIE790) { - flake8_pie::plugins::no_unnecessary_pass(self, body); + flake8_pie::rules::no_unnecessary_pass(self, body); } if self.settings.enabled.contains(&RuleCode::SIM110) @@ -3263,7 +3238,7 @@ where if matches!(stmt.node, StmtKind::For { .. }) && matches!(sibling.node, StmtKind::Return { .. }) { - flake8_simplify::plugins::convert_loop_to_any_all(self, stmt, sibling); + flake8_simplify::rules::convert_loop_to_any_all(self, stmt, sibling); } } } @@ -3606,7 +3581,7 @@ impl<'a> Checker<'a> { .iter() .map(|index| &self.scopes[*index]) .collect(); - if let Some(diagnostic) = pyflakes::checks::undefined_local(id, &scopes, &self.bindings) + if let Some(diagnostic) = pyflakes::rules::undefined_local(id, &scopes, &self.bindings) { self.diagnostics.push(diagnostic); } @@ -3618,22 +3593,20 @@ impl<'a> Checker<'a> { if !self.current_scope().values.get(id).map_or(false, |index| { matches!(self.bindings[*index].kind, BindingKind::Global) }) { - pep8_naming::plugins::non_lowercase_variable_in_function( - self, expr, parent, id, - ); + pep8_naming::rules::non_lowercase_variable_in_function(self, expr, parent, id); } } } if self.settings.enabled.contains(&RuleCode::N815) { if matches!(self.current_scope().kind, ScopeKind::Class(..)) { - pep8_naming::plugins::mixed_case_variable_in_class_scope(self, expr, parent, id); + pep8_naming::rules::mixed_case_variable_in_class_scope(self, expr, parent, id); } } if self.settings.enabled.contains(&RuleCode::N816) { if matches!(self.current_scope().kind, ScopeKind::Module) { - pep8_naming::plugins::mixed_case_variable_in_global_scope(self, expr, parent, id); + pep8_naming::rules::mixed_case_variable_in_global_scope(self, expr, parent, id); } } @@ -3771,7 +3744,7 @@ impl<'a> Checker<'a> { 'b: 'a, { if self.settings.enabled.contains(&RuleCode::B021) { - flake8_bugbear::plugins::f_string_docstring(self, python_ast); + flake8_bugbear::rules::f_string_docstring(self, python_ast); } let docstring = docstrings::extraction::docstring_from(python_ast); self.definitions.push(( @@ -3881,10 +3854,10 @@ impl<'a> Checker<'a> { let scope_index = scopes[scopes.len() - 1]; let parent_scope_index = scopes[scopes.len() - 2]; if self.settings.enabled.contains(&RuleCode::F841) { - pyflakes::plugins::unused_variable(self, scope_index); + pyflakes::rules::unused_variable(self, scope_index); } if self.settings.enabled.contains(&RuleCode::F842) { - pyflakes::plugins::unused_annotation(self, scope_index); + pyflakes::rules::unused_annotation(self, scope_index); } if self.settings.enabled.contains(&RuleCode::ARG001) || self.settings.enabled.contains(&RuleCode::ARG002) @@ -3893,7 +3866,7 @@ impl<'a> Checker<'a> { || self.settings.enabled.contains(&RuleCode::ARG005) { self.diagnostics - .extend(flake8_unused_arguments::plugins::unused_arguments( + .extend(flake8_unused_arguments::rules::unused_arguments( self, &self.scopes[parent_scope_index], &self.scopes[scope_index], @@ -4252,7 +4225,7 @@ impl<'a> Checker<'a> { &overloaded_name, ) }) { - flake8_annotations::plugins::definition(self, &definition, &visibility); + flake8_annotations::rules::definition(self, &definition, &visibility); } overloaded_name = flake8_annotations::helpers::overloaded_name(self, &definition); } @@ -4260,7 +4233,7 @@ impl<'a> Checker<'a> { // pydocstyle if enforce_docstrings { if definition.docstring.is_none() { - pydocstyle::plugins::not_missing(self, &definition, &visibility); + pydocstyle::rules::not_missing(self, &definition, &visibility); continue; } @@ -4282,67 +4255,67 @@ impl<'a> Checker<'a> { body, }; - if !pydocstyle::plugins::not_empty(self, &docstring) { + if !pydocstyle::rules::not_empty(self, &docstring) { continue; } if self.settings.enabled.contains(&RuleCode::D200) { - pydocstyle::plugins::one_liner(self, &docstring); + pydocstyle::rules::one_liner(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D201) || self.settings.enabled.contains(&RuleCode::D202) { - pydocstyle::plugins::blank_before_after_function(self, &docstring); + pydocstyle::rules::blank_before_after_function(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D203) || self.settings.enabled.contains(&RuleCode::D204) || self.settings.enabled.contains(&RuleCode::D211) { - pydocstyle::plugins::blank_before_after_class(self, &docstring); + pydocstyle::rules::blank_before_after_class(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D205) { - pydocstyle::plugins::blank_after_summary(self, &docstring); + pydocstyle::rules::blank_after_summary(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D206) || self.settings.enabled.contains(&RuleCode::D207) || self.settings.enabled.contains(&RuleCode::D208) { - pydocstyle::plugins::indent(self, &docstring); + pydocstyle::rules::indent(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D209) { - pydocstyle::plugins::newline_after_last_paragraph(self, &docstring); + pydocstyle::rules::newline_after_last_paragraph(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D210) { - pydocstyle::plugins::no_surrounding_whitespace(self, &docstring); + pydocstyle::rules::no_surrounding_whitespace(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D212) || self.settings.enabled.contains(&RuleCode::D213) { - pydocstyle::plugins::multi_line_summary_start(self, &docstring); + pydocstyle::rules::multi_line_summary_start(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D300) { - pydocstyle::plugins::triple_quotes(self, &docstring); + pydocstyle::rules::triple_quotes(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D301) { - pydocstyle::plugins::backslashes(self, &docstring); + pydocstyle::rules::backslashes(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D400) { - pydocstyle::plugins::ends_with_period(self, &docstring); + pydocstyle::rules::ends_with_period(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D402) { - pydocstyle::plugins::no_signature(self, &docstring); + pydocstyle::rules::no_signature(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D403) { - pydocstyle::plugins::capitalized(self, &docstring); + pydocstyle::rules::capitalized(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D404) { - pydocstyle::plugins::starts_with_this(self, &docstring); + pydocstyle::rules::starts_with_this(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D415) { - pydocstyle::plugins::ends_with_punctuation(self, &docstring); + pydocstyle::rules::ends_with_punctuation(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D418) { - pydocstyle::plugins::if_needed(self, &docstring); + pydocstyle::rules::if_needed(self, &docstring); } if self.settings.enabled.contains(&RuleCode::D212) || self.settings.enabled.contains(&RuleCode::D214) @@ -4360,7 +4333,7 @@ impl<'a> Checker<'a> { || self.settings.enabled.contains(&RuleCode::D416) || self.settings.enabled.contains(&RuleCode::D417) { - pydocstyle::plugins::sections( + pydocstyle::rules::sections( self, &docstring, self.settings.pydocstyle.convention.as_ref(), @@ -4373,7 +4346,7 @@ impl<'a> Checker<'a> { fn check_builtin_shadowing(&mut self, name: &str, located: &Located, is_attribute: bool) { if is_attribute && matches!(self.current_scope().kind, ScopeKind::Class(_)) { if self.settings.enabled.contains(&RuleCode::A003) { - if let Some(diagnostic) = flake8_builtins::checks::builtin_shadowing( + if let Some(diagnostic) = flake8_builtins::rules::builtin_shadowing( name, located, flake8_builtins::types::ShadowingType::Attribute, @@ -4383,7 +4356,7 @@ impl<'a> Checker<'a> { } } else { if self.settings.enabled.contains(&RuleCode::A001) { - if let Some(diagnostic) = flake8_builtins::checks::builtin_shadowing( + if let Some(diagnostic) = flake8_builtins::rules::builtin_shadowing( name, located, flake8_builtins::types::ShadowingType::Variable, @@ -4396,7 +4369,7 @@ impl<'a> Checker<'a> { fn check_builtin_arg_shadowing(&mut self, name: &str, arg: &Arg) { if self.settings.enabled.contains(&RuleCode::A002) { - if let Some(diagnostic) = flake8_builtins::checks::builtin_shadowing( + if let Some(diagnostic) = flake8_builtins::rules::builtin_shadowing( name, arg, flake8_builtins::types::ShadowingType::Argument, diff --git a/src/checkers/imports.rs b/src/checkers/imports.rs index 2472a7ae07..43fc3e55f9 100644 --- a/src/checkers/imports.rs +++ b/src/checkers/imports.rs @@ -25,7 +25,7 @@ fn check_import_blocks( for block in tracker.into_iter() { if !block.imports.is_empty() { if let Some(diagnostic) = - isort::plugins::check_imports(&block, locator, settings, stylist, autofix, package) + isort::rules::check_imports(&block, locator, settings, stylist, autofix, package) { diagnostics.push(diagnostic); } diff --git a/src/checkers/lines.rs b/src/checkers/lines.rs index 3b5a5b9b6a..4895cbec87 100644 --- a/src/checkers/lines.rs +++ b/src/checkers/lines.rs @@ -1,8 +1,8 @@ //! Lint rules based on checking raw physical lines. -use crate::pycodestyle::checks::{line_too_long, no_newline_at_end_of_file}; -use crate::pygrep_hooks::plugins::{blanket_noqa, blanket_type_ignore}; -use crate::pyupgrade::checks::unnecessary_coding_comment; +use crate::pycodestyle::rules::{line_too_long, no_newline_at_end_of_file}; +use crate::pygrep_hooks::rules::{blanket_noqa, blanket_type_ignore}; +use crate::pyupgrade::rules::unnecessary_coding_comment; use crate::registry::{Diagnostic, RuleCode}; use crate::settings::{flags, Settings}; diff --git a/src/checkers/tokens.rs b/src/checkers/tokens.rs index 955c345f78..94b85c87f5 100644 --- a/src/checkers/tokens.rs +++ b/src/checkers/tokens.rs @@ -4,7 +4,7 @@ use rustpython_parser::lexer::{LexResult, Tok}; use crate::lex::docstring_detection::StateMachine; use crate::registry::{Diagnostic, RuleCode}; -use crate::ruff::checks::Context; +use crate::ruff::rules::Context; use crate::settings::flags; use crate::source_code_locator::SourceCodeLocator; use crate::{eradicate, flake8_implicit_str_concat, flake8_quotes, pycodestyle, ruff, Settings}; @@ -40,7 +40,7 @@ pub fn check_tokens( // RUF001, RUF002, RUF003 if enforce_ambiguous_unicode_character { if matches!(tok, Tok::String { .. } | Tok::Comment(_)) { - diagnostics.extend(ruff::checks::ambiguous_unicode_character( + diagnostics.extend(ruff::rules::ambiguous_unicode_character( locator, start, end, @@ -62,7 +62,7 @@ pub fn check_tokens( // flake8-quotes if enforce_quotes { if matches!(tok, Tok::String { .. }) { - if let Some(diagnostic) = flake8_quotes::checks::quotes( + if let Some(diagnostic) = flake8_quotes::rules::quotes( locator, start, end, @@ -80,7 +80,7 @@ pub fn check_tokens( if enforce_commented_out_code { if matches!(tok, Tok::Comment(_)) { if let Some(diagnostic) = - eradicate::checks::commented_out_code(locator, start, end, settings, autofix) + eradicate::rules::commented_out_code(locator, start, end, settings, autofix) { diagnostics.push(diagnostic); } @@ -90,7 +90,7 @@ pub fn check_tokens( // W605 if enforce_invalid_escape_sequence { if matches!(tok, Tok::String { .. }) { - diagnostics.extend(pycodestyle::checks::invalid_escape_sequence( + diagnostics.extend(pycodestyle::rules::invalid_escape_sequence( locator, start, end, @@ -104,7 +104,7 @@ pub fn check_tokens( // ISC001, ISC002 if enforce_implicit_string_concatenation { diagnostics.extend( - flake8_implicit_str_concat::checks::implicit(tokens, locator) + flake8_implicit_str_concat::rules::implicit(tokens, locator) .into_iter() .filter(|diagnostic| settings.enabled.contains(diagnostic.kind.code())), ); diff --git a/src/eradicate/mod.rs b/src/eradicate/mod.rs index 06876e1155..e611107fb5 100644 --- a/src/eradicate/mod.rs +++ b/src/eradicate/mod.rs @@ -1,5 +1,5 @@ -pub mod checks; pub mod detection; +pub mod rules; #[cfg(test)] mod tests { @@ -14,7 +14,7 @@ mod tests { use crate::settings; #[test_case(RuleCode::ERA001, Path::new("ERA001.py"); "ERA001")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/eradicate") diff --git a/src/eradicate/checks.rs b/src/eradicate/rules.rs similarity index 100% rename from src/eradicate/checks.rs rename to src/eradicate/rules.rs diff --git a/src/flake8_2020/mod.rs b/src/flake8_2020/mod.rs index ca5150b89d..abc8807f60 100644 --- a/src/flake8_2020/mod.rs +++ b/src/flake8_2020/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; #[cfg(test)] mod tests { @@ -22,7 +22,7 @@ mod tests { #[test_case(RuleCode::YTT301, Path::new("YTT301.py"); "YTT301")] #[test_case(RuleCode::YTT302, Path::new("YTT302.py"); "YTT302")] #[test_case(RuleCode::YTT303, Path::new("YTT303.py"); "YTT303")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_2020") diff --git a/src/flake8_2020/plugins.rs b/src/flake8_2020/rules.rs similarity index 100% rename from src/flake8_2020/plugins.rs rename to src/flake8_2020/rules.rs diff --git a/src/flake8_annotations/mod.rs b/src/flake8_annotations/mod.rs index 5def0c15e9..d8278251cc 100644 --- a/src/flake8_annotations/mod.rs +++ b/src/flake8_annotations/mod.rs @@ -1,6 +1,6 @@ mod fixes; pub mod helpers; -pub mod plugins; +pub mod rules; pub mod settings; #[cfg(test)] diff --git a/src/flake8_annotations/plugins.rs b/src/flake8_annotations/rules.rs similarity index 100% rename from src/flake8_annotations/plugins.rs rename to src/flake8_annotations/rules.rs diff --git a/src/flake8_bandit/mod.rs b/src/flake8_bandit/mod.rs index 300808335b..923c98d951 100644 --- a/src/flake8_bandit/mod.rs +++ b/src/flake8_bandit/mod.rs @@ -1,5 +1,5 @@ -pub mod checks; mod helpers; +pub mod rules; pub mod settings; #[cfg(test)] @@ -25,7 +25,7 @@ mod tests { #[test_case(RuleCode::S324, Path::new("S324.py"); "S324")] #[test_case(RuleCode::S501, Path::new("S501.py"); "S501")] #[test_case(RuleCode::S506, Path::new("S506.py"); "S506")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_bandit") diff --git a/src/flake8_bandit/checks/assert_used.rs b/src/flake8_bandit/rules/assert_used.rs similarity index 100% rename from src/flake8_bandit/checks/assert_used.rs rename to src/flake8_bandit/rules/assert_used.rs diff --git a/src/flake8_bandit/checks/bad_file_permissions.rs b/src/flake8_bandit/rules/bad_file_permissions.rs similarity index 100% rename from src/flake8_bandit/checks/bad_file_permissions.rs rename to src/flake8_bandit/rules/bad_file_permissions.rs diff --git a/src/flake8_bandit/checks/exec_used.rs b/src/flake8_bandit/rules/exec_used.rs similarity index 100% rename from src/flake8_bandit/checks/exec_used.rs rename to src/flake8_bandit/rules/exec_used.rs diff --git a/src/flake8_bandit/checks/hardcoded_bind_all_interfaces.rs b/src/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs similarity index 100% rename from src/flake8_bandit/checks/hardcoded_bind_all_interfaces.rs rename to src/flake8_bandit/rules/hardcoded_bind_all_interfaces.rs diff --git a/src/flake8_bandit/checks/hardcoded_password_default.rs b/src/flake8_bandit/rules/hardcoded_password_default.rs similarity index 100% rename from src/flake8_bandit/checks/hardcoded_password_default.rs rename to src/flake8_bandit/rules/hardcoded_password_default.rs diff --git a/src/flake8_bandit/checks/hardcoded_password_func_arg.rs b/src/flake8_bandit/rules/hardcoded_password_func_arg.rs similarity index 100% rename from src/flake8_bandit/checks/hardcoded_password_func_arg.rs rename to src/flake8_bandit/rules/hardcoded_password_func_arg.rs diff --git a/src/flake8_bandit/checks/hardcoded_password_string.rs b/src/flake8_bandit/rules/hardcoded_password_string.rs similarity index 100% rename from src/flake8_bandit/checks/hardcoded_password_string.rs rename to src/flake8_bandit/rules/hardcoded_password_string.rs diff --git a/src/flake8_bandit/checks/hardcoded_tmp_directory.rs b/src/flake8_bandit/rules/hardcoded_tmp_directory.rs similarity index 100% rename from src/flake8_bandit/checks/hardcoded_tmp_directory.rs rename to src/flake8_bandit/rules/hardcoded_tmp_directory.rs diff --git a/src/flake8_bandit/checks/hashlib_insecure_hash_functions.rs b/src/flake8_bandit/rules/hashlib_insecure_hash_functions.rs similarity index 100% rename from src/flake8_bandit/checks/hashlib_insecure_hash_functions.rs rename to src/flake8_bandit/rules/hashlib_insecure_hash_functions.rs diff --git a/src/flake8_bandit/checks/mod.rs b/src/flake8_bandit/rules/mod.rs similarity index 100% rename from src/flake8_bandit/checks/mod.rs rename to src/flake8_bandit/rules/mod.rs diff --git a/src/flake8_bandit/checks/request_with_no_cert_validation.rs b/src/flake8_bandit/rules/request_with_no_cert_validation.rs similarity index 100% rename from src/flake8_bandit/checks/request_with_no_cert_validation.rs rename to src/flake8_bandit/rules/request_with_no_cert_validation.rs diff --git a/src/flake8_bandit/checks/request_without_timeout.rs b/src/flake8_bandit/rules/request_without_timeout.rs similarity index 100% rename from src/flake8_bandit/checks/request_without_timeout.rs rename to src/flake8_bandit/rules/request_without_timeout.rs diff --git a/src/flake8_bandit/checks/unsafe_yaml_load.rs b/src/flake8_bandit/rules/unsafe_yaml_load.rs similarity index 100% rename from src/flake8_bandit/checks/unsafe_yaml_load.rs rename to src/flake8_bandit/rules/unsafe_yaml_load.rs diff --git a/src/flake8_blind_except/mod.rs b/src/flake8_blind_except/mod.rs index bda46d405b..1ef8d92f39 100644 --- a/src/flake8_blind_except/mod.rs +++ b/src/flake8_blind_except/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; #[cfg(test)] mod tests { @@ -13,7 +13,7 @@ mod tests { use crate::settings; #[test_case(RuleCode::BLE001, Path::new("BLE.py"); "BLE001")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_blind_except") diff --git a/src/flake8_blind_except/plugins.rs b/src/flake8_blind_except/rules.rs similarity index 100% rename from src/flake8_blind_except/plugins.rs rename to src/flake8_blind_except/rules.rs diff --git a/src/flake8_boolean_trap/mod.rs b/src/flake8_boolean_trap/mod.rs index 806c96d016..5e64a2112f 100644 --- a/src/flake8_boolean_trap/mod.rs +++ b/src/flake8_boolean_trap/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; #[cfg(test)] mod tests { @@ -15,7 +15,7 @@ mod tests { #[test_case(RuleCode::FBT001, Path::new("FBT.py"); "FBT001")] #[test_case(RuleCode::FBT002, Path::new("FBT.py"); "FBT002")] #[test_case(RuleCode::FBT003, Path::new("FBT.py"); "FBT003")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_boolean_trap") diff --git a/src/flake8_boolean_trap/plugins.rs b/src/flake8_boolean_trap/rules.rs similarity index 100% rename from src/flake8_boolean_trap/plugins.rs rename to src/flake8_boolean_trap/rules.rs diff --git a/src/flake8_bugbear/mod.rs b/src/flake8_bugbear/mod.rs index 1391ba20f5..0f55196094 100644 --- a/src/flake8_bugbear/mod.rs +++ b/src/flake8_bugbear/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; pub mod settings; #[cfg(test)] @@ -40,7 +40,7 @@ mod tests { #[test_case(RuleCode::B027, Path::new("B027.py"); "B027")] #[test_case(RuleCode::B904, Path::new("B904.py"); "B904")] #[test_case(RuleCode::B905, Path::new("B905.py"); "B905")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_bugbear") diff --git a/src/flake8_bugbear/plugins/abstract_base_class.rs b/src/flake8_bugbear/rules/abstract_base_class.rs similarity index 100% rename from src/flake8_bugbear/plugins/abstract_base_class.rs rename to src/flake8_bugbear/rules/abstract_base_class.rs diff --git a/src/flake8_bugbear/plugins/assert_false.rs b/src/flake8_bugbear/rules/assert_false.rs similarity index 100% rename from src/flake8_bugbear/plugins/assert_false.rs rename to src/flake8_bugbear/rules/assert_false.rs diff --git a/src/flake8_bugbear/plugins/assert_raises_exception.rs b/src/flake8_bugbear/rules/assert_raises_exception.rs similarity index 100% rename from src/flake8_bugbear/plugins/assert_raises_exception.rs rename to src/flake8_bugbear/rules/assert_raises_exception.rs diff --git a/src/flake8_bugbear/plugins/assignment_to_os_environ.rs b/src/flake8_bugbear/rules/assignment_to_os_environ.rs similarity index 100% rename from src/flake8_bugbear/plugins/assignment_to_os_environ.rs rename to src/flake8_bugbear/rules/assignment_to_os_environ.rs diff --git a/src/flake8_bugbear/plugins/cached_instance_method.rs b/src/flake8_bugbear/rules/cached_instance_method.rs similarity index 100% rename from src/flake8_bugbear/plugins/cached_instance_method.rs rename to src/flake8_bugbear/rules/cached_instance_method.rs diff --git a/src/flake8_bugbear/plugins/cannot_raise_literal.rs b/src/flake8_bugbear/rules/cannot_raise_literal.rs similarity index 100% rename from src/flake8_bugbear/plugins/cannot_raise_literal.rs rename to src/flake8_bugbear/rules/cannot_raise_literal.rs diff --git a/src/flake8_bugbear/plugins/duplicate_exceptions.rs b/src/flake8_bugbear/rules/duplicate_exceptions.rs similarity index 100% rename from src/flake8_bugbear/plugins/duplicate_exceptions.rs rename to src/flake8_bugbear/rules/duplicate_exceptions.rs diff --git a/src/flake8_bugbear/plugins/f_string_docstring.rs b/src/flake8_bugbear/rules/f_string_docstring.rs similarity index 100% rename from src/flake8_bugbear/plugins/f_string_docstring.rs rename to src/flake8_bugbear/rules/f_string_docstring.rs diff --git a/src/flake8_bugbear/plugins/function_call_argument_default.rs b/src/flake8_bugbear/rules/function_call_argument_default.rs similarity index 97% rename from src/flake8_bugbear/plugins/function_call_argument_default.rs rename to src/flake8_bugbear/rules/function_call_argument_default.rs index 83b9b84c4f..20c5d3074f 100644 --- a/src/flake8_bugbear/plugins/function_call_argument_default.rs +++ b/src/flake8_bugbear/rules/function_call_argument_default.rs @@ -8,7 +8,7 @@ use crate::ast::types::Range; use crate::ast::visitor; use crate::ast::visitor::Visitor; use crate::checkers::ast::Checker; -use crate::flake8_bugbear::plugins::mutable_argument_default::is_mutable_func; +use crate::flake8_bugbear::rules::mutable_argument_default::is_mutable_func; use crate::registry::{Diagnostic, DiagnosticKind}; use crate::violations; diff --git a/src/flake8_bugbear/plugins/function_uses_loop_variable.rs b/src/flake8_bugbear/rules/function_uses_loop_variable.rs similarity index 100% rename from src/flake8_bugbear/plugins/function_uses_loop_variable.rs rename to src/flake8_bugbear/rules/function_uses_loop_variable.rs diff --git a/src/flake8_bugbear/plugins/getattr_with_constant.rs b/src/flake8_bugbear/rules/getattr_with_constant.rs similarity index 100% rename from src/flake8_bugbear/plugins/getattr_with_constant.rs rename to src/flake8_bugbear/rules/getattr_with_constant.rs diff --git a/src/flake8_bugbear/plugins/jump_statement_in_finally.rs b/src/flake8_bugbear/rules/jump_statement_in_finally.rs similarity index 100% rename from src/flake8_bugbear/plugins/jump_statement_in_finally.rs rename to src/flake8_bugbear/rules/jump_statement_in_finally.rs diff --git a/src/flake8_bugbear/plugins/loop_variable_overrides_iterator.rs b/src/flake8_bugbear/rules/loop_variable_overrides_iterator.rs similarity index 100% rename from src/flake8_bugbear/plugins/loop_variable_overrides_iterator.rs rename to src/flake8_bugbear/rules/loop_variable_overrides_iterator.rs diff --git a/src/flake8_bugbear/plugins/mod.rs b/src/flake8_bugbear/rules/mod.rs similarity index 100% rename from src/flake8_bugbear/plugins/mod.rs rename to src/flake8_bugbear/rules/mod.rs diff --git a/src/flake8_bugbear/plugins/mutable_argument_default.rs b/src/flake8_bugbear/rules/mutable_argument_default.rs similarity index 100% rename from src/flake8_bugbear/plugins/mutable_argument_default.rs rename to src/flake8_bugbear/rules/mutable_argument_default.rs diff --git a/src/flake8_bugbear/plugins/raise_without_from_inside_except.rs b/src/flake8_bugbear/rules/raise_without_from_inside_except.rs similarity index 100% rename from src/flake8_bugbear/plugins/raise_without_from_inside_except.rs rename to src/flake8_bugbear/rules/raise_without_from_inside_except.rs diff --git a/src/flake8_bugbear/plugins/redundant_tuple_in_exception_handler.rs b/src/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs similarity index 100% rename from src/flake8_bugbear/plugins/redundant_tuple_in_exception_handler.rs rename to src/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs diff --git a/src/flake8_bugbear/plugins/setattr_with_constant.rs b/src/flake8_bugbear/rules/setattr_with_constant.rs similarity index 100% rename from src/flake8_bugbear/plugins/setattr_with_constant.rs rename to src/flake8_bugbear/rules/setattr_with_constant.rs diff --git a/src/flake8_bugbear/plugins/star_arg_unpacking_after_keyword_arg.rs b/src/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs similarity index 100% rename from src/flake8_bugbear/plugins/star_arg_unpacking_after_keyword_arg.rs rename to src/flake8_bugbear/rules/star_arg_unpacking_after_keyword_arg.rs diff --git a/src/flake8_bugbear/plugins/strip_with_multi_characters.rs b/src/flake8_bugbear/rules/strip_with_multi_characters.rs similarity index 100% rename from src/flake8_bugbear/plugins/strip_with_multi_characters.rs rename to src/flake8_bugbear/rules/strip_with_multi_characters.rs diff --git a/src/flake8_bugbear/plugins/unary_prefix_increment.rs b/src/flake8_bugbear/rules/unary_prefix_increment.rs similarity index 100% rename from src/flake8_bugbear/plugins/unary_prefix_increment.rs rename to src/flake8_bugbear/rules/unary_prefix_increment.rs diff --git a/src/flake8_bugbear/plugins/unreliable_callable_check.rs b/src/flake8_bugbear/rules/unreliable_callable_check.rs similarity index 100% rename from src/flake8_bugbear/plugins/unreliable_callable_check.rs rename to src/flake8_bugbear/rules/unreliable_callable_check.rs diff --git a/src/flake8_bugbear/plugins/unused_loop_control_variable.rs b/src/flake8_bugbear/rules/unused_loop_control_variable.rs similarity index 100% rename from src/flake8_bugbear/plugins/unused_loop_control_variable.rs rename to src/flake8_bugbear/rules/unused_loop_control_variable.rs diff --git a/src/flake8_bugbear/plugins/useless_comparison.rs b/src/flake8_bugbear/rules/useless_comparison.rs similarity index 100% rename from src/flake8_bugbear/plugins/useless_comparison.rs rename to src/flake8_bugbear/rules/useless_comparison.rs diff --git a/src/flake8_bugbear/plugins/useless_contextlib_suppress.rs b/src/flake8_bugbear/rules/useless_contextlib_suppress.rs similarity index 100% rename from src/flake8_bugbear/plugins/useless_contextlib_suppress.rs rename to src/flake8_bugbear/rules/useless_contextlib_suppress.rs diff --git a/src/flake8_bugbear/plugins/useless_expression.rs b/src/flake8_bugbear/rules/useless_expression.rs similarity index 100% rename from src/flake8_bugbear/plugins/useless_expression.rs rename to src/flake8_bugbear/rules/useless_expression.rs diff --git a/src/flake8_bugbear/plugins/zip_without_explicit_strict.rs b/src/flake8_bugbear/rules/zip_without_explicit_strict.rs similarity index 100% rename from src/flake8_bugbear/plugins/zip_without_explicit_strict.rs rename to src/flake8_bugbear/rules/zip_without_explicit_strict.rs diff --git a/src/flake8_builtins/mod.rs b/src/flake8_builtins/mod.rs index 9a0d68d502..622923312e 100644 --- a/src/flake8_builtins/mod.rs +++ b/src/flake8_builtins/mod.rs @@ -1,4 +1,4 @@ -pub mod checks; +pub mod rules; pub mod types; #[cfg(test)] @@ -16,7 +16,7 @@ mod tests { #[test_case(RuleCode::A001, Path::new("A001.py"); "A001")] #[test_case(RuleCode::A002, Path::new("A002.py"); "A002")] #[test_case(RuleCode::A003, Path::new("A003.py"); "A003")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_builtins") diff --git a/src/flake8_builtins/checks.rs b/src/flake8_builtins/rules.rs similarity index 100% rename from src/flake8_builtins/checks.rs rename to src/flake8_builtins/rules.rs diff --git a/src/flake8_comprehensions/mod.rs b/src/flake8_comprehensions/mod.rs index a518c566c6..11a7189972 100644 --- a/src/flake8_comprehensions/mod.rs +++ b/src/flake8_comprehensions/mod.rs @@ -1,5 +1,5 @@ -pub mod checks; mod fixes; +pub mod rules; #[cfg(test)] mod tests { @@ -30,7 +30,7 @@ mod tests { #[test_case(RuleCode::C416, Path::new("C416.py"); "C416")] #[test_case(RuleCode::C417, Path::new("C417.py"); "C417")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_comprehensions") diff --git a/src/flake8_comprehensions/checks.rs b/src/flake8_comprehensions/rules.rs similarity index 100% rename from src/flake8_comprehensions/checks.rs rename to src/flake8_comprehensions/rules.rs diff --git a/src/flake8_datetimez/mod.rs b/src/flake8_datetimez/mod.rs index 80210c3464..a184ab28e8 100644 --- a/src/flake8_datetimez/mod.rs +++ b/src/flake8_datetimez/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; #[cfg(test)] mod tests { @@ -21,7 +21,7 @@ mod tests { #[test_case(RuleCode::DTZ007, Path::new("DTZ007.py"); "DTZ007")] #[test_case(RuleCode::DTZ011, Path::new("DTZ011.py"); "DTZ011")] #[test_case(RuleCode::DTZ012, Path::new("DTZ012.py"); "DTZ012")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_datetimez") diff --git a/src/flake8_datetimez/plugins.rs b/src/flake8_datetimez/rules.rs similarity index 100% rename from src/flake8_datetimez/plugins.rs rename to src/flake8_datetimez/rules.rs diff --git a/src/flake8_debugger/mod.rs b/src/flake8_debugger/mod.rs index ef5fe55e5e..234832ac60 100644 --- a/src/flake8_debugger/mod.rs +++ b/src/flake8_debugger/mod.rs @@ -1,4 +1,4 @@ -pub mod checks; +pub mod rules; pub mod types; #[cfg(test)] @@ -14,7 +14,7 @@ mod tests { use crate::settings; #[test_case(RuleCode::T100, Path::new("T100.py"); "T100")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_debugger") diff --git a/src/flake8_debugger/checks.rs b/src/flake8_debugger/rules.rs similarity index 100% rename from src/flake8_debugger/checks.rs rename to src/flake8_debugger/rules.rs diff --git a/src/flake8_errmsg/mod.rs b/src/flake8_errmsg/mod.rs index 6e2798bdf2..5c16749d57 100644 --- a/src/flake8_errmsg/mod.rs +++ b/src/flake8_errmsg/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; pub mod settings; #[cfg(test)] diff --git a/src/flake8_errmsg/plugins.rs b/src/flake8_errmsg/rules.rs similarity index 100% rename from src/flake8_errmsg/plugins.rs rename to src/flake8_errmsg/rules.rs diff --git a/src/flake8_implicit_str_concat/mod.rs b/src/flake8_implicit_str_concat/mod.rs index 62aa9dc632..43b0f8b7dc 100644 --- a/src/flake8_implicit_str_concat/mod.rs +++ b/src/flake8_implicit_str_concat/mod.rs @@ -1,4 +1,4 @@ -pub mod checks; +pub mod rules; #[cfg(test)] mod tests { @@ -15,7 +15,7 @@ mod tests { #[test_case(RuleCode::ISC001, Path::new("ISC.py"); "ISC001")] #[test_case(RuleCode::ISC002, Path::new("ISC.py"); "ISC002")] #[test_case(RuleCode::ISC003, Path::new("ISC.py"); "ISC003")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_implicit_str_concat") diff --git a/src/flake8_implicit_str_concat/checks.rs b/src/flake8_implicit_str_concat/rules.rs similarity index 100% rename from src/flake8_implicit_str_concat/checks.rs rename to src/flake8_implicit_str_concat/rules.rs diff --git a/src/flake8_import_conventions/mod.rs b/src/flake8_import_conventions/mod.rs index a98855ae2f..e475c28695 100644 --- a/src/flake8_import_conventions/mod.rs +++ b/src/flake8_import_conventions/mod.rs @@ -1,4 +1,4 @@ -pub mod checks; +pub mod rules; pub mod settings; #[cfg(test)] diff --git a/src/flake8_import_conventions/checks.rs b/src/flake8_import_conventions/rules.rs similarity index 100% rename from src/flake8_import_conventions/checks.rs rename to src/flake8_import_conventions/rules.rs diff --git a/src/flake8_pie/mod.rs b/src/flake8_pie/mod.rs index 53674e269a..085207e925 100644 --- a/src/flake8_pie/mod.rs +++ b/src/flake8_pie/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; #[cfg(test)] mod tests { @@ -15,7 +15,7 @@ mod tests { #[test_case(RuleCode::PIE790, Path::new("PIE790.py"); "PIE790")] #[test_case(RuleCode::PIE794, Path::new("PIE794.py"); "PIE794")] #[test_case(RuleCode::PIE807, Path::new("PIE807.py"); "PIE807")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_pie") diff --git a/src/flake8_pie/plugins.rs b/src/flake8_pie/rules.rs similarity index 100% rename from src/flake8_pie/plugins.rs rename to src/flake8_pie/rules.rs diff --git a/src/flake8_print/mod.rs b/src/flake8_print/mod.rs index 696986f7f3..9ed5e30716 100644 --- a/src/flake8_print/mod.rs +++ b/src/flake8_print/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; #[cfg(test)] mod tests { @@ -14,7 +14,7 @@ mod tests { #[test_case(RuleCode::T201, Path::new("T201.py"); "T201")] #[test_case(RuleCode::T203, Path::new("T203.py"); "T203")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_print") diff --git a/src/flake8_print/plugins/mod.rs b/src/flake8_print/rules/mod.rs similarity index 100% rename from src/flake8_print/plugins/mod.rs rename to src/flake8_print/rules/mod.rs diff --git a/src/flake8_print/plugins/print_call.rs b/src/flake8_print/rules/print_call.rs similarity index 100% rename from src/flake8_print/plugins/print_call.rs rename to src/flake8_print/rules/print_call.rs diff --git a/src/flake8_pytest_style/mod.rs b/src/flake8_pytest_style/mod.rs index 3d44e21cd6..6a643dee22 100644 --- a/src/flake8_pytest_style/mod.rs +++ b/src/flake8_pytest_style/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; pub mod settings; pub mod types; diff --git a/src/flake8_pytest_style/plugins/assertion.rs b/src/flake8_pytest_style/rules/assertion.rs similarity index 100% rename from src/flake8_pytest_style/plugins/assertion.rs rename to src/flake8_pytest_style/rules/assertion.rs diff --git a/src/flake8_pytest_style/plugins/fail.rs b/src/flake8_pytest_style/rules/fail.rs similarity index 100% rename from src/flake8_pytest_style/plugins/fail.rs rename to src/flake8_pytest_style/rules/fail.rs diff --git a/src/flake8_pytest_style/plugins/fixture.rs b/src/flake8_pytest_style/rules/fixture.rs similarity index 100% rename from src/flake8_pytest_style/plugins/fixture.rs rename to src/flake8_pytest_style/rules/fixture.rs diff --git a/src/flake8_pytest_style/plugins/helpers.rs b/src/flake8_pytest_style/rules/helpers.rs similarity index 100% rename from src/flake8_pytest_style/plugins/helpers.rs rename to src/flake8_pytest_style/rules/helpers.rs diff --git a/src/flake8_pytest_style/plugins/imports.rs b/src/flake8_pytest_style/rules/imports.rs similarity index 100% rename from src/flake8_pytest_style/plugins/imports.rs rename to src/flake8_pytest_style/rules/imports.rs diff --git a/src/flake8_pytest_style/plugins/marks.rs b/src/flake8_pytest_style/rules/marks.rs similarity index 100% rename from src/flake8_pytest_style/plugins/marks.rs rename to src/flake8_pytest_style/rules/marks.rs diff --git a/src/flake8_pytest_style/plugins/mod.rs b/src/flake8_pytest_style/rules/mod.rs similarity index 100% rename from src/flake8_pytest_style/plugins/mod.rs rename to src/flake8_pytest_style/rules/mod.rs diff --git a/src/flake8_pytest_style/plugins/parametrize.rs b/src/flake8_pytest_style/rules/parametrize.rs similarity index 100% rename from src/flake8_pytest_style/plugins/parametrize.rs rename to src/flake8_pytest_style/rules/parametrize.rs diff --git a/src/flake8_pytest_style/plugins/patch.rs b/src/flake8_pytest_style/rules/patch.rs similarity index 100% rename from src/flake8_pytest_style/plugins/patch.rs rename to src/flake8_pytest_style/rules/patch.rs diff --git a/src/flake8_pytest_style/plugins/raises.rs b/src/flake8_pytest_style/rules/raises.rs similarity index 100% rename from src/flake8_pytest_style/plugins/raises.rs rename to src/flake8_pytest_style/rules/raises.rs diff --git a/src/flake8_pytest_style/plugins/unittest_assert.rs b/src/flake8_pytest_style/rules/unittest_assert.rs similarity index 100% rename from src/flake8_pytest_style/plugins/unittest_assert.rs rename to src/flake8_pytest_style/rules/unittest_assert.rs diff --git a/src/flake8_quotes/mod.rs b/src/flake8_quotes/mod.rs index 2ad2a2c706..87d48b07f6 100644 --- a/src/flake8_quotes/mod.rs +++ b/src/flake8_quotes/mod.rs @@ -1,4 +1,4 @@ -pub mod checks; +pub mod rules; pub mod settings; #[cfg(test)] diff --git a/src/flake8_quotes/checks.rs b/src/flake8_quotes/rules.rs similarity index 100% rename from src/flake8_quotes/checks.rs rename to src/flake8_quotes/rules.rs diff --git a/src/flake8_return/mod.rs b/src/flake8_return/mod.rs index 833d46879d..1273b8ccbd 100644 --- a/src/flake8_return/mod.rs +++ b/src/flake8_return/mod.rs @@ -1,5 +1,5 @@ mod helpers; -pub mod plugins; +pub mod rules; mod visitor; #[cfg(test)] @@ -21,7 +21,7 @@ mod tests { #[test_case(RuleCode::RET506, Path::new("RET506.py"); "RET506")] #[test_case(RuleCode::RET507, Path::new("RET507.py"); "RET507")] #[test_case(RuleCode::RET508, Path::new("RET508.py"); "RET508")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_return") diff --git a/src/flake8_return/plugins.rs b/src/flake8_return/rules.rs similarity index 100% rename from src/flake8_return/plugins.rs rename to src/flake8_return/rules.rs diff --git a/src/flake8_simplify/mod.rs b/src/flake8_simplify/mod.rs index 39402f0afa..99fdf6f852 100644 --- a/src/flake8_simplify/mod.rs +++ b/src/flake8_simplify/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; #[cfg(test)] mod tests { @@ -34,7 +34,7 @@ mod tests { #[test_case(RuleCode::SIM222, Path::new("SIM222.py"); "SIM222")] #[test_case(RuleCode::SIM223, Path::new("SIM223.py"); "SIM223")] #[test_case(RuleCode::SIM300, Path::new("SIM300.py"); "SIM300")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_simplify") diff --git a/src/flake8_simplify/plugins/ast_bool_op.rs b/src/flake8_simplify/rules/ast_bool_op.rs similarity index 100% rename from src/flake8_simplify/plugins/ast_bool_op.rs rename to src/flake8_simplify/rules/ast_bool_op.rs diff --git a/src/flake8_simplify/plugins/ast_for.rs b/src/flake8_simplify/rules/ast_for.rs similarity index 100% rename from src/flake8_simplify/plugins/ast_for.rs rename to src/flake8_simplify/rules/ast_for.rs diff --git a/src/flake8_simplify/plugins/ast_if.rs b/src/flake8_simplify/rules/ast_if.rs similarity index 100% rename from src/flake8_simplify/plugins/ast_if.rs rename to src/flake8_simplify/rules/ast_if.rs diff --git a/src/flake8_simplify/plugins/ast_ifexp.rs b/src/flake8_simplify/rules/ast_ifexp.rs similarity index 100% rename from src/flake8_simplify/plugins/ast_ifexp.rs rename to src/flake8_simplify/rules/ast_ifexp.rs diff --git a/src/flake8_simplify/plugins/ast_unary_op.rs b/src/flake8_simplify/rules/ast_unary_op.rs similarity index 100% rename from src/flake8_simplify/plugins/ast_unary_op.rs rename to src/flake8_simplify/rules/ast_unary_op.rs diff --git a/src/flake8_simplify/plugins/ast_with.rs b/src/flake8_simplify/rules/ast_with.rs similarity index 100% rename from src/flake8_simplify/plugins/ast_with.rs rename to src/flake8_simplify/rules/ast_with.rs diff --git a/src/flake8_simplify/plugins/key_in_dict.rs b/src/flake8_simplify/rules/key_in_dict.rs similarity index 100% rename from src/flake8_simplify/plugins/key_in_dict.rs rename to src/flake8_simplify/rules/key_in_dict.rs diff --git a/src/flake8_simplify/plugins/mod.rs b/src/flake8_simplify/rules/mod.rs similarity index 100% rename from src/flake8_simplify/plugins/mod.rs rename to src/flake8_simplify/rules/mod.rs diff --git a/src/flake8_simplify/plugins/return_in_try_except_finally.rs b/src/flake8_simplify/rules/return_in_try_except_finally.rs similarity index 100% rename from src/flake8_simplify/plugins/return_in_try_except_finally.rs rename to src/flake8_simplify/rules/return_in_try_except_finally.rs diff --git a/src/flake8_simplify/plugins/use_contextlib_suppress.rs b/src/flake8_simplify/rules/use_contextlib_suppress.rs similarity index 100% rename from src/flake8_simplify/plugins/use_contextlib_suppress.rs rename to src/flake8_simplify/rules/use_contextlib_suppress.rs diff --git a/src/flake8_simplify/plugins/yoda_conditions.rs b/src/flake8_simplify/rules/yoda_conditions.rs similarity index 100% rename from src/flake8_simplify/plugins/yoda_conditions.rs rename to src/flake8_simplify/rules/yoda_conditions.rs diff --git a/src/flake8_tidy_imports/mod.rs b/src/flake8_tidy_imports/mod.rs index b2f07764a6..f8cc4037dc 100644 --- a/src/flake8_tidy_imports/mod.rs +++ b/src/flake8_tidy_imports/mod.rs @@ -1,4 +1,4 @@ -pub mod checks; +pub mod rules; pub mod settings; #[cfg(test)] diff --git a/src/flake8_tidy_imports/checks.rs b/src/flake8_tidy_imports/rules.rs similarity index 100% rename from src/flake8_tidy_imports/checks.rs rename to src/flake8_tidy_imports/rules.rs diff --git a/src/flake8_unused_arguments/mod.rs b/src/flake8_unused_arguments/mod.rs index 45eb9e0b92..304216e6e7 100644 --- a/src/flake8_unused_arguments/mod.rs +++ b/src/flake8_unused_arguments/mod.rs @@ -1,5 +1,5 @@ mod helpers; -pub mod plugins; +pub mod rules; pub mod settings; mod types; @@ -20,7 +20,7 @@ mod tests { #[test_case(RuleCode::ARG003, Path::new("ARG.py"); "ARG003")] #[test_case(RuleCode::ARG004, Path::new("ARG.py"); "ARG004")] #[test_case(RuleCode::ARG005, Path::new("ARG.py"); "ARG005")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/flake8_unused_arguments") diff --git a/src/flake8_unused_arguments/plugins.rs b/src/flake8_unused_arguments/rules.rs similarity index 100% rename from src/flake8_unused_arguments/plugins.rs rename to src/flake8_unused_arguments/rules.rs diff --git a/src/isort/mod.rs b/src/isort/mod.rs index ff53b889c0..b32568ba66 100644 --- a/src/isort/mod.rs +++ b/src/isort/mod.rs @@ -25,7 +25,7 @@ mod categorize; mod comments; pub mod format; pub mod helpers; -pub mod plugins; +pub mod rules; pub mod settings; mod sorting; pub mod track; diff --git a/src/isort/plugins.rs b/src/isort/rules.rs similarity index 100% rename from src/isort/plugins.rs rename to src/isort/rules.rs diff --git a/src/mccabe/mod.rs b/src/mccabe/mod.rs index 816bb5e68d..0174182eb1 100644 --- a/src/mccabe/mod.rs +++ b/src/mccabe/mod.rs @@ -1,4 +1,4 @@ -pub mod checks; +pub mod rules; pub mod settings; #[cfg(test)] diff --git a/src/mccabe/checks.rs b/src/mccabe/rules.rs similarity index 99% rename from src/mccabe/checks.rs rename to src/mccabe/rules.rs index e1696a60a6..a42f30c78e 100644 --- a/src/mccabe/checks.rs +++ b/src/mccabe/rules.rs @@ -79,7 +79,7 @@ mod tests { use anyhow::Result; use rustpython_parser::parser; - use crate::mccabe::checks::get_complexity_number; + use crate::mccabe::rules::get_complexity_number; #[test] fn trivial() -> Result<()> { diff --git a/src/pandas_vet/mod.rs b/src/pandas_vet/mod.rs index cac3af93bd..eef329d7a8 100644 --- a/src/pandas_vet/mod.rs +++ b/src/pandas_vet/mod.rs @@ -1,5 +1,5 @@ -pub mod checks; pub mod helpers; +pub mod rules; #[cfg(test)] mod tests { diff --git a/src/pandas_vet/checks.rs b/src/pandas_vet/rules.rs similarity index 100% rename from src/pandas_vet/checks.rs rename to src/pandas_vet/rules.rs diff --git a/src/pep8_naming/mod.rs b/src/pep8_naming/mod.rs index b75be69f3a..27b6036531 100644 --- a/src/pep8_naming/mod.rs +++ b/src/pep8_naming/mod.rs @@ -1,6 +1,5 @@ -pub mod checks; mod helpers; -pub mod plugins; +pub mod rules; pub mod settings; #[cfg(test)] @@ -30,7 +29,7 @@ mod tests { #[test_case(RuleCode::N816, Path::new("N816.py"); "N816")] #[test_case(RuleCode::N817, Path::new("N817.py"); "N817")] #[test_case(RuleCode::N818, Path::new("N818.py"); "N818")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pep8_naming") diff --git a/src/pep8_naming/plugins.rs b/src/pep8_naming/plugins.rs deleted file mode 100644 index becde97462..0000000000 --- a/src/pep8_naming/plugins.rs +++ /dev/null @@ -1,57 +0,0 @@ -use rustpython_ast::{Expr, Stmt}; - -use crate::ast::types::Range; -use crate::checkers::ast::Checker; -use crate::pep8_naming::helpers; -use crate::{violations, Diagnostic}; - -/// N806 -pub fn non_lowercase_variable_in_function( - checker: &mut Checker, - expr: &Expr, - stmt: &Stmt, - name: &str, -) { - if name.to_lowercase() != name - && !helpers::is_namedtuple_assignment(stmt, &checker.from_imports) - { - checker.diagnostics.push(Diagnostic::new( - violations::NonLowercaseVariableInFunction(name.to_string()), - Range::from_located(expr), - )); - } -} - -/// N815 -pub fn mixed_case_variable_in_class_scope( - checker: &mut Checker, - expr: &Expr, - stmt: &Stmt, - name: &str, -) { - if helpers::is_mixed_case(name) - && !helpers::is_namedtuple_assignment(stmt, &checker.from_imports) - { - checker.diagnostics.push(Diagnostic::new( - violations::MixedCaseVariableInClassScope(name.to_string()), - Range::from_located(expr), - )); - } -} - -/// N816 -pub fn mixed_case_variable_in_global_scope( - checker: &mut Checker, - expr: &Expr, - stmt: &Stmt, - name: &str, -) { - if helpers::is_mixed_case(name) - && !helpers::is_namedtuple_assignment(stmt, &checker.from_imports) - { - checker.diagnostics.push(Diagnostic::new( - violations::MixedCaseVariableInGlobalScope(name.to_string()), - Range::from_located(expr), - )); - } -} diff --git a/src/pep8_naming/checks.rs b/src/pep8_naming/rules.rs similarity index 84% rename from src/pep8_naming/checks.rs rename to src/pep8_naming/rules.rs index d520765ff8..0c34d516b1 100644 --- a/src/pep8_naming/checks.rs +++ b/src/pep8_naming/rules.rs @@ -4,6 +4,7 @@ use rustpython_ast::{Arg, Arguments, Expr, ExprKind, Stmt}; use crate::ast::function_type; use crate::ast::helpers::identifier_range; use crate::ast::types::{Range, Scope, ScopeKind}; +use crate::checkers::ast::Checker; use crate::pep8_naming::helpers; use crate::pep8_naming::settings::Settings; use crate::python::string::{self}; @@ -130,6 +131,23 @@ pub fn invalid_first_argument_name_for_method( )) } +/// N806 +pub fn non_lowercase_variable_in_function( + checker: &mut Checker, + expr: &Expr, + stmt: &Stmt, + name: &str, +) { + if name.to_lowercase() != name + && !helpers::is_namedtuple_assignment(stmt, &checker.from_imports) + { + checker.diagnostics.push(Diagnostic::new( + violations::NonLowercaseVariableInFunction(name.to_string()), + Range::from_located(expr), + )); + } +} + /// N807 pub fn dunder_function_name( scope: &Scope, @@ -222,6 +240,40 @@ pub fn camelcase_imported_as_constant( None } +/// N815 +pub fn mixed_case_variable_in_class_scope( + checker: &mut Checker, + expr: &Expr, + stmt: &Stmt, + name: &str, +) { + if helpers::is_mixed_case(name) + && !helpers::is_namedtuple_assignment(stmt, &checker.from_imports) + { + checker.diagnostics.push(Diagnostic::new( + violations::MixedCaseVariableInClassScope(name.to_string()), + Range::from_located(expr), + )); + } +} + +/// N816 +pub fn mixed_case_variable_in_global_scope( + checker: &mut Checker, + expr: &Expr, + stmt: &Stmt, + name: &str, +) { + if helpers::is_mixed_case(name) + && !helpers::is_namedtuple_assignment(stmt, &checker.from_imports) + { + checker.diagnostics.push(Diagnostic::new( + violations::MixedCaseVariableInGlobalScope(name.to_string()), + Range::from_located(expr), + )); + } +} + /// N817 pub fn camelcase_imported_as_acronym( import_from: &Stmt, diff --git a/src/pycodestyle/checks.rs b/src/pycodestyle/checks.rs deleted file mode 100644 index d4d7c010d6..0000000000 --- a/src/pycodestyle/checks.rs +++ /dev/null @@ -1,269 +0,0 @@ -use itertools::izip; -use once_cell::sync::Lazy; -use regex::Regex; -use rustpython_ast::{Constant, Excepthandler, Location, Stmt, StmtKind}; -use rustpython_parser::ast::{Cmpop, Expr, ExprKind}; - -use crate::ast::helpers::except_range; -use crate::ast::types::Range; -use crate::autofix::Fix; -use crate::registry::Diagnostic; -use crate::settings::Settings; -use crate::source_code_locator::SourceCodeLocator; -use crate::violations; - -static URL_REGEX: Lazy = Lazy::new(|| Regex::new(r"^https?://\S+$").unwrap()); - -/// E501 -pub fn line_too_long(lineno: usize, line: &str, settings: &Settings) -> Option { - let line_length = line.chars().count(); - - if line_length <= settings.line_length { - return None; - } - - let mut chunks = line.split_whitespace(); - let (Some(first), Some(second)) = (chunks.next(), chunks.next()) else { - // Single word / no printable chars - no way to make the line shorter - return None; - }; - - if first == "#" { - if settings.pycodestyle.ignore_overlong_task_comments { - let second = second.trim_end_matches(':'); - if settings.task_tags.iter().any(|tag| tag == second) { - return None; - } - } - - // Do not enforce the line length for commented lines that end with a URL - // or contain only a single word. - if chunks.last().map_or(true, |c| URL_REGEX.is_match(c)) { - return None; - } - } - - Some(Diagnostic::new( - violations::LineTooLong(line_length, settings.line_length), - Range::new( - Location::new(lineno + 1, settings.line_length), - Location::new(lineno + 1, line_length), - ), - )) -} - -/// E721 -pub fn type_comparison(ops: &[Cmpop], comparators: &[Expr], location: Range) -> Vec { - let mut diagnostics: Vec = vec![]; - - for (op, right) in izip!(ops, comparators) { - if !matches!(op, Cmpop::Is | Cmpop::IsNot | Cmpop::Eq | Cmpop::NotEq) { - continue; - } - match &right.node { - ExprKind::Call { func, args, .. } => { - if let ExprKind::Name { id, .. } = &func.node { - // Ex) type(False) - if id == "type" { - if let Some(arg) = args.first() { - // Allow comparison for types which are not obvious. - if !matches!( - arg.node, - ExprKind::Name { .. } - | ExprKind::Constant { - value: Constant::None, - kind: None - } - ) { - diagnostics - .push(Diagnostic::new(violations::TypeComparison, location)); - } - } - } - } - } - ExprKind::Attribute { value, .. } => { - if let ExprKind::Name { id, .. } = &value.node { - // Ex) types.IntType - if id == "types" { - diagnostics.push(Diagnostic::new(violations::TypeComparison, location)); - } - } - } - _ => {} - } - } - - diagnostics -} - -/// E722 -pub fn do_not_use_bare_except( - type_: Option<&Expr>, - body: &[Stmt], - handler: &Excepthandler, - locator: &SourceCodeLocator, -) -> Option { - if type_.is_none() - && !body - .iter() - .any(|stmt| matches!(stmt.node, StmtKind::Raise { exc: None, .. })) - { - Some(Diagnostic::new( - violations::DoNotUseBareExcept, - except_range(handler, locator), - )) - } else { - None - } -} - -fn is_ambiguous_name(name: &str) -> bool { - name == "l" || name == "I" || name == "O" -} - -/// E741 -pub fn ambiguous_variable_name(name: &str, range: Range) -> Option { - if is_ambiguous_name(name) { - Some(Diagnostic::new( - violations::AmbiguousVariableName(name.to_string()), - range, - )) - } else { - None - } -} - -/// E742 -pub fn ambiguous_class_name(name: &str, locate: F) -> Option -where - F: FnOnce() -> Range, -{ - if is_ambiguous_name(name) { - Some(Diagnostic::new( - violations::AmbiguousClassName(name.to_string()), - locate(), - )) - } else { - None - } -} - -/// E743 -pub fn ambiguous_function_name(name: &str, locate: F) -> Option -where - F: FnOnce() -> Range, -{ - if is_ambiguous_name(name) { - Some(Diagnostic::new( - violations::AmbiguousFunctionName(name.to_string()), - locate(), - )) - } else { - None - } -} - -/// W292 -pub fn no_newline_at_end_of_file(contents: &str, autofix: bool) -> Option { - if !contents.ends_with('\n') { - // Note: if `lines.last()` is `None`, then `contents` is empty (and so we don't - // want to raise W292 anyway). - if let Some(line) = contents.lines().last() { - // Both locations are at the end of the file (and thus the same). - let location = Location::new(contents.lines().count(), line.len()); - let mut diagnostic = Diagnostic::new( - violations::NoNewLineAtEndOfFile, - Range::new(location, location), - ); - if autofix { - diagnostic.amend(Fix::insertion("\n".to_string(), location)); - } - return Some(diagnostic); - } - } - None -} - -// See: https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals -const VALID_ESCAPE_SEQUENCES: &[char; 23] = &[ - '\n', '\\', '\'', '"', 'a', 'b', 'f', 'n', 'r', 't', 'v', '0', '1', '2', '3', '4', '5', '6', - '7', 'x', // Escape sequences only recognized in string literals - 'N', 'u', 'U', -]; - -/// Return the quotation markers used for a String token. -fn extract_quote(text: &str) -> &str { - for quote in ["'''", "\"\"\"", "'", "\""] { - if text.ends_with(quote) { - return quote; - } - } - - panic!("Unable to find quotation mark for String token") -} - -/// W605 -pub fn invalid_escape_sequence( - locator: &SourceCodeLocator, - start: Location, - end: Location, - autofix: bool, -) -> Vec { - let mut diagnostics = vec![]; - - let text = locator.slice_source_code_range(&Range::new(start, end)); - - // Determine whether the string is single- or triple-quoted. - let quote = extract_quote(&text); - let quote_pos = text.find(quote).unwrap(); - let prefix = text[..quote_pos].to_lowercase(); - let body = &text[(quote_pos + quote.len())..(text.len() - quote.len())]; - - if !prefix.contains('r') { - for (row_offset, line) in body.lines().enumerate() { - let chars: Vec = line.chars().collect(); - for col_offset in 0..chars.len() { - if chars[col_offset] != '\\' { - continue; - } - - // If the previous character was also a backslash, skip. - if col_offset > 0 && chars[col_offset - 1] == '\\' { - continue; - } - - // If we're at the end of the line, skip. - if col_offset == chars.len() - 1 { - continue; - } - - // If the next character is a valid escape sequence, skip. - let next_char = chars[col_offset + 1]; - if VALID_ESCAPE_SEQUENCES.contains(&next_char) { - continue; - } - - // Compute the location of the escape sequence by offsetting the location of the - // string token by the characters we've seen thus far. - let col = if row_offset == 0 { - start.column() + prefix.len() + quote.len() + col_offset - } else { - col_offset - }; - let location = Location::new(start.row() + row_offset, col); - let end_location = Location::new(location.row(), location.column() + 2); - let mut diagnostic = Diagnostic::new( - violations::InvalidEscapeSequence(next_char), - Range::new(location, end_location), - ); - if autofix { - diagnostic.amend(Fix::insertion(r"\".to_string(), location)); - } - diagnostics.push(diagnostic); - } - } - } - - diagnostics -} diff --git a/src/pycodestyle/mod.rs b/src/pycodestyle/mod.rs index 9bc467427f..3d0128f841 100644 --- a/src/pycodestyle/mod.rs +++ b/src/pycodestyle/mod.rs @@ -1,5 +1,4 @@ -pub mod checks; -pub mod plugins; +pub mod rules; pub mod settings; #[cfg(test)] @@ -37,7 +36,7 @@ mod tests { #[test_case(RuleCode::W292, Path::new("W292_4.py"))] #[test_case(RuleCode::W605, Path::new("W605_0.py"))] #[test_case(RuleCode::W605, Path::new("W605_1.py"))] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pycodestyle") diff --git a/src/pycodestyle/plugins.rs b/src/pycodestyle/rules.rs similarity index 57% rename from src/pycodestyle/plugins.rs rename to src/pycodestyle/rules.rs index 10235ae010..53deb15012 100644 --- a/src/pycodestyle/plugins.rs +++ b/src/pycodestyle/rules.rs @@ -1,22 +1,66 @@ use itertools::izip; +use once_cell::sync::Lazy; +use regex::Regex; use rustc_hash::FxHashMap; -use rustpython_ast::{Arguments, Location, StmtKind}; -use rustpython_parser::ast::{Cmpop, Constant, Expr, ExprKind, Stmt, Unaryop}; +use rustpython_ast::{Arguments, Constant, Excepthandler, Location, Stmt, StmtKind, Unaryop}; +use rustpython_parser::ast::{Cmpop, Expr, ExprKind}; use crate::ast::helpers; use crate::ast::helpers::{ - create_expr, match_leading_content, match_trailing_content, unparse_expr, + create_expr, except_range, match_leading_content, match_trailing_content, unparse_expr, }; use crate::ast::types::Range; use crate::ast::whitespace::leading_space; use crate::autofix::Fix; use crate::checkers::ast::Checker; use crate::registry::Diagnostic; +use crate::settings::Settings; use crate::source_code_generator::SourceCodeGenerator; +use crate::source_code_locator::SourceCodeLocator; use crate::source_code_style::SourceCodeStyleDetector; use crate::violations; -pub fn compare( +static URL_REGEX: Lazy = Lazy::new(|| Regex::new(r"^https?://\S+$").unwrap()); + +/// E501 +pub fn line_too_long(lineno: usize, line: &str, settings: &Settings) -> Option { + let line_length = line.chars().count(); + + if line_length <= settings.line_length { + return None; + } + + let mut chunks = line.split_whitespace(); + let (Some(first), Some(second)) = (chunks.next(), chunks.next()) else { + // Single word / no printable chars - no way to make the line shorter + return None; + }; + + if first == "#" { + if settings.pycodestyle.ignore_overlong_task_comments { + let second = second.trim_end_matches(':'); + if settings.task_tags.iter().any(|tag| tag == second) { + return None; + } + } + + // Do not enforce the line length for commented lines that end with a URL + // or contain only a single word. + if chunks.last().map_or(true, |c| URL_REGEX.is_match(c)) { + return None; + } + } + + Some(Diagnostic::new( + violations::LineTooLong(line_length, settings.line_length), + Range::new( + Location::new(lineno + 1, settings.line_length), + Location::new(lineno + 1, line_length), + ), + )) +} + +fn compare( left: &Expr, ops: &[Cmpop], comparators: &[Expr], @@ -273,6 +317,72 @@ pub fn not_tests( } } +/// E721 +pub fn type_comparison(ops: &[Cmpop], comparators: &[Expr], location: Range) -> Vec { + let mut diagnostics: Vec = vec![]; + + for (op, right) in izip!(ops, comparators) { + if !matches!(op, Cmpop::Is | Cmpop::IsNot | Cmpop::Eq | Cmpop::NotEq) { + continue; + } + match &right.node { + ExprKind::Call { func, args, .. } => { + if let ExprKind::Name { id, .. } = &func.node { + // Ex) type(False) + if id == "type" { + if let Some(arg) = args.first() { + // Allow comparison for types which are not obvious. + if !matches!( + arg.node, + ExprKind::Name { .. } + | ExprKind::Constant { + value: Constant::None, + kind: None + } + ) { + diagnostics + .push(Diagnostic::new(violations::TypeComparison, location)); + } + } + } + } + } + ExprKind::Attribute { value, .. } => { + if let ExprKind::Name { id, .. } = &value.node { + // Ex) types.IntType + if id == "types" { + diagnostics.push(Diagnostic::new(violations::TypeComparison, location)); + } + } + } + _ => {} + } + } + + diagnostics +} + +/// E722 +pub fn do_not_use_bare_except( + type_: Option<&Expr>, + body: &[Stmt], + handler: &Excepthandler, + locator: &SourceCodeLocator, +) -> Option { + if type_.is_none() + && !body + .iter() + .any(|stmt| matches!(stmt.node, StmtKind::Raise { exc: None, .. })) + { + Some(Diagnostic::new( + violations::DoNotUseBareExcept, + except_range(handler, locator), + )) + } else { + None + } +} + fn function( name: &str, args: &Arguments, @@ -341,3 +451,153 @@ pub fn do_not_assign_lambda(checker: &mut Checker, target: &Expr, value: &Expr, } } } + +fn is_ambiguous_name(name: &str) -> bool { + name == "l" || name == "I" || name == "O" +} + +/// E741 +pub fn ambiguous_variable_name(name: &str, range: Range) -> Option { + if is_ambiguous_name(name) { + Some(Diagnostic::new( + violations::AmbiguousVariableName(name.to_string()), + range, + )) + } else { + None + } +} + +/// E742 +pub fn ambiguous_class_name(name: &str, locate: F) -> Option +where + F: FnOnce() -> Range, +{ + if is_ambiguous_name(name) { + Some(Diagnostic::new( + violations::AmbiguousClassName(name.to_string()), + locate(), + )) + } else { + None + } +} + +/// E743 +pub fn ambiguous_function_name(name: &str, locate: F) -> Option +where + F: FnOnce() -> Range, +{ + if is_ambiguous_name(name) { + Some(Diagnostic::new( + violations::AmbiguousFunctionName(name.to_string()), + locate(), + )) + } else { + None + } +} + +/// W292 +pub fn no_newline_at_end_of_file(contents: &str, autofix: bool) -> Option { + if !contents.ends_with('\n') { + // Note: if `lines.last()` is `None`, then `contents` is empty (and so we don't + // want to raise W292 anyway). + if let Some(line) = contents.lines().last() { + // Both locations are at the end of the file (and thus the same). + let location = Location::new(contents.lines().count(), line.len()); + let mut diagnostic = Diagnostic::new( + violations::NoNewLineAtEndOfFile, + Range::new(location, location), + ); + if autofix { + diagnostic.amend(Fix::insertion("\n".to_string(), location)); + } + return Some(diagnostic); + } + } + None +} + +// See: https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals +const VALID_ESCAPE_SEQUENCES: &[char; 23] = &[ + '\n', '\\', '\'', '"', 'a', 'b', 'f', 'n', 'r', 't', 'v', '0', '1', '2', '3', '4', '5', '6', + '7', 'x', // Escape sequences only recognized in string literals + 'N', 'u', 'U', +]; + +/// Return the quotation markers used for a String token. +fn extract_quote(text: &str) -> &str { + for quote in ["'''", "\"\"\"", "'", "\""] { + if text.ends_with(quote) { + return quote; + } + } + + panic!("Unable to find quotation mark for String token") +} + +/// W605 +pub fn invalid_escape_sequence( + locator: &SourceCodeLocator, + start: Location, + end: Location, + autofix: bool, +) -> Vec { + let mut diagnostics = vec![]; + + let text = locator.slice_source_code_range(&Range::new(start, end)); + + // Determine whether the string is single- or triple-quoted. + let quote = extract_quote(&text); + let quote_pos = text.find(quote).unwrap(); + let prefix = text[..quote_pos].to_lowercase(); + let body = &text[(quote_pos + quote.len())..(text.len() - quote.len())]; + + if !prefix.contains('r') { + for (row_offset, line) in body.lines().enumerate() { + let chars: Vec = line.chars().collect(); + for col_offset in 0..chars.len() { + if chars[col_offset] != '\\' { + continue; + } + + // If the previous character was also a backslash, skip. + if col_offset > 0 && chars[col_offset - 1] == '\\' { + continue; + } + + // If we're at the end of the line, skip. + if col_offset == chars.len() - 1 { + continue; + } + + // If the next character is a valid escape sequence, skip. + let next_char = chars[col_offset + 1]; + if VALID_ESCAPE_SEQUENCES.contains(&next_char) { + continue; + } + + // Compute the location of the escape sequence by offsetting the location of the + // string token by the characters we've seen thus far. + let col = if row_offset == 0 { + start.column() + prefix.len() + quote.len() + col_offset + } else { + col_offset + }; + let location = Location::new(start.row() + row_offset, col); + let end_location = Location::new(location.row(), location.column() + 2); + let mut diagnostic = Diagnostic::new( + violations::InvalidEscapeSequence(next_char), + Range::new(location, end_location), + ); + if autofix { + diagnostic.amend(Fix::insertion(r"\".to_string(), location)); + } + diagnostics.push(diagnostic); + } + } + } + + diagnostics +} diff --git a/src/pydocstyle/mod.rs b/src/pydocstyle/mod.rs index f767aa7b39..ea5f61888e 100644 --- a/src/pydocstyle/mod.rs +++ b/src/pydocstyle/mod.rs @@ -1,5 +1,5 @@ pub mod helpers; -pub mod plugins; +pub mod rules; pub mod settings; #[cfg(test)] @@ -63,7 +63,7 @@ mod tests { #[test_case(RuleCode::D418, Path::new("D.py"); "D418")] #[test_case(RuleCode::D419, Path::new("D.py"); "D419")] #[test_case(RuleCode::D104, Path::new("D104/__init__.py"); "D104_1")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pydocstyle") diff --git a/src/pydocstyle/plugins.rs b/src/pydocstyle/rules.rs similarity index 100% rename from src/pydocstyle/plugins.rs rename to src/pydocstyle/rules.rs diff --git a/src/pyflakes/mod.rs b/src/pyflakes/mod.rs index bdea8c95ed..df80206cd9 100644 --- a/src/pyflakes/mod.rs +++ b/src/pyflakes/mod.rs @@ -1,8 +1,7 @@ pub mod cformat; -pub mod checks; pub mod fixes; pub mod format; -pub mod plugins; +pub mod rules; #[cfg(test)] mod tests { @@ -106,7 +105,7 @@ mod tests { #[test_case(RuleCode::F841, Path::new("F841_3.py"); "F841_3")] #[test_case(RuleCode::F842, Path::new("F842.py"); "F842")] #[test_case(RuleCode::F901, Path::new("F901.py"); "F901")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pyflakes") diff --git a/src/pyflakes/plugins/assert_tuple.rs b/src/pyflakes/plugins/assert_tuple.rs deleted file mode 100644 index 3c3fc18cfa..0000000000 --- a/src/pyflakes/plugins/assert_tuple.rs +++ /dev/null @@ -1,12 +0,0 @@ -use rustpython_ast::{Expr, Stmt}; - -use crate::ast::types::Range; -use crate::checkers::ast::Checker; -use crate::pyflakes::checks; - -/// F631 -pub fn assert_tuple(checker: &mut Checker, stmt: &Stmt, test: &Expr) { - if let Some(diagnostic) = checks::assert_tuple(test, Range::from_located(stmt)) { - checker.diagnostics.push(diagnostic); - } -} diff --git a/src/pyflakes/plugins/if_tuple.rs b/src/pyflakes/plugins/if_tuple.rs deleted file mode 100644 index 278a0d8cc0..0000000000 --- a/src/pyflakes/plugins/if_tuple.rs +++ /dev/null @@ -1,12 +0,0 @@ -use rustpython_ast::{Expr, Stmt}; - -use crate::ast::types::Range; -use crate::checkers::ast::Checker; -use crate::pyflakes::checks; - -/// F634 -pub fn if_tuple(checker: &mut Checker, stmt: &Stmt, test: &Expr) { - if let Some(diagnostic) = checks::if_tuple(test, Range::from_located(stmt)) { - checker.diagnostics.push(diagnostic); - } -} diff --git a/src/pyflakes/plugins/mod.rs b/src/pyflakes/plugins/mod.rs deleted file mode 100644 index 993765daef..0000000000 --- a/src/pyflakes/plugins/mod.rs +++ /dev/null @@ -1,28 +0,0 @@ -pub use assert_tuple::assert_tuple; -pub use f_string_missing_placeholders::f_string_missing_placeholders; -pub use if_tuple::if_tuple; -pub use invalid_literal_comparisons::invalid_literal_comparison; -pub use invalid_print_syntax::invalid_print_syntax; -pub use raise_not_implemented::raise_not_implemented; -pub use repeated_keys::repeated_keys; -pub(crate) use strings::{ - percent_format_expected_mapping, percent_format_expected_sequence, - percent_format_extra_named_arguments, percent_format_missing_arguments, - percent_format_mixed_positional_and_named, percent_format_positional_count_mismatch, - percent_format_star_requires_sequence, string_dot_format_extra_named_arguments, - string_dot_format_extra_positional_arguments, string_dot_format_missing_argument, - string_dot_format_mixing_automatic, -}; -pub use unused_annotation::unused_annotation; -pub use unused_variable::unused_variable; - -mod assert_tuple; -mod f_string_missing_placeholders; -mod if_tuple; -mod invalid_literal_comparisons; -mod invalid_print_syntax; -mod raise_not_implemented; -mod repeated_keys; -mod strings; -mod unused_annotation; -mod unused_variable; diff --git a/src/pyflakes/rules/assert_tuple.rs b/src/pyflakes/rules/assert_tuple.rs new file mode 100644 index 0000000000..4cea240e0b --- /dev/null +++ b/src/pyflakes/rules/assert_tuple.rs @@ -0,0 +1,18 @@ +use rustpython_ast::{Expr, ExprKind, Stmt}; + +use crate::ast::types::Range; +use crate::checkers::ast::Checker; +use crate::registry::Diagnostic; +use crate::violations; + +/// F631 +pub fn assert_tuple(checker: &mut Checker, stmt: &Stmt, test: &Expr) { + if let ExprKind::Tuple { elts, .. } = &test.node { + if !elts.is_empty() { + checker.diagnostics.push(Diagnostic::new( + violations::AssertTuple, + Range::from_located(stmt), + )); + } + } +} diff --git a/src/pyflakes/plugins/f_string_missing_placeholders.rs b/src/pyflakes/rules/f_string_missing_placeholders.rs similarity index 100% rename from src/pyflakes/plugins/f_string_missing_placeholders.rs rename to src/pyflakes/rules/f_string_missing_placeholders.rs diff --git a/src/pyflakes/rules/if_tuple.rs b/src/pyflakes/rules/if_tuple.rs new file mode 100644 index 0000000000..8a1c456585 --- /dev/null +++ b/src/pyflakes/rules/if_tuple.rs @@ -0,0 +1,18 @@ +use rustpython_ast::{Expr, ExprKind, Stmt}; + +use crate::ast::types::Range; +use crate::checkers::ast::Checker; +use crate::registry::Diagnostic; +use crate::violations; + +/// F634 +pub fn if_tuple(checker: &mut Checker, stmt: &Stmt, test: &Expr) { + if let ExprKind::Tuple { elts, .. } = &test.node { + if !elts.is_empty() { + checker.diagnostics.push(Diagnostic::new( + violations::IfTuple, + Range::from_located(stmt), + )); + } + } +} diff --git a/src/pyflakes/plugins/invalid_literal_comparisons.rs b/src/pyflakes/rules/invalid_literal_comparisons.rs similarity index 100% rename from src/pyflakes/plugins/invalid_literal_comparisons.rs rename to src/pyflakes/rules/invalid_literal_comparisons.rs diff --git a/src/pyflakes/plugins/invalid_print_syntax.rs b/src/pyflakes/rules/invalid_print_syntax.rs similarity index 100% rename from src/pyflakes/plugins/invalid_print_syntax.rs rename to src/pyflakes/rules/invalid_print_syntax.rs diff --git a/src/pyflakes/checks.rs b/src/pyflakes/rules/mod.rs similarity index 80% rename from src/pyflakes/checks.rs rename to src/pyflakes/rules/mod.rs index ff62215414..37d8493492 100644 --- a/src/pyflakes/checks.rs +++ b/src/pyflakes/rules/mod.rs @@ -1,3 +1,32 @@ +pub use assert_tuple::assert_tuple; +pub use f_string_missing_placeholders::f_string_missing_placeholders; +pub use if_tuple::if_tuple; +pub use invalid_literal_comparisons::invalid_literal_comparison; +pub use invalid_print_syntax::invalid_print_syntax; +pub use raise_not_implemented::raise_not_implemented; +pub use repeated_keys::repeated_keys; +pub(crate) use strings::{ + percent_format_expected_mapping, percent_format_expected_sequence, + percent_format_extra_named_arguments, percent_format_missing_arguments, + percent_format_mixed_positional_and_named, percent_format_positional_count_mismatch, + percent_format_star_requires_sequence, string_dot_format_extra_named_arguments, + string_dot_format_extra_positional_arguments, string_dot_format_missing_argument, + string_dot_format_mixing_automatic, +}; +pub use unused_annotation::unused_annotation; +pub use unused_variable::unused_variable; + +mod assert_tuple; +mod f_string_missing_placeholders; +mod if_tuple; +mod invalid_literal_comparisons; +mod invalid_print_syntax; +mod raise_not_implemented; +mod repeated_keys; +mod strings; +mod unused_annotation; +mod unused_variable; + use std::string::ToString; use rustpython_parser::ast::{Excepthandler, ExcepthandlerKind, Expr, ExprKind, Stmt, StmtKind}; @@ -8,26 +37,6 @@ use crate::registry::Diagnostic; use crate::source_code_locator::SourceCodeLocator; use crate::violations; -/// F631 -pub fn assert_tuple(test: &Expr, location: Range) -> Option { - if let ExprKind::Tuple { elts, .. } = &test.node { - if !elts.is_empty() { - return Some(Diagnostic::new(violations::AssertTuple, location)); - } - } - None -} - -/// F634 -pub fn if_tuple(test: &Expr, location: Range) -> Option { - if let ExprKind::Tuple { elts, .. } = &test.node { - if !elts.is_empty() { - return Some(Diagnostic::new(violations::IfTuple, location)); - } - } - None -} - /// F821 pub fn undefined_local(name: &str, scopes: &[&Scope], bindings: &[Binding]) -> Option { let current = &scopes.last().expect("No current scope found"); diff --git a/src/pyflakes/plugins/raise_not_implemented.rs b/src/pyflakes/rules/raise_not_implemented.rs similarity index 100% rename from src/pyflakes/plugins/raise_not_implemented.rs rename to src/pyflakes/rules/raise_not_implemented.rs diff --git a/src/pyflakes/plugins/repeated_keys.rs b/src/pyflakes/rules/repeated_keys.rs similarity index 100% rename from src/pyflakes/plugins/repeated_keys.rs rename to src/pyflakes/rules/repeated_keys.rs diff --git a/src/pyflakes/plugins/strings.rs b/src/pyflakes/rules/strings.rs similarity index 100% rename from src/pyflakes/plugins/strings.rs rename to src/pyflakes/rules/strings.rs diff --git a/src/pyflakes/plugins/unused_annotation.rs b/src/pyflakes/rules/unused_annotation.rs similarity index 100% rename from src/pyflakes/plugins/unused_annotation.rs rename to src/pyflakes/rules/unused_annotation.rs diff --git a/src/pyflakes/plugins/unused_variable.rs b/src/pyflakes/rules/unused_variable.rs similarity index 100% rename from src/pyflakes/plugins/unused_variable.rs rename to src/pyflakes/rules/unused_variable.rs diff --git a/src/pygrep_hooks/mod.rs b/src/pygrep_hooks/mod.rs index 2ff8aa73b3..82f5427fb2 100644 --- a/src/pygrep_hooks/mod.rs +++ b/src/pygrep_hooks/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; #[cfg(test)] mod tests { @@ -18,7 +18,7 @@ mod tests { #[test_case(RuleCode::PGH002, Path::new("PGH002_1.py"); "PGH002_1")] #[test_case(RuleCode::PGH003, Path::new("PGH003_0.py"); "PGH003_0")] #[test_case(RuleCode::PGH004, Path::new("PGH004_0.py"); "PGH004_0")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pygrep-hooks") diff --git a/src/pygrep_hooks/plugins/blanket_noqa.rs b/src/pygrep_hooks/rules/blanket_noqa.rs similarity index 100% rename from src/pygrep_hooks/plugins/blanket_noqa.rs rename to src/pygrep_hooks/rules/blanket_noqa.rs diff --git a/src/pygrep_hooks/plugins/blanket_type_ignore.rs b/src/pygrep_hooks/rules/blanket_type_ignore.rs similarity index 100% rename from src/pygrep_hooks/plugins/blanket_type_ignore.rs rename to src/pygrep_hooks/rules/blanket_type_ignore.rs diff --git a/src/pygrep_hooks/plugins/deprecated_log_warn.rs b/src/pygrep_hooks/rules/deprecated_log_warn.rs similarity index 100% rename from src/pygrep_hooks/plugins/deprecated_log_warn.rs rename to src/pygrep_hooks/rules/deprecated_log_warn.rs diff --git a/src/pygrep_hooks/plugins/mod.rs b/src/pygrep_hooks/rules/mod.rs similarity index 100% rename from src/pygrep_hooks/plugins/mod.rs rename to src/pygrep_hooks/rules/mod.rs diff --git a/src/pygrep_hooks/plugins/no_eval.rs b/src/pygrep_hooks/rules/no_eval.rs similarity index 100% rename from src/pygrep_hooks/plugins/no_eval.rs rename to src/pygrep_hooks/rules/no_eval.rs diff --git a/src/pylint/mod.rs b/src/pylint/mod.rs index c56294ff58..82ac3e238b 100644 --- a/src/pylint/mod.rs +++ b/src/pylint/mod.rs @@ -1,4 +1,4 @@ -pub mod plugins; +pub mod rules; #[cfg(test)] mod tests { @@ -29,7 +29,7 @@ mod tests { #[test_case(RuleCode::PLR1722, Path::new("consider_using_sys_exit_6.py"); "PLR1722_6")] #[test_case(RuleCode::PLW0120, Path::new("useless_else_on_loop.py"); "PLW0120")] #[test_case(RuleCode::PLW0602, Path::new("global_variable_not_assigned.py"); "PLW0602")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pylint") diff --git a/src/pylint/plugins/await_outside_async.rs b/src/pylint/rules/await_outside_async.rs similarity index 100% rename from src/pylint/plugins/await_outside_async.rs rename to src/pylint/rules/await_outside_async.rs diff --git a/src/pylint/plugins/merge_isinstance.rs b/src/pylint/rules/merge_isinstance.rs similarity index 100% rename from src/pylint/plugins/merge_isinstance.rs rename to src/pylint/rules/merge_isinstance.rs diff --git a/src/pylint/plugins/misplaced_comparison_constant.rs b/src/pylint/rules/misplaced_comparison_constant.rs similarity index 100% rename from src/pylint/plugins/misplaced_comparison_constant.rs rename to src/pylint/rules/misplaced_comparison_constant.rs diff --git a/src/pylint/plugins/mod.rs b/src/pylint/rules/mod.rs similarity index 100% rename from src/pylint/plugins/mod.rs rename to src/pylint/rules/mod.rs diff --git a/src/pylint/plugins/property_with_parameters.rs b/src/pylint/rules/property_with_parameters.rs similarity index 100% rename from src/pylint/plugins/property_with_parameters.rs rename to src/pylint/rules/property_with_parameters.rs diff --git a/src/pylint/plugins/unnecessary_direct_lambda_call.rs b/src/pylint/rules/unnecessary_direct_lambda_call.rs similarity index 100% rename from src/pylint/plugins/unnecessary_direct_lambda_call.rs rename to src/pylint/rules/unnecessary_direct_lambda_call.rs diff --git a/src/pylint/plugins/use_from_import.rs b/src/pylint/rules/use_from_import.rs similarity index 100% rename from src/pylint/plugins/use_from_import.rs rename to src/pylint/rules/use_from_import.rs diff --git a/src/pylint/plugins/use_sys_exit.rs b/src/pylint/rules/use_sys_exit.rs similarity index 100% rename from src/pylint/plugins/use_sys_exit.rs rename to src/pylint/rules/use_sys_exit.rs diff --git a/src/pylint/plugins/used_prior_global_declaration.rs b/src/pylint/rules/used_prior_global_declaration.rs similarity index 100% rename from src/pylint/plugins/used_prior_global_declaration.rs rename to src/pylint/rules/used_prior_global_declaration.rs diff --git a/src/pylint/plugins/useless_else_on_loop.rs b/src/pylint/rules/useless_else_on_loop.rs similarity index 100% rename from src/pylint/plugins/useless_else_on_loop.rs rename to src/pylint/rules/useless_else_on_loop.rs diff --git a/src/pylint/plugins/useless_import_alias.rs b/src/pylint/rules/useless_import_alias.rs similarity index 100% rename from src/pylint/plugins/useless_import_alias.rs rename to src/pylint/rules/useless_import_alias.rs diff --git a/src/pyupgrade/checks.rs b/src/pyupgrade/checks.rs deleted file mode 100644 index 27b6df43c5..0000000000 --- a/src/pyupgrade/checks.rs +++ /dev/null @@ -1,255 +0,0 @@ -use once_cell::sync::Lazy; -use regex::Regex; -use rustc_hash::{FxHashMap, FxHashSet}; -use rustpython_ast::{Constant, KeywordData, Location}; -use rustpython_parser::ast::{ArgData, Expr, ExprKind, Stmt, StmtKind}; - -use crate::ast::helpers::{self}; -use crate::ast::types::{Binding, BindingKind, Range, Scope, ScopeKind}; -use crate::autofix::Fix; -use crate::pyupgrade::types::Primitive; -use crate::registry::Diagnostic; -use crate::settings::types::PythonVersion; -use crate::violations; - -/// UP001 -pub fn useless_metaclass_type( - targets: &[Expr], - value: &Expr, - location: Range, -) -> Option { - if targets.len() != 1 { - return None; - } - let ExprKind::Name { id, .. } = targets.first().map(|expr| &expr.node).unwrap() else { - return None; - }; - if id != "__metaclass__" { - return None; - } - let ExprKind::Name { id, .. } = &value.node else { - return None; - }; - if id != "type" { - return None; - } - Some(Diagnostic::new(violations::UselessMetaclassType, location)) -} - -/// UP003 -pub fn type_of_primitive(func: &Expr, args: &[Expr], location: Range) -> Option { - // Validate the arguments. - if args.len() != 1 { - return None; - } - - let (ExprKind::Attribute { attr: id, .. } | ExprKind::Name { id, .. }) = &func.node else { - return None; - }; - if id != "type" { - return None; - } - - let ExprKind::Constant { value, .. } = &args[0].node else { - return None; - }; - - let primitive = Primitive::from_constant(value)?; - Some(Diagnostic::new( - violations::TypeOfPrimitive(primitive), - location, - )) -} - -/// UP004 -pub fn useless_object_inheritance( - name: &str, - bases: &[Expr], - scope: &Scope, - bindings: &[Binding], -) -> Option { - for expr in bases { - let ExprKind::Name { id, .. } = &expr.node else { - continue; - }; - if id != "object" { - continue; - } - if !matches!( - scope - .values - .get(&id.as_str()) - .map(|index| &bindings[*index]), - None | Some(Binding { - kind: BindingKind::Builtin, - .. - }) - ) { - continue; - } - return Some(Diagnostic::new( - violations::UselessObjectInheritance(name.to_string()), - Range::from_located(expr), - )); - } - - None -} - -/// UP008 -pub fn super_args( - scope: &Scope, - parents: &[&Stmt], - expr: &Expr, - func: &Expr, - args: &[Expr], -) -> Option { - if !helpers::is_super_call_with_arguments(func, args) { - return None; - } - - // Check: are we in a Function scope? - if !matches!(scope.kind, ScopeKind::Function { .. }) { - return None; - } - - let mut parents = parents.iter().rev(); - - // For a `super` invocation to be unnecessary, the first argument needs to match - // the enclosing class, and the second argument needs to match the first - // argument to the enclosing function. - let [first_arg, second_arg] = args else { - return None; - }; - - // Find the enclosing function definition (if any). - let Some(StmtKind::FunctionDef { - args: parent_args, .. - }) = parents - .find(|stmt| matches!(stmt.node, StmtKind::FunctionDef { .. })) - .map(|stmt| &stmt.node) else { - return None; - }; - - // Extract the name of the first argument to the enclosing function. - let Some(ArgData { - arg: parent_arg, .. - }) = parent_args.args.first().map(|expr| &expr.node) else { - return None; - }; - - // Find the enclosing class definition (if any). - let Some(StmtKind::ClassDef { - name: parent_name, .. - }) = parents - .find(|stmt| matches!(stmt.node, StmtKind::ClassDef { .. })) - .map(|stmt| &stmt.node) else { - return None; - }; - - let ( - ExprKind::Name { - id: first_arg_id, .. - }, - ExprKind::Name { - id: second_arg_id, .. - }, - ) = (&first_arg.node, &second_arg.node) else { - return None; - }; - - if first_arg_id == parent_name && second_arg_id == parent_arg { - return Some(Diagnostic::new( - violations::SuperCallWithParameters, - Range::from_located(expr), - )); - } - - None -} - -// Regex from PEP263. -static CODING_COMMENT_REGEX: Lazy = - Lazy::new(|| Regex::new(r"^[ \t\f]*#.*?coding[:=][ \t]*utf-?8").unwrap()); - -/// UP009 -pub fn unnecessary_coding_comment(lineno: usize, line: &str, autofix: bool) -> Option { - // PEP3120 makes utf-8 the default encoding. - if CODING_COMMENT_REGEX.is_match(line) { - let mut diagnostic = Diagnostic::new( - violations::PEP3120UnnecessaryCodingComment, - Range::new(Location::new(lineno + 1, 0), Location::new(lineno + 2, 0)), - ); - if autofix { - diagnostic.amend(Fix::deletion( - Location::new(lineno + 1, 0), - Location::new(lineno + 2, 0), - )); - } - Some(diagnostic) - } else { - None - } -} - -/// UP011 -pub fn unnecessary_lru_cache_params( - decorator_list: &[Expr], - target_version: PythonVersion, - from_imports: &FxHashMap<&str, FxHashSet<&str>>, - import_aliases: &FxHashMap<&str, &str>, -) -> Option { - for expr in decorator_list.iter() { - let ExprKind::Call { - func, - args, - keywords, - } = &expr.node - else { - continue; - }; - - if !(args.is_empty() - && helpers::match_module_member( - func, - "functools", - "lru_cache", - from_imports, - import_aliases, - )) - { - continue; - } - - let range = Range::new(func.end_location.unwrap(), expr.end_location.unwrap()); - // Ex) `functools.lru_cache()` - if keywords.is_empty() { - return Some(Diagnostic::new( - violations::UnnecessaryLRUCacheParams, - range, - )); - } - // Ex) `functools.lru_cache(maxsize=None)` - if !(target_version >= PythonVersion::Py39 && keywords.len() == 1) { - continue; - } - - let KeywordData { arg, value } = &keywords[0].node; - if !(arg.as_ref().map(|arg| arg == "maxsize").unwrap_or_default() - && matches!( - value.node, - ExprKind::Constant { - value: Constant::None, - kind: None, - } - )) - { - continue; - } - return Some(Diagnostic::new( - violations::UnnecessaryLRUCacheParams, - range, - )); - } - None -} diff --git a/src/pyupgrade/mod.rs b/src/pyupgrade/mod.rs index 43205d8b6e..bc844d5fba 100644 --- a/src/pyupgrade/mod.rs +++ b/src/pyupgrade/mod.rs @@ -1,6 +1,5 @@ -pub mod checks; pub mod fixes; -pub mod plugins; +pub mod rules; pub mod settings; pub mod types; @@ -51,7 +50,7 @@ mod tests { #[test_case(RuleCode::UP028, Path::new("UP028_0.py"); "UP028_0")] #[test_case(RuleCode::UP028, Path::new("UP028_1.py"); "UP028_1")] #[test_case(RuleCode::UP029, Path::new("UP029.py"); "UP029")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/pyupgrade") diff --git a/src/pyupgrade/plugins/mod.rs b/src/pyupgrade/plugins/mod.rs deleted file mode 100644 index 50e20ef54e..0000000000 --- a/src/pyupgrade/plugins/mod.rs +++ /dev/null @@ -1,55 +0,0 @@ -pub use convert_named_tuple_functional_to_class::convert_named_tuple_functional_to_class; -pub use convert_typed_dict_functional_to_class::convert_typed_dict_functional_to_class; -pub use datetime_utc_alias::datetime_utc_alias; -pub use deprecated_unittest_alias::deprecated_unittest_alias; -pub use native_literals::native_literals; -pub use open_alias::open_alias; -pub use os_error_alias::os_error_alias; -pub use redundant_open_modes::redundant_open_modes; -pub use remove_six_compat::remove_six_compat; -pub use replace_stdout_stderr::replace_stdout_stderr; -pub use replace_universal_newlines::replace_universal_newlines; -pub use rewrite_c_element_tree::replace_c_element_tree; -pub use rewrite_mock_import::{rewrite_mock_attribute, rewrite_mock_import}; -pub use rewrite_unicode_literal::rewrite_unicode_literal; -pub use rewrite_yield_from::rewrite_yield_from; -pub use super_call_with_parameters::super_call_with_parameters; -pub use type_of_primitive::type_of_primitive; -pub use typing_text_str_alias::typing_text_str_alias; -pub use unnecessary_builtin_import::unnecessary_builtin_import; -pub use unnecessary_encode_utf8::unnecessary_encode_utf8; -pub use unnecessary_future_import::unnecessary_future_import; -pub use unnecessary_lru_cache_params::unnecessary_lru_cache_params; -pub use unpack_list_comprehension::unpack_list_comprehension; -pub use use_pep585_annotation::use_pep585_annotation; -pub use use_pep604_annotation::use_pep604_annotation; -pub use useless_metaclass_type::useless_metaclass_type; -pub use useless_object_inheritance::useless_object_inheritance; - -mod convert_named_tuple_functional_to_class; -mod convert_typed_dict_functional_to_class; -mod datetime_utc_alias; -mod deprecated_unittest_alias; -mod native_literals; -mod open_alias; -mod os_error_alias; -mod redundant_open_modes; -mod remove_six_compat; -mod replace_stdout_stderr; -mod replace_universal_newlines; -mod rewrite_c_element_tree; -mod rewrite_mock_import; -mod rewrite_unicode_literal; -mod rewrite_yield_from; -mod super_call_with_parameters; -mod type_of_primitive; -mod typing_text_str_alias; -mod unnecessary_builtin_import; -mod unnecessary_encode_utf8; -mod unnecessary_future_import; -mod unnecessary_lru_cache_params; -mod unpack_list_comprehension; -mod use_pep585_annotation; -mod use_pep604_annotation; -mod useless_metaclass_type; -mod useless_object_inheritance; diff --git a/src/pyupgrade/plugins/type_of_primitive.rs b/src/pyupgrade/plugins/type_of_primitive.rs deleted file mode 100644 index 99eb8ff6be..0000000000 --- a/src/pyupgrade/plugins/type_of_primitive.rs +++ /dev/null @@ -1,27 +0,0 @@ -use rustpython_ast::Expr; - -use crate::ast::types::Range; -use crate::autofix::Fix; -use crate::checkers::ast::Checker; -use crate::pyupgrade::checks; -use crate::registry::DiagnosticKind; -use crate::violations; - -/// UP003 -pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) { - let Some(mut diagnostic) = checks::type_of_primitive(func, args, Range::from_located(expr)) else { - return; - }; - if checker.patch(diagnostic.kind.code()) { - if let DiagnosticKind::TypeOfPrimitive(violations::TypeOfPrimitive(primitive)) = - &diagnostic.kind - { - diagnostic.amend(Fix::replacement( - primitive.builtin(), - expr.location, - expr.end_location.unwrap(), - )); - } - } - checker.diagnostics.push(diagnostic); -} diff --git a/src/pyupgrade/plugins/unnecessary_lru_cache_params.rs b/src/pyupgrade/plugins/unnecessary_lru_cache_params.rs deleted file mode 100644 index f0d8bfbc0c..0000000000 --- a/src/pyupgrade/plugins/unnecessary_lru_cache_params.rs +++ /dev/null @@ -1,21 +0,0 @@ -use rustpython_parser::ast::Expr; - -use crate::autofix::Fix; -use crate::checkers::ast::Checker; -use crate::pyupgrade::checks; - -/// UP011 -pub fn unnecessary_lru_cache_params(checker: &mut Checker, decorator_list: &[Expr]) { - let Some(mut diagnostic) = checks::unnecessary_lru_cache_params( - decorator_list, - checker.settings.target_version, - &checker.from_imports, - &checker.import_aliases, - ) else { - return; - }; - if checker.patch(diagnostic.kind.code()) { - diagnostic.amend(Fix::deletion(diagnostic.location, diagnostic.end_location)); - } - checker.diagnostics.push(diagnostic); -} diff --git a/src/pyupgrade/plugins/useless_object_inheritance.rs b/src/pyupgrade/plugins/useless_object_inheritance.rs deleted file mode 100644 index 339991061c..0000000000 --- a/src/pyupgrade/plugins/useless_object_inheritance.rs +++ /dev/null @@ -1,30 +0,0 @@ -use rustpython_ast::{Expr, Keyword, Stmt}; - -use crate::checkers::ast::Checker; -use crate::pyupgrade; -use crate::pyupgrade::checks; - -/// UP004 -pub fn useless_object_inheritance( - checker: &mut Checker, - stmt: &Stmt, - name: &str, - bases: &[Expr], - keywords: &[Keyword], -) { - let Some(mut diagnostic) = checks::useless_object_inheritance(name, bases, checker.current_scope(), &checker.bindings) else { - return; - }; - if checker.patch(diagnostic.kind.code()) { - if let Some(fix) = pyupgrade::fixes::remove_class_def_base( - checker.locator, - stmt.location, - diagnostic.location, - bases, - keywords, - ) { - diagnostic.amend(fix); - } - } - checker.diagnostics.push(diagnostic); -} diff --git a/src/pyupgrade/plugins/convert_named_tuple_functional_to_class.rs b/src/pyupgrade/rules/convert_named_tuple_functional_to_class.rs similarity index 100% rename from src/pyupgrade/plugins/convert_named_tuple_functional_to_class.rs rename to src/pyupgrade/rules/convert_named_tuple_functional_to_class.rs diff --git a/src/pyupgrade/plugins/convert_typed_dict_functional_to_class.rs b/src/pyupgrade/rules/convert_typed_dict_functional_to_class.rs similarity index 100% rename from src/pyupgrade/plugins/convert_typed_dict_functional_to_class.rs rename to src/pyupgrade/rules/convert_typed_dict_functional_to_class.rs diff --git a/src/pyupgrade/plugins/datetime_utc_alias.rs b/src/pyupgrade/rules/datetime_utc_alias.rs similarity index 100% rename from src/pyupgrade/plugins/datetime_utc_alias.rs rename to src/pyupgrade/rules/datetime_utc_alias.rs diff --git a/src/pyupgrade/plugins/deprecated_unittest_alias.rs b/src/pyupgrade/rules/deprecated_unittest_alias.rs similarity index 100% rename from src/pyupgrade/plugins/deprecated_unittest_alias.rs rename to src/pyupgrade/rules/deprecated_unittest_alias.rs diff --git a/src/pyupgrade/rules/mod.rs b/src/pyupgrade/rules/mod.rs new file mode 100644 index 0000000000..b75550c906 --- /dev/null +++ b/src/pyupgrade/rules/mod.rs @@ -0,0 +1,161 @@ +pub use convert_named_tuple_functional_to_class::convert_named_tuple_functional_to_class; +pub use convert_typed_dict_functional_to_class::convert_typed_dict_functional_to_class; +pub use datetime_utc_alias::datetime_utc_alias; +pub use deprecated_unittest_alias::deprecated_unittest_alias; +pub use native_literals::native_literals; +use once_cell::sync::Lazy; +pub use open_alias::open_alias; +pub use os_error_alias::os_error_alias; +pub use redundant_open_modes::redundant_open_modes; +use regex::Regex; +pub use remove_six_compat::remove_six_compat; +pub use replace_stdout_stderr::replace_stdout_stderr; +pub use replace_universal_newlines::replace_universal_newlines; +pub use rewrite_c_element_tree::replace_c_element_tree; +pub use rewrite_mock_import::{rewrite_mock_attribute, rewrite_mock_import}; +pub use rewrite_unicode_literal::rewrite_unicode_literal; +pub use rewrite_yield_from::rewrite_yield_from; +use rustpython_ast::Location; +use rustpython_parser::ast::{ArgData, Expr, ExprKind, Stmt, StmtKind}; +pub use super_call_with_parameters::super_call_with_parameters; +pub use type_of_primitive::type_of_primitive; +pub use typing_text_str_alias::typing_text_str_alias; +pub use unnecessary_builtin_import::unnecessary_builtin_import; +pub use unnecessary_encode_utf8::unnecessary_encode_utf8; +pub use unnecessary_future_import::unnecessary_future_import; +pub use unnecessary_lru_cache_params::unnecessary_lru_cache_params; +pub use unpack_list_comprehension::unpack_list_comprehension; +pub use use_pep585_annotation::use_pep585_annotation; +pub use use_pep604_annotation::use_pep604_annotation; +pub use useless_metaclass_type::useless_metaclass_type; +pub use useless_object_inheritance::useless_object_inheritance; + +use crate::ast::helpers::{self}; +use crate::ast::types::{Range, Scope, ScopeKind}; +use crate::autofix::Fix; +use crate::registry::Diagnostic; +use crate::violations; + +mod convert_named_tuple_functional_to_class; +mod convert_typed_dict_functional_to_class; +mod datetime_utc_alias; +mod deprecated_unittest_alias; +mod native_literals; +mod open_alias; +mod os_error_alias; +mod redundant_open_modes; +mod remove_six_compat; +mod replace_stdout_stderr; +mod replace_universal_newlines; +mod rewrite_c_element_tree; +mod rewrite_mock_import; +mod rewrite_unicode_literal; +mod rewrite_yield_from; +mod super_call_with_parameters; +mod type_of_primitive; +mod typing_text_str_alias; +mod unnecessary_builtin_import; +mod unnecessary_encode_utf8; +mod unnecessary_future_import; +mod unnecessary_lru_cache_params; +mod unpack_list_comprehension; +mod use_pep585_annotation; +mod use_pep604_annotation; +mod useless_metaclass_type; +mod useless_object_inheritance; + +/// UP008 +pub fn super_args( + scope: &Scope, + parents: &[&Stmt], + expr: &Expr, + func: &Expr, + args: &[Expr], +) -> Option { + if !helpers::is_super_call_with_arguments(func, args) { + return None; + } + + // Check: are we in a Function scope? + if !matches!(scope.kind, ScopeKind::Function { .. }) { + return None; + } + + let mut parents = parents.iter().rev(); + + // For a `super` invocation to be unnecessary, the first argument needs to match + // the enclosing class, and the second argument needs to match the first + // argument to the enclosing function. + let [first_arg, second_arg] = args else { + return None; + }; + + // Find the enclosing function definition (if any). + let Some(StmtKind::FunctionDef { + args: parent_args, .. + }) = parents + .find(|stmt| matches!(stmt.node, StmtKind::FunctionDef { .. })) + .map(|stmt| &stmt.node) else { + return None; + }; + + // Extract the name of the first argument to the enclosing function. + let Some(ArgData { + arg: parent_arg, .. + }) = parent_args.args.first().map(|expr| &expr.node) else { + return None; + }; + + // Find the enclosing class definition (if any). + let Some(StmtKind::ClassDef { + name: parent_name, .. + }) = parents + .find(|stmt| matches!(stmt.node, StmtKind::ClassDef { .. })) + .map(|stmt| &stmt.node) else { + return None; + }; + + let ( + ExprKind::Name { + id: first_arg_id, .. + }, + ExprKind::Name { + id: second_arg_id, .. + }, + ) = (&first_arg.node, &second_arg.node) else { + return None; + }; + + if first_arg_id == parent_name && second_arg_id == parent_arg { + return Some(Diagnostic::new( + violations::SuperCallWithParameters, + Range::from_located(expr), + )); + } + + None +} + +// Regex from PEP263. +static CODING_COMMENT_REGEX: Lazy = + Lazy::new(|| Regex::new(r"^[ \t\f]*#.*?coding[:=][ \t]*utf-?8").unwrap()); + +/// UP009 +pub fn unnecessary_coding_comment(lineno: usize, line: &str, autofix: bool) -> Option { + // PEP3120 makes utf-8 the default encoding. + if CODING_COMMENT_REGEX.is_match(line) { + let mut diagnostic = Diagnostic::new( + violations::PEP3120UnnecessaryCodingComment, + Range::new(Location::new(lineno + 1, 0), Location::new(lineno + 2, 0)), + ); + if autofix { + diagnostic.amend(Fix::deletion( + Location::new(lineno + 1, 0), + Location::new(lineno + 2, 0), + )); + } + Some(diagnostic) + } else { + None + } +} diff --git a/src/pyupgrade/plugins/native_literals.rs b/src/pyupgrade/rules/native_literals.rs similarity index 100% rename from src/pyupgrade/plugins/native_literals.rs rename to src/pyupgrade/rules/native_literals.rs diff --git a/src/pyupgrade/plugins/open_alias.rs b/src/pyupgrade/rules/open_alias.rs similarity index 100% rename from src/pyupgrade/plugins/open_alias.rs rename to src/pyupgrade/rules/open_alias.rs diff --git a/src/pyupgrade/plugins/os_error_alias.rs b/src/pyupgrade/rules/os_error_alias.rs similarity index 100% rename from src/pyupgrade/plugins/os_error_alias.rs rename to src/pyupgrade/rules/os_error_alias.rs diff --git a/src/pyupgrade/plugins/redundant_open_modes.rs b/src/pyupgrade/rules/redundant_open_modes.rs similarity index 100% rename from src/pyupgrade/plugins/redundant_open_modes.rs rename to src/pyupgrade/rules/redundant_open_modes.rs diff --git a/src/pyupgrade/plugins/remove_six_compat.rs b/src/pyupgrade/rules/remove_six_compat.rs similarity index 100% rename from src/pyupgrade/plugins/remove_six_compat.rs rename to src/pyupgrade/rules/remove_six_compat.rs diff --git a/src/pyupgrade/plugins/replace_stdout_stderr.rs b/src/pyupgrade/rules/replace_stdout_stderr.rs similarity index 100% rename from src/pyupgrade/plugins/replace_stdout_stderr.rs rename to src/pyupgrade/rules/replace_stdout_stderr.rs diff --git a/src/pyupgrade/plugins/replace_universal_newlines.rs b/src/pyupgrade/rules/replace_universal_newlines.rs similarity index 100% rename from src/pyupgrade/plugins/replace_universal_newlines.rs rename to src/pyupgrade/rules/replace_universal_newlines.rs diff --git a/src/pyupgrade/plugins/rewrite_c_element_tree.rs b/src/pyupgrade/rules/rewrite_c_element_tree.rs similarity index 100% rename from src/pyupgrade/plugins/rewrite_c_element_tree.rs rename to src/pyupgrade/rules/rewrite_c_element_tree.rs diff --git a/src/pyupgrade/plugins/rewrite_mock_import.rs b/src/pyupgrade/rules/rewrite_mock_import.rs similarity index 100% rename from src/pyupgrade/plugins/rewrite_mock_import.rs rename to src/pyupgrade/rules/rewrite_mock_import.rs diff --git a/src/pyupgrade/plugins/rewrite_unicode_literal.rs b/src/pyupgrade/rules/rewrite_unicode_literal.rs similarity index 100% rename from src/pyupgrade/plugins/rewrite_unicode_literal.rs rename to src/pyupgrade/rules/rewrite_unicode_literal.rs diff --git a/src/pyupgrade/plugins/rewrite_yield_from.rs b/src/pyupgrade/rules/rewrite_yield_from.rs similarity index 100% rename from src/pyupgrade/plugins/rewrite_yield_from.rs rename to src/pyupgrade/rules/rewrite_yield_from.rs diff --git a/src/pyupgrade/plugins/super_call_with_parameters.rs b/src/pyupgrade/rules/super_call_with_parameters.rs similarity index 88% rename from src/pyupgrade/plugins/super_call_with_parameters.rs rename to src/pyupgrade/rules/super_call_with_parameters.rs index 0e0cee9a92..ea9792031f 100644 --- a/src/pyupgrade/plugins/super_call_with_parameters.rs +++ b/src/pyupgrade/rules/super_call_with_parameters.rs @@ -3,7 +3,7 @@ use rustpython_ast::{Expr, Stmt}; use crate::ast::helpers; use crate::checkers::ast::Checker; use crate::pyupgrade; -use crate::pyupgrade::checks; +use crate::pyupgrade::rules; /// UP008 pub fn super_call_with_parameters(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) { @@ -18,7 +18,7 @@ pub fn super_call_with_parameters(checker: &mut Checker, expr: &Expr, func: &Exp .iter() .map(std::convert::Into::into) .collect(); - let Some(mut diagnostic) = checks::super_args(scope, &parents, expr, func, args) else { + let Some(mut diagnostic) = rules::super_args(scope, &parents, expr, func, args) else { return; }; if checker.patch(diagnostic.kind.code()) { diff --git a/src/pyupgrade/rules/type_of_primitive.rs b/src/pyupgrade/rules/type_of_primitive.rs new file mode 100644 index 0000000000..1acfaa2643 --- /dev/null +++ b/src/pyupgrade/rules/type_of_primitive.rs @@ -0,0 +1,51 @@ +use rustpython_ast::{Expr, ExprKind}; + +use crate::ast::types::Range; +use crate::autofix::Fix; +use crate::checkers::ast::Checker; +use crate::pyupgrade::types::Primitive; +use crate::registry::{Diagnostic, DiagnosticKind}; +use crate::violations; + +fn rule(func: &Expr, args: &[Expr], location: Range) -> Option { + // Validate the arguments. + if args.len() != 1 { + return None; + } + + let (ExprKind::Attribute { attr: id, .. } | ExprKind::Name { id, .. }) = &func.node else { + return None; + }; + if id != "type" { + return None; + } + + let ExprKind::Constant { value, .. } = &args[0].node else { + return None; + }; + + let primitive = Primitive::from_constant(value)?; + Some(Diagnostic::new( + violations::TypeOfPrimitive(primitive), + location, + )) +} + +/// UP003 +pub fn type_of_primitive(checker: &mut Checker, expr: &Expr, func: &Expr, args: &[Expr]) { + let Some(mut diagnostic) = rule(func, args, Range::from_located(expr)) else { + return; + }; + if checker.patch(diagnostic.kind.code()) { + if let DiagnosticKind::TypeOfPrimitive(violations::TypeOfPrimitive(primitive)) = + &diagnostic.kind + { + diagnostic.amend(Fix::replacement( + primitive.builtin(), + expr.location, + expr.end_location.unwrap(), + )); + } + } + checker.diagnostics.push(diagnostic); +} diff --git a/src/pyupgrade/plugins/typing_text_str_alias.rs b/src/pyupgrade/rules/typing_text_str_alias.rs similarity index 100% rename from src/pyupgrade/plugins/typing_text_str_alias.rs rename to src/pyupgrade/rules/typing_text_str_alias.rs diff --git a/src/pyupgrade/plugins/unnecessary_builtin_import.rs b/src/pyupgrade/rules/unnecessary_builtin_import.rs similarity index 100% rename from src/pyupgrade/plugins/unnecessary_builtin_import.rs rename to src/pyupgrade/rules/unnecessary_builtin_import.rs diff --git a/src/pyupgrade/plugins/unnecessary_encode_utf8.rs b/src/pyupgrade/rules/unnecessary_encode_utf8.rs similarity index 100% rename from src/pyupgrade/plugins/unnecessary_encode_utf8.rs rename to src/pyupgrade/rules/unnecessary_encode_utf8.rs diff --git a/src/pyupgrade/plugins/unnecessary_future_import.rs b/src/pyupgrade/rules/unnecessary_future_import.rs similarity index 100% rename from src/pyupgrade/plugins/unnecessary_future_import.rs rename to src/pyupgrade/rules/unnecessary_future_import.rs diff --git a/src/pyupgrade/rules/unnecessary_lru_cache_params.rs b/src/pyupgrade/rules/unnecessary_lru_cache_params.rs new file mode 100644 index 0000000000..e97d13ad73 --- /dev/null +++ b/src/pyupgrade/rules/unnecessary_lru_cache_params.rs @@ -0,0 +1,88 @@ +use rustc_hash::{FxHashMap, FxHashSet}; +use rustpython_ast::{Constant, ExprKind, KeywordData}; +use rustpython_parser::ast::Expr; + +use crate::ast::helpers; +use crate::ast::types::Range; +use crate::autofix::Fix; +use crate::checkers::ast::Checker; +use crate::registry::Diagnostic; +use crate::settings::types::PythonVersion; +use crate::violations; + +fn rule( + decorator_list: &[Expr], + target_version: PythonVersion, + from_imports: &FxHashMap<&str, FxHashSet<&str>>, + import_aliases: &FxHashMap<&str, &str>, +) -> Option { + for expr in decorator_list.iter() { + let ExprKind::Call { + func, + args, + keywords, + } = &expr.node + else { + continue; + }; + + if !(args.is_empty() + && helpers::match_module_member( + func, + "functools", + "lru_cache", + from_imports, + import_aliases, + )) + { + continue; + } + + let range = Range::new(func.end_location.unwrap(), expr.end_location.unwrap()); + // Ex) `functools.lru_cache()` + if keywords.is_empty() { + return Some(Diagnostic::new( + violations::UnnecessaryLRUCacheParams, + range, + )); + } + // Ex) `functools.lru_cache(maxsize=None)` + if !(target_version >= PythonVersion::Py39 && keywords.len() == 1) { + continue; + } + + let KeywordData { arg, value } = &keywords[0].node; + if !(arg.as_ref().map(|arg| arg == "maxsize").unwrap_or_default() + && matches!( + value.node, + ExprKind::Constant { + value: Constant::None, + kind: None, + } + )) + { + continue; + } + return Some(Diagnostic::new( + violations::UnnecessaryLRUCacheParams, + range, + )); + } + None +} + +/// UP011 +pub fn unnecessary_lru_cache_params(checker: &mut Checker, decorator_list: &[Expr]) { + let Some(mut diagnostic) = rule( + decorator_list, + checker.settings.target_version, + &checker.from_imports, + &checker.import_aliases, + ) else { + return; + }; + if checker.patch(diagnostic.kind.code()) { + diagnostic.amend(Fix::deletion(diagnostic.location, diagnostic.end_location)); + } + checker.diagnostics.push(diagnostic); +} diff --git a/src/pyupgrade/plugins/unpack_list_comprehension.rs b/src/pyupgrade/rules/unpack_list_comprehension.rs similarity index 100% rename from src/pyupgrade/plugins/unpack_list_comprehension.rs rename to src/pyupgrade/rules/unpack_list_comprehension.rs diff --git a/src/pyupgrade/plugins/use_pep585_annotation.rs b/src/pyupgrade/rules/use_pep585_annotation.rs similarity index 100% rename from src/pyupgrade/plugins/use_pep585_annotation.rs rename to src/pyupgrade/rules/use_pep585_annotation.rs diff --git a/src/pyupgrade/plugins/use_pep604_annotation.rs b/src/pyupgrade/rules/use_pep604_annotation.rs similarity index 100% rename from src/pyupgrade/plugins/use_pep604_annotation.rs rename to src/pyupgrade/rules/use_pep604_annotation.rs diff --git a/src/pyupgrade/plugins/useless_metaclass_type.rs b/src/pyupgrade/rules/useless_metaclass_type.rs similarity index 62% rename from src/pyupgrade/plugins/useless_metaclass_type.rs rename to src/pyupgrade/rules/useless_metaclass_type.rs index cdc644ae28..cc15a4e0e6 100644 --- a/src/pyupgrade/plugins/useless_metaclass_type.rs +++ b/src/pyupgrade/rules/useless_metaclass_type.rs @@ -1,15 +1,35 @@ use log::error; -use rustpython_ast::{Expr, Stmt}; +use rustpython_ast::{Expr, ExprKind, Stmt}; use crate::ast::types::Range; use crate::autofix::helpers; use crate::checkers::ast::Checker; -use crate::pyupgrade::checks; +use crate::registry::Diagnostic; +use crate::violations; + +fn rule(targets: &[Expr], value: &Expr, location: Range) -> Option { + if targets.len() != 1 { + return None; + } + let ExprKind::Name { id, .. } = targets.first().map(|expr| &expr.node).unwrap() else { + return None; + }; + if id != "__metaclass__" { + return None; + } + let ExprKind::Name { id, .. } = &value.node else { + return None; + }; + if id != "type" { + return None; + } + Some(Diagnostic::new(violations::UselessMetaclassType, location)) +} /// UP001 pub fn useless_metaclass_type(checker: &mut Checker, stmt: &Stmt, value: &Expr, targets: &[Expr]) { let Some(mut diagnostic) = - checks::useless_metaclass_type(targets, value, Range::from_located(stmt)) else { + rule(targets, value, Range::from_located(stmt)) else { return; }; if checker.patch(diagnostic.kind.code()) { diff --git a/src/pyupgrade/rules/useless_object_inheritance.rs b/src/pyupgrade/rules/useless_object_inheritance.rs new file mode 100644 index 0000000000..0f85edd1c8 --- /dev/null +++ b/src/pyupgrade/rules/useless_object_inheritance.rs @@ -0,0 +1,60 @@ +use rustpython_ast::{Expr, ExprKind, Keyword, Stmt}; + +use crate::ast::types::{Binding, BindingKind, Range, Scope}; +use crate::checkers::ast::Checker; +use crate::registry::Diagnostic; +use crate::{pyupgrade, violations}; + +fn rule(name: &str, bases: &[Expr], scope: &Scope, bindings: &[Binding]) -> Option { + for expr in bases { + let ExprKind::Name { id, .. } = &expr.node else { + continue; + }; + if id != "object" { + continue; + } + if !matches!( + scope + .values + .get(&id.as_str()) + .map(|index| &bindings[*index]), + None | Some(Binding { + kind: BindingKind::Builtin, + .. + }) + ) { + continue; + } + return Some(Diagnostic::new( + violations::UselessObjectInheritance(name.to_string()), + Range::from_located(expr), + )); + } + + None +} + +/// UP004 +pub fn useless_object_inheritance( + checker: &mut Checker, + stmt: &Stmt, + name: &str, + bases: &[Expr], + keywords: &[Keyword], +) { + let Some(mut diagnostic) = rule(name, bases, checker.current_scope(), &checker.bindings) else { + return; + }; + if checker.patch(diagnostic.kind.code()) { + if let Some(fix) = pyupgrade::fixes::remove_class_def_base( + checker.locator, + stmt.location, + diagnostic.location, + bases, + keywords, + ) { + diagnostic.amend(fix); + } + } + checker.diagnostics.push(diagnostic); +} diff --git a/src/ruff/mod.rs b/src/ruff/mod.rs index 67c3c33a45..93080df618 100644 --- a/src/ruff/mod.rs +++ b/src/ruff/mod.rs @@ -1,6 +1,6 @@ //! Module for Ruff-specific rules. -pub mod checks; +pub mod rules; #[cfg(test)] mod tests { @@ -14,7 +14,7 @@ mod tests { use crate::registry::RuleCode; use crate::settings; #[test_case(RuleCode::RUF004, Path::new("RUF004.py"); "RUF004")] - fn diagnostics(rule_code: RuleCode, path: &Path) -> Result<()> { + fn rules(rule_code: RuleCode, path: &Path) -> Result<()> { let snapshot = format!("{}_{}", rule_code.as_ref(), path.to_string_lossy()); let diagnostics = test_path( Path::new("./resources/test/fixtures/ruff") diff --git a/src/ruff/checks.rs b/src/ruff/rules.rs similarity index 100% rename from src/ruff/checks.rs rename to src/ruff/rules.rs diff --git a/src/settings/options.rs b/src/settings/options.rs index 5dfddfb218..f8732ce6ee 100644 --- a/src/settings/options.rs +++ b/src/settings/options.rs @@ -143,7 +143,7 @@ pub struct Options { /// A list of check codes that are unsupported by Ruff, but should be /// preserved when (e.g.) validating `# noqa` directives. Useful for /// retaining `# noqa` directives that cover plugins not yet implemented - /// in Ruff. + /// by Ruff. pub external: Option>, #[option(default = "false", value_type = "bool", example = "fix = true")] /// Enable autofix behavior by-default when running `ruff` (overridden