From e402183437dd54f3d0d7fa85d0bcd53da4fa7bcb Mon Sep 17 00:00:00 2001 From: konstin Date: Mon, 25 Sep 2023 16:28:47 +0200 Subject: [PATCH] Rename `Autofix` to `Fix` **Summary** Mostly mechanical rename symbol, with small changes to the markdown docs to read better --- .github/release.yml | 2 +- CONTRIBUTING.md | 2 +- README.md | 4 +- crates/ruff_cli/src/args.rs | 8 +-- crates/ruff_cli/src/commands/check.rs | 8 +-- crates/ruff_cli/src/commands/check_stdin.rs | 4 +- crates/ruff_cli/src/commands/rule.rs | 14 +++--- crates/ruff_cli/src/diagnostics.rs | 20 ++++---- crates/ruff_cli/src/lib.rs | 18 +++---- crates/ruff_cli/src/printer.rs | 22 ++++---- crates/ruff_cli/tests/integration_test.rs | 6 +-- ...ation_test__explain_status_codes_f401.snap | 2 +- crates/ruff_dev/src/generate_docs.rs | 8 +-- crates/ruff_dev/src/generate_rules_table.rs | 8 +-- crates/ruff_diagnostics/src/lib.rs | 2 +- crates/ruff_diagnostics/src/violation.rs | 48 +++++++++--------- .../test/fixtures/flake8_commas/COM81.py | 2 +- .../fixtures/flake8_pytest_style/PT018.py | 4 +- .../test/fixtures/flake8_return/RET504.py | 2 +- .../test/fixtures/pyflakes/F841_3.py | 2 +- crates/ruff_linter/src/cst/matchers.rs | 2 +- .../src/{autofix => fix}/codemods.rs | 0 .../ruff_linter/src/{autofix => fix}/edits.rs | 6 +-- .../ruff_linter/src/{autofix => fix}/mod.rs | 2 +- .../src/{autofix => fix}/snippet.rs | 0 crates/ruff_linter/src/importer/mod.rs | 8 +-- crates/ruff_linter/src/lib.rs | 2 +- crates/ruff_linter/src/linter.rs | 20 ++++---- crates/ruff_linter/src/message/text.rs | 4 +- .../eradicate/rules/commented_out_code.rs | 6 +-- .../flake8_annotations/rules/definition.rs | 6 +-- .../flake8_bugbear/rules/assert_false.rs | 6 +-- .../rules/duplicate_exceptions.rs | 6 +-- .../rules/getattr_with_constant.rs | 8 +-- .../rules/mutable_argument_default.rs | 6 +-- .../redundant_tuple_in_exception_handler.rs | 8 +-- .../rules/setattr_with_constant.rs | 6 +-- .../rules/unreliable_callable_check.rs | 6 +-- .../rules/unused_loop_control_variable.rs | 6 +-- .../flake8_commas/rules/trailing_commas.rs | 12 ++--- ...rules__flake8_commas__tests__COM81.py.snap | 6 +-- .../src/rules/flake8_comprehensions/fixes.rs | 4 +- .../rules/unnecessary_call_around_sorted.rs | 6 +-- .../rules/unnecessary_collection_call.rs | 6 +-- .../rules/unnecessary_comprehension.rs | 6 +-- .../unnecessary_comprehension_any_all.rs | 6 +-- .../unnecessary_double_cast_or_process.rs | 6 +-- .../rules/unnecessary_generator_dict.rs | 6 +-- .../rules/unnecessary_generator_list.rs | 6 +-- .../rules/unnecessary_generator_set.rs | 6 +-- .../rules/unnecessary_list_call.rs | 6 +-- .../unnecessary_list_comprehension_dict.rs | 6 +-- .../unnecessary_list_comprehension_set.rs | 6 +-- .../rules/unnecessary_literal_dict.rs | 6 +-- .../rules/unnecessary_literal_set.rs | 6 +-- .../unnecessary_literal_within_dict_call.rs | 6 +-- .../unnecessary_literal_within_list_call.rs | 6 +-- .../unnecessary_literal_within_tuple_call.rs | 6 +-- .../rules/unnecessary_map.rs | 6 +-- .../rules/string_in_exception.rs | 14 +++--- .../rules/shebang_leading_whitespace.rs | 6 +-- .../rules/implicit.rs | 6 +-- .../rules/unconventional_import_alias.rs | 6 +-- .../rules/direct_logger_instantiation.rs | 6 +-- .../rules/invalid_get_logger_argument.rs | 6 +-- .../flake8_logging/rules/undocumented_warn.rs | 6 +-- .../rules/flake8_logging_format/violations.rs | 6 +-- .../rules/duplicate_class_field_definition.rs | 16 +++--- .../rules/multiple_starts_ends_with.rs | 6 +-- .../flake8_pie/rules/no_unnecessary_pass.rs | 10 ++-- .../rules/reimplemented_list_builtin.rs | 6 +-- .../rules/unnecessary_range_start.rs | 8 +-- .../flake8_pyi/rules/any_eq_ne_annotation.rs | 6 +-- .../rules/collections_named_tuple.rs | 2 +- .../rules/duplicate_union_member.rs | 6 +-- .../rules/ellipsis_in_non_empty_class_body.rs | 16 +++--- .../flake8_pyi/rules/exit_annotations.rs | 6 +-- .../flake8_pyi/rules/non_empty_stub_body.rs | 6 +-- .../flake8_pyi/rules/non_self_return_type.rs | 2 +- .../rules/numeric_literal_too_long.rs | 6 +-- .../flake8_pyi/rules/pass_in_class_body.rs | 10 ++-- .../rules/pass_statement_stub_body.rs | 6 +-- .../rules/quoted_annotation_in_stub.rs | 6 +-- .../rules/redundant_literal_union.rs | 2 +- .../rules/flake8_pyi/rules/simple_defaults.rs | 18 +++---- .../rules/str_or_repr_defined_in_stub.rs | 8 +-- .../rules/string_or_bytes_too_long.rs | 6 +-- .../unaliased_collections_abc_set_import.rs | 6 +-- .../flake8_pytest_style/rules/assertion.rs | 16 +++--- .../flake8_pytest_style/rules/fixture.rs | 24 ++++----- .../rules/flake8_pytest_style/rules/marks.rs | 10 ++-- .../flake8_pytest_style/rules/parametrize.rs | 10 ++-- .../rules/unittest_assert.rs | 2 +- ...es__flake8_pytest_style__tests__PT018.snap | 16 +++--- .../rules/flake8_quotes/rules/from_tokens.rs | 18 +++---- .../unnecessary_paren_on_raise_exception.rs | 6 +-- .../src/rules/flake8_return/rules/function.rs | 20 ++++---- ...lake8_return__tests__RET504_RET504.py.snap | 2 +- .../flake8_simplify/rules/ast_bool_op.rs | 26 +++++----- .../rules/flake8_simplify/rules/ast_expr.rs | 12 ++--- .../src/rules/flake8_simplify/rules/ast_if.rs | 18 +++---- .../rules/flake8_simplify/rules/ast_ifexp.rs | 14 +++--- .../flake8_simplify/rules/ast_unary_op.rs | 14 +++--- .../rules/flake8_simplify/rules/ast_with.rs | 6 +-- .../src/rules/flake8_simplify/rules/fix_if.rs | 2 +- .../rules/flake8_simplify/rules/fix_with.rs | 2 +- .../flake8_simplify/rules/key_in_dict.rs | 6 +-- .../rules/reimplemented_builtin.rs | 6 +-- .../rules/suppressible_exception.rs | 6 +-- .../flake8_simplify/rules/yoda_conditions.rs | 10 ++-- .../rules/relative_imports.rs | 6 +-- .../src/rules/flake8_todos/rules/todos.rs | 6 +-- .../rules/empty_type_checking_block.rs | 10 ++-- .../runtime_import_in_type_checking_block.rs | 10 ++-- .../rules/typing_only_runtime_import.rs | 18 +++---- .../path_constructor_current_directory.rs | 6 +-- .../flynt/rules/static_join_to_fstring.rs | 10 ++-- .../rules/isort/rules/add_required_imports.rs | 6 +-- .../src/rules/isort/rules/organize_imports.rs | 6 +-- .../rules/numpy/rules/deprecated_function.rs | 6 +-- .../numpy/rules/deprecated_type_alias.rs | 6 +-- .../pandas_vet/rules/inplace_argument.rs | 8 +-- .../perflint/rules/incorrect_dict_iterator.rs | 8 +-- .../perflint/rules/unnecessary_list_cast.rs | 6 +-- .../pycodestyle/rules/compound_statements.rs | 6 +-- .../rules/invalid_escape_sequence.rs | 12 ++--- .../pycodestyle/rules/lambda_assignment.rs | 6 +-- .../pycodestyle/rules/literal_comparisons.rs | 10 ++-- .../logical_lines/extraneous_whitespace.rs | 26 +++++----- .../rules/logical_lines/missing_whitespace.rs | 14 ++---- .../whitespace_before_parameters.rs | 10 ++-- .../rules/missing_newline_at_end_of_file.rs | 10 ++-- .../src/rules/pycodestyle/rules/not_tests.rs | 12 ++--- .../pycodestyle/rules/trailing_whitespace.rs | 10 ++-- .../pydocstyle/rules/blank_after_summary.rs | 6 +-- .../rules/blank_before_after_class.rs | 14 +++--- .../rules/blank_before_after_function.rs | 10 ++-- .../src/rules/pydocstyle/rules/capitalized.rs | 6 +-- .../pydocstyle/rules/ends_with_period.rs | 8 +-- .../pydocstyle/rules/ends_with_punctuation.rs | 8 +-- .../src/rules/pydocstyle/rules/indent.rs | 14 +++--- .../rules/multi_line_summary_start.rs | 10 ++-- .../rules/newline_after_last_paragraph.rs | 6 +-- .../rules/no_surrounding_whitespace.rs | 6 +-- .../src/rules/pydocstyle/rules/one_liner.rs | 6 +-- .../src/rules/pydocstyle/rules/sections.rs | 50 +++++++++---------- .../rules/f_string_missing_placeholders.rs | 6 +-- .../rules/invalid_literal_comparisons.rs | 6 +-- .../pyflakes/rules/raise_not_implemented.rs | 6 +-- .../src/rules/pyflakes/rules/repeated_keys.rs | 12 ++--- .../src/rules/pyflakes/rules/strings.rs | 14 +++--- .../src/rules/pyflakes/rules/unused_import.rs | 10 ++-- .../rules/pyflakes/rules/unused_variable.rs | 8 +-- .../pylint/rules/comparison_with_itself.rs | 2 +- .../pylint/rules/invalid_string_characters.rs | 22 ++++---- .../rules/pylint/rules/manual_import_from.rs | 6 +-- .../src/rules/pylint/rules/nested_min_max.rs | 6 +-- .../rules/repeated_equality_comparison.rs | 2 +- .../pylint/rules/repeated_isinstance_calls.rs | 10 ++-- .../src/rules/pylint/rules/sys_exit_alias.rs | 6 +-- .../pylint/rules/useless_import_alias.rs | 6 +-- .../src/rules/pylint/rules/useless_return.rs | 16 +++--- .../ruff_linter/src/rules/pyupgrade/fixes.rs | 2 +- ...convert_named_tuple_functional_to_class.rs | 6 +-- .../convert_typed_dict_functional_to_class.rs | 6 +-- .../pyupgrade/rules/datetime_utc_alias.rs | 6 +-- .../rules/deprecated_c_element_tree.rs | 6 +-- .../pyupgrade/rules/deprecated_import.rs | 6 +-- .../pyupgrade/rules/deprecated_mock_import.rs | 8 +-- .../rules/deprecated_unittest_alias.rs | 6 +-- .../pyupgrade/rules/extraneous_parentheses.rs | 6 +-- .../src/rules/pyupgrade/rules/f_strings.rs | 8 +-- .../rules/pyupgrade/rules/format_literals.rs | 8 +-- .../rules/lru_cache_with_maxsize_none.rs | 6 +-- .../rules/lru_cache_without_parameters.rs | 6 +-- .../rules/pyupgrade/rules/native_literals.rs | 6 +-- .../src/rules/pyupgrade/rules/open_alias.rs | 6 +-- .../rules/pyupgrade/rules/os_error_alias.rs | 8 +-- .../pyupgrade/rules/outdated_version_block.rs | 8 +-- .../rules/printf_string_formatting.rs | 8 +-- .../pyupgrade/rules/quoted_annotation.rs | 6 +-- .../pyupgrade/rules/redundant_open_modes.rs | 6 +-- .../pyupgrade/rules/replace_stdout_stderr.rs | 8 +-- .../rules/replace_universal_newlines.rs | 8 +-- .../rules/super_call_with_parameters.rs | 6 +-- .../pyupgrade/rules/type_of_primitive.rs | 8 +-- .../pyupgrade/rules/typing_text_str_alias.rs | 6 +-- .../pyupgrade/rules/unicode_kind_prefix.rs | 6 +-- .../rules/unnecessary_builtin_import.rs | 10 ++-- .../rules/unnecessary_class_parentheses.rs | 6 +-- .../rules/unnecessary_coding_comment.rs | 6 +-- .../rules/unnecessary_encode_utf8.rs | 8 +-- .../rules/unnecessary_future_import.rs | 10 ++-- .../rules/unpacked_list_comprehension.rs | 6 +-- .../pyupgrade/rules/use_pep585_annotation.rs | 6 +-- .../pyupgrade/rules/use_pep604_annotation.rs | 8 +-- .../pyupgrade/rules/use_pep604_isinstance.rs | 6 +-- .../pyupgrade/rules/use_pep695_type_alias.rs | 6 +-- .../pyupgrade/rules/useless_metaclass_type.rs | 10 ++-- .../rules/useless_object_inheritance.rs | 8 +-- .../pyupgrade/rules/yield_in_for_loop.rs | 6 +-- .../refurb/rules/check_and_remove_from_set.rs | 8 +-- .../rules/refurb/rules/delete_full_slice.rs | 6 +-- .../rules/refurb/rules/print_empty_string.rs | 6 +-- .../refurb/rules/reimplemented_starmap.rs | 6 +-- .../src/rules/refurb/rules/repeated_append.rs | 8 +-- .../src/rules/refurb/rules/slice_copy.rs | 6 +-- .../refurb/rules/unnecessary_enumerate.rs | 8 +-- .../rules/collection_literal_concatenation.rs | 8 +-- .../explicit_f_string_type_conversion.rs | 6 +-- .../src/rules/ruff/rules/implicit_optional.rs | 6 +-- .../ruff/rules/invalid_pyproject_toml.rs | 4 +- .../ruff/rules/quadratic_list_summation.rs | 6 +-- .../rules/static_key_dict_comprehension.rs | 2 +- ...y_iterable_allocation_for_first_element.rs | 8 +-- .../src/rules/ruff/rules/unused_noqa.rs | 6 +-- .../rules/tryceratops/rules/verbose_raise.rs | 6 +-- crates/ruff_linter/src/settings/rule_table.rs | 6 +-- crates/ruff_linter/src/test.rs | 24 ++++----- crates/ruff_macros/src/map_codes.rs | 12 ++--- crates/ruff_macros/src/violation.rs | 4 +- crates/ruff_notebook/src/notebook.rs | 2 +- crates/ruff_workspace/src/options.rs | 18 +++---- docs/configuration.md | 18 +++---- docs/editor-integrations.md | 2 +- docs/faq.md | 10 ++-- docs/usage.md | 6 +-- playground/src/Editor/SourceEditor.tsx | 2 +- ruff.schema.json | 10 ++-- scripts/ecosystem_all_check.py | 2 +- scripts/ecosystem_all_check.sh | 6 +-- 231 files changed, 930 insertions(+), 946 deletions(-) rename crates/ruff_linter/src/{autofix => fix}/codemods.rs (100%) rename crates/ruff_linter/src/{autofix => fix}/edits.rs (98%) rename crates/ruff_linter/src/{autofix => fix}/mod.rs (99%) rename crates/ruff_linter/src/{autofix => fix}/snippet.rs (100%) diff --git a/.github/release.yml b/.github/release.yml index 7b7737791d36d..29cdd79de793f 100644 --- a/.github/release.yml +++ b/.github/release.yml @@ -12,7 +12,7 @@ changelog: - title: Rules labels: - rule - - autofix + - fix - title: Settings labels: - configuration diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index cf239242294f1..f721c4992d403 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -204,7 +204,7 @@ As such, rule names should... For example, `AssertFalse` guards against `assert False` statements. - _Not_ contain instructions on how to fix the violation, which instead belong in the rule - documentation and the `autofix_title`. + documentation and the `fix_title`. - _Not_ contain a redundant prefix, like `Disallow` or `Banned`, which are already implied by the convention. diff --git a/README.md b/README.md index 19f4ab17f27f3..07fbf8c0ac4ba 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ An extremely fast Python linter, written in Rust. - 🛠️ `pyproject.toml` support - 🤝 Python 3.11 compatibility - 📦 Built-in caching, to avoid re-analyzing unchanged files -- 🔧 Autofix support, for automatic error correction (e.g., automatically remove unused imports) +- 🔧 Fix support, for automatic error correction (e.g., automatically remove unused imports) - 📏 Over [700 built-in rules](https://docs.astral.sh/ruff/rules/) - ⚖️ [Near-parity](https://docs.astral.sh/ruff/faq/#how-does-ruff-compare-to-flake8) with the built-in Flake8 rule set @@ -176,7 +176,7 @@ If left unspecified, the default configuration is equivalent to: select = ["E", "F"] ignore = [] -# Allow autofix for all enabled rules (when `--fix`) is provided. +# Allow fix for all enabled rules (when `--fix`) is provided. fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"] unfixable = [] diff --git a/crates/ruff_cli/src/args.rs b/crates/ruff_cli/src/args.rs index b3159f4eb6ab5..1156b3a133dae 100644 --- a/crates/ruff_cli/src/args.rs +++ b/crates/ruff_cli/src/args.rs @@ -88,7 +88,7 @@ pub struct CheckCommand { show_source: bool, #[clap(long, overrides_with("show_source"), hide = true)] no_show_source: bool, - /// Show an enumeration of all autofixed lint violations. + /// Show an enumeration of all fixed lint violations. /// Use `--no-show-fixes` to disable. #[arg(long, overrides_with("no_show_fixes"))] show_fixes: bool, @@ -202,7 +202,7 @@ pub struct CheckCommand { help_heading = "File selection" )] pub extend_exclude: Option>, - /// List of rule codes to treat as eligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`). + /// List of rule codes to treat as eligible for fix. Only applicable when fix itself is enabled (e.g., via `--fix`). #[arg( long, value_delimiter = ',', @@ -212,7 +212,7 @@ pub struct CheckCommand { hide_possible_values = true )] pub fixable: Option>, - /// List of rule codes to treat as ineligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`). + /// List of rule codes to treat as ineligible for fix. Only applicable when fix itself is enabled (e.g., via `--fix`). #[arg( long, value_delimiter = ',', @@ -288,7 +288,7 @@ pub struct CheckCommand { conflicts_with = "exit_non_zero_on_fix" )] pub exit_zero: bool, - /// Exit with a non-zero status code if any files were modified via autofix, even if no lint violations remain. + /// Exit with a non-zero status code if any files were modified via fix, even if no lint violations remain. #[arg(long, help_heading = "Miscellaneous", conflicts_with = "exit_zero")] pub exit_non_zero_on_fix: bool, /// Show counts for every rule with at least one violation. diff --git a/crates/ruff_cli/src/commands/check.rs b/crates/ruff_cli/src/commands/check.rs index a16f9fef9ae5d..f19c8d80d4c11 100644 --- a/crates/ruff_cli/src/commands/check.rs +++ b/crates/ruff_cli/src/commands/check.rs @@ -35,7 +35,7 @@ pub(crate) fn check( overrides: &CliOverrides, cache: flags::Cache, noqa: flags::Noqa, - autofix: flags::FixMode, + fix_mode: flags::FixMode, ) -> Result { // Collect all the Python files to check. let start = Instant::now(); @@ -119,7 +119,7 @@ pub(crate) fn check( } }); - lint_path(path, package, &settings.linter, cache, noqa, autofix).map_err(|e| { + lint_path(path, package, &settings.linter, cache, noqa, fix_mode).map_err(|e| { (Some(path.to_owned()), { let mut error = e.to_string(); for cause in e.chain() { @@ -198,10 +198,10 @@ fn lint_path( settings: &LinterSettings, cache: Option<&Cache>, noqa: flags::Noqa, - autofix: flags::FixMode, + fix_mode: flags::FixMode, ) -> Result { let result = catch_unwind(|| { - crate::diagnostics::lint_path(path, package, settings, cache, noqa, autofix) + crate::diagnostics::lint_path(path, package, settings, cache, noqa, fix_mode) }); match result { diff --git a/crates/ruff_cli/src/commands/check_stdin.rs b/crates/ruff_cli/src/commands/check_stdin.rs index 9b391fb384e40..ab15f61439f43 100644 --- a/crates/ruff_cli/src/commands/check_stdin.rs +++ b/crates/ruff_cli/src/commands/check_stdin.rs @@ -16,7 +16,7 @@ pub(crate) fn check_stdin( pyproject_config: &PyprojectConfig, overrides: &CliOverrides, noqa: flags::Noqa, - autofix: flags::FixMode, + fix_mode: flags::FixMode, ) -> Result { if let Some(filename) = filename { if !python_file_at_path(filename, pyproject_config, overrides)? { @@ -33,7 +33,7 @@ pub(crate) fn check_stdin( stdin, &pyproject_config.settings, noqa, - autofix, + fix_mode, )?; diagnostics.messages.sort_unstable(); Ok(diagnostics) diff --git a/crates/ruff_cli/src/commands/rule.rs b/crates/ruff_cli/src/commands/rule.rs index f9b9f86c957dc..1373ef3d46313 100644 --- a/crates/ruff_cli/src/commands/rule.rs +++ b/crates/ruff_cli/src/commands/rule.rs @@ -5,7 +5,7 @@ use serde::ser::SerializeSeq; use serde::{Serialize, Serializer}; use strum::IntoEnumIterator; -use ruff_diagnostics::AutofixKind; +use ruff_diagnostics::FixKind; use ruff_linter::registry::{Linter, Rule, RuleNamespace}; use crate::args::HelpFormat; @@ -17,7 +17,7 @@ struct Explanation<'a> { linter: &'a str, summary: &'a str, message_formats: &'a [&'a str], - autofix: String, + fix: String, explanation: Option<&'a str>, preview: bool, } @@ -26,14 +26,14 @@ impl<'a> Explanation<'a> { fn from_rule(rule: &'a Rule) -> Self { let code = rule.noqa_code().to_string(); let (linter, _) = Linter::parse_code(&code).unwrap(); - let autofix = rule.autofixable().to_string(); + let fix = rule.fixable().to_string(); Self { name: rule.as_ref(), code, linter: linter.name(), summary: rule.message_formats()[0], message_formats: rule.message_formats(), - autofix, + fix, explanation: rule.explanation(), preview: rule.is_preview(), } @@ -51,9 +51,9 @@ fn format_rule_text(rule: Rule) -> String { output.push('\n'); output.push('\n'); - let autofix = rule.autofixable(); - if matches!(autofix, AutofixKind::Always | AutofixKind::Sometimes) { - output.push_str(&autofix.to_string()); + let fix_kind = rule.fixable(); + if matches!(fix_kind, FixKind::Always | FixKind::Sometimes) { + output.push_str(&fix_kind.to_string()); output.push('\n'); output.push('\n'); } diff --git a/crates/ruff_cli/src/diagnostics.rs b/crates/ruff_cli/src/diagnostics.rs index 13de795a86b8b..b8308f281962e 100644 --- a/crates/ruff_cli/src/diagnostics.rs +++ b/crates/ruff_cli/src/diagnostics.rs @@ -147,7 +147,7 @@ pub(crate) fn lint_path( settings: &LinterSettings, cache: Option<&Cache>, noqa: flags::Noqa, - autofix: flags::FixMode, + fix_mode: flags::FixMode, ) -> Result { // Check the cache. // TODO(charlie): `fixer::Mode::Apply` and `fixer::Mode::Diff` both have @@ -156,7 +156,7 @@ pub(crate) fn lint_path( // write the fixes to disk, thus invalidating the cache. But it's a bit hard // to reason about. We need to come up with a better solution here.) let caching = match cache { - Some(cache) if noqa.into() && autofix.is_generate() => { + Some(cache) if noqa.into() && fix_mode.is_generate() => { let relative_path = cache .relative_path(path) .expect("wrong package cache for file"); @@ -220,7 +220,7 @@ pub(crate) fn lint_path( error: parse_error, }, fixed, - ) = if matches!(autofix, flags::FixMode::Apply | flags::FixMode::Diff) { + ) = if matches!(fix_mode, flags::FixMode::Apply | flags::FixMode::Diff) { if let Ok(FixerResult { result, transformed, @@ -228,7 +228,7 @@ pub(crate) fn lint_path( }) = lint_fix(path, package, noqa, settings, &source_kind, source_type) { if !fixed.is_empty() { - match autofix { + match fix_mode { flags::FixMode::Apply => match transformed.as_ref() { SourceKind::Python(transformed) => { write(path, transformed.as_bytes())?; @@ -302,7 +302,7 @@ pub(crate) fn lint_path( } (result, fixed) } else { - // If we fail to autofix, lint the original source code. + // If we fail to fix, lint the original source code. let result = lint_only(path, package, settings, noqa, &source_kind, source_type); let fixed = FxHashMap::default(); (result, fixed) @@ -370,7 +370,7 @@ pub(crate) fn lint_stdin( contents: String, settings: &Settings, noqa: flags::Noqa, - autofix: flags::FixMode, + fix_mode: flags::FixMode, ) -> Result { // TODO(charlie): Support `pyproject.toml`. let SourceType::Python(source_type) = path.map(SourceType::from).unwrap_or_default() else { @@ -393,7 +393,7 @@ pub(crate) fn lint_stdin( error: parse_error, }, fixed, - ) = if matches!(autofix, flags::FixMode::Apply | flags::FixMode::Diff) { + ) = if matches!(fix_mode, flags::FixMode::Apply | flags::FixMode::Diff) { if let Ok(FixerResult { result, transformed, @@ -406,7 +406,7 @@ pub(crate) fn lint_stdin( &source_kind, source_type, ) { - match autofix { + match fix_mode { flags::FixMode::Apply => { // Write the contents to stdout, regardless of whether any errors were fixed. io::stdout().write_all(transformed.source_code().as_bytes())?; @@ -435,7 +435,7 @@ pub(crate) fn lint_stdin( (result, fixed) } else { - // If we fail to autofix, lint the original source code. + // If we fail to fix, lint the original source code. let result = lint_only( path.unwrap_or_else(|| Path::new("-")), package, @@ -447,7 +447,7 @@ pub(crate) fn lint_stdin( let fixed = FxHashMap::default(); // Write the contents to stdout anyway. - if autofix.is_apply() { + if fix_mode.is_apply() { io::stdout().write_all(source_kind.source_code().as_bytes())?; } diff --git a/crates/ruff_cli/src/lib.rs b/crates/ruff_cli/src/lib.rs index c7f0c34729322..f9dbb164df0d3 100644 --- a/crates/ruff_cli/src/lib.rs +++ b/crates/ruff_cli/src/lib.rs @@ -234,13 +234,13 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result { .. } = pyproject_config.settings; - // Autofix rules are as follows: + // Fix rules are as follows: // - By default, generate all fixes, but don't apply them to the filesystem. // - If `--fix` or `--fix-only` is set, always apply fixes to the filesystem (or // print them to stdout, if we're reading from stdin). // - If `--diff` or `--fix-only` are set, don't print any violations (only // fixes). - let autofix = if cli.diff { + let fix_mode = if cli.diff { flags::FixMode::Diff } else if fix || fix_only { flags::FixMode::Apply @@ -275,7 +275,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result { } if cli.add_noqa { - if !autofix.is_generate() { + if !fix_mode.is_generate() { warn_user!("--fix is incompatible with --add-noqa."); } let modifications = @@ -290,7 +290,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result { return Ok(ExitStatus::Success); } - let printer = Printer::new(output_format, log_level, autofix, printer_flags); + let printer = Printer::new(output_format, log_level, fix_mode, printer_flags); if cli.watch { if output_format != SerializationFormat::Text { @@ -317,7 +317,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result { &overrides, cache.into(), noqa.into(), - autofix, + fix_mode, )?; printer.write_continuously(&mut writer, &messages)?; @@ -349,7 +349,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result { &overrides, cache.into(), noqa.into(), - autofix, + fix_mode, )?; printer.write_continuously(&mut writer, &messages)?; } @@ -366,7 +366,7 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result { &pyproject_config, &overrides, noqa.into(), - autofix, + fix_mode, )? } else { commands::check::check( @@ -375,14 +375,14 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result { &overrides, cache.into(), noqa.into(), - autofix, + fix_mode, )? }; // Always try to print violations (the printer itself may suppress output), // unless we're writing fixes via stdin (in which case, the transformed // source code goes to stdout). - if !(is_stdin && matches!(autofix, flags::FixMode::Apply | flags::FixMode::Diff)) { + if !(is_stdin && matches!(fix_mode, flags::FixMode::Apply | flags::FixMode::Diff)) { if cli.statistics { printer.write_statistics(&diagnostics, &mut writer)?; } else { diff --git a/crates/ruff_cli/src/printer.rs b/crates/ruff_cli/src/printer.rs index 07757fed83860..7700df9749466 100644 --- a/crates/ruff_cli/src/printer.rs +++ b/crates/ruff_cli/src/printer.rs @@ -72,7 +72,7 @@ impl From for SerializeRuleAsCode { pub(crate) struct Printer { format: SerializationFormat, log_level: LogLevel, - autofix_level: flags::FixMode, + fix_mode: flags::FixMode, flags: Flags, } @@ -80,13 +80,13 @@ impl Printer { pub(crate) const fn new( format: SerializationFormat, log_level: LogLevel, - autofix_level: flags::FixMode, + fix_mode: flags::FixMode, flags: Flags, ) -> Self { Self { format, log_level, - autofix_level, + fix_mode, flags, } } @@ -118,7 +118,7 @@ impl Printer { writeln!(writer, "Found {remaining} error{s}.")?; } - if show_fix_status(self.autofix_level) { + if show_fix_status(self.fix_mode) { let num_fixable = diagnostics .messages .iter() @@ -140,7 +140,7 @@ impl Printer { .sum::(); if fixed > 0 { let s = if fixed == 1 { "" } else { "s" }; - if self.autofix_level.is_apply() { + if self.fix_mode.is_apply() { writeln!(writer, "Fixed {fixed} error{s}.")?; } else { writeln!(writer, "Would fix {fixed} error{s}.")?; @@ -191,7 +191,7 @@ impl Printer { } SerializationFormat::Text => { TextEmitter::default() - .with_show_fix_status(show_fix_status(self.autofix_level)) + .with_show_fix_status(show_fix_status(self.fix_mode)) .with_show_fix_diff(self.flags.intersects(Flags::SHOW_FIX_DIFF)) .with_show_source(self.flags.intersects(Flags::SHOW_SOURCE)) .emit(writer, &diagnostics.messages, &context)?; @@ -209,7 +209,7 @@ impl Printer { SerializationFormat::Grouped => { GroupedEmitter::default() .with_show_source(self.flags.intersects(Flags::SHOW_SOURCE)) - .with_show_fix_status(show_fix_status(self.autofix_level)) + .with_show_fix_status(show_fix_status(self.fix_mode)) .emit(writer, &diagnostics.messages, &context)?; if self.flags.intersects(Flags::SHOW_FIX_SUMMARY) { @@ -366,7 +366,7 @@ impl Printer { let context = EmitterContext::new(&diagnostics.notebook_indexes); TextEmitter::default() - .with_show_fix_status(show_fix_status(self.autofix_level)) + .with_show_fix_status(show_fix_status(self.fix_mode)) .with_show_source(self.flags.intersects(Flags::SHOW_SOURCE)) .emit(writer, &diagnostics.messages, &context)?; } @@ -390,13 +390,13 @@ fn num_digits(n: usize) -> usize { } /// Return `true` if the [`Printer`] should indicate that a rule is fixable. -const fn show_fix_status(autofix_level: flags::FixMode) -> bool { +const fn show_fix_status(fix_mode: flags::FixMode) -> bool { // If we're in application mode, avoid indicating that a rule is fixable. // If the specific violation were truly fixable, it would've been fixed in // this pass! (We're occasionally unable to determine whether a specific - // violation is fixable without trying to fix it, so if autofix is not + // violation is fixable without trying to fix it, so if fix is not // enabled, we may inadvertently indicate that a rule is fixable.) - !autofix_level.is_apply() + !fix_mode.is_apply() } fn print_fix_summary(writer: &mut dyn Write, fixed: &FxHashMap) -> Result<()> { diff --git a/crates/ruff_cli/tests/integration_test.rs b/crates/ruff_cli/tests/integration_test.rs index 1a4e538bd2ff8..2dc20faafaec9 100644 --- a/crates/ruff_cli/tests/integration_test.rs +++ b/crates/ruff_cli/tests/integration_test.rs @@ -137,7 +137,7 @@ fn stdin_json() { } #[test] -fn stdin_autofix() { +fn stdin_fix() { let args = ["--fix"]; assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .args(STDIN_BASE_OPTIONS) @@ -155,7 +155,7 @@ fn stdin_autofix() { } #[test] -fn stdin_autofix_when_not_fixable_should_still_print_contents() { +fn stdin_fix_when_not_fixable_should_still_print_contents() { let args = ["--fix"]; assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .args(STDIN_BASE_OPTIONS) @@ -174,7 +174,7 @@ fn stdin_autofix_when_not_fixable_should_still_print_contents() { } #[test] -fn stdin_autofix_when_no_issues_should_still_print_contents() { +fn stdin_fix_when_no_issues_should_still_print_contents() { let args = ["--fix"]; assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) .args(STDIN_BASE_OPTIONS) diff --git a/crates/ruff_cli/tests/snapshots/integration_test__explain_status_codes_f401.snap b/crates/ruff_cli/tests/snapshots/integration_test__explain_status_codes_f401.snap index 17615bf57049e..f8e0c12dc7021 100644 --- a/crates/ruff_cli/tests/snapshots/integration_test__explain_status_codes_f401.snap +++ b/crates/ruff_cli/tests/snapshots/integration_test__explain_status_codes_f401.snap @@ -13,7 +13,7 @@ exit_code: 0 Derived from the **Pyflakes** linter. -Autofix is sometimes available. +Fix is sometimes available. ## What it does Checks for unused imports. diff --git a/crates/ruff_dev/src/generate_docs.rs b/crates/ruff_dev/src/generate_docs.rs index b6b70c7f4e324..bbbc59bea192a 100644 --- a/crates/ruff_dev/src/generate_docs.rs +++ b/crates/ruff_dev/src/generate_docs.rs @@ -8,7 +8,7 @@ use anyhow::Result; use regex::{Captures, Regex}; use strum::IntoEnumIterator; -use ruff_diagnostics::AutofixKind; +use ruff_diagnostics::FixKind; use ruff_linter::registry::{Linter, Rule, RuleNamespace}; use ruff_workspace::options::Options; use ruff_workspace::options_base::OptionsMetadata; @@ -37,9 +37,9 @@ pub(crate) fn main(args: &Args) -> Result<()> { output.push('\n'); } - let autofix = rule.autofixable(); - if matches!(autofix, AutofixKind::Always | AutofixKind::Sometimes) { - output.push_str(&autofix.to_string()); + let fix_kind = rule.fixable(); + if matches!(fix_kind, FixKind::Always | FixKind::Sometimes) { + output.push_str(&fix_kind.to_string()); output.push('\n'); output.push('\n'); } diff --git a/crates/ruff_dev/src/generate_rules_table.rs b/crates/ruff_dev/src/generate_rules_table.rs index 82addce497d4d..23f02d20a8031 100644 --- a/crates/ruff_dev/src/generate_rules_table.rs +++ b/crates/ruff_dev/src/generate_rules_table.rs @@ -5,7 +5,7 @@ use itertools::Itertools; use strum::IntoEnumIterator; -use ruff_diagnostics::AutofixKind; +use ruff_diagnostics::FixKind; use ruff_linter::registry::{Linter, Rule, RuleNamespace}; use ruff_linter::upstream_categories::UpstreamCategoryAndPrefix; use ruff_workspace::options::Options; @@ -20,11 +20,11 @@ fn generate_table(table_out: &mut String, rules: impl IntoIterator, table_out.push_str("| ---- | ---- | ------- | ------: |"); table_out.push('\n'); for rule in rules { - let fix_token = match rule.autofixable() { - AutofixKind::Always | AutofixKind::Sometimes => { + let fix_token = match rule.fixable() { + FixKind::Always | FixKind::Sometimes => { format!("{FIX_SYMBOL}") } - AutofixKind::None => format!("{FIX_SYMBOL}"), + FixKind::None => format!("{FIX_SYMBOL}"), }; let preview_token = if rule.is_preview() || rule.is_nursery() { format!("{PREVIEW_SYMBOL}") diff --git a/crates/ruff_diagnostics/src/lib.rs b/crates/ruff_diagnostics/src/lib.rs index f093861de7fbf..9315e23bc92ca 100644 --- a/crates/ruff_diagnostics/src/lib.rs +++ b/crates/ruff_diagnostics/src/lib.rs @@ -2,7 +2,7 @@ pub use diagnostic::{Diagnostic, DiagnosticKind}; pub use edit::Edit; pub use fix::{Applicability, Fix, IsolationLevel}; pub use source_map::{SourceMap, SourceMarker}; -pub use violation::{AlwaysAutofixableViolation, AutofixKind, Violation}; +pub use violation::{AlwaysFixableViolation, FixKind, Violation}; mod diagnostic; mod edit; diff --git a/crates/ruff_diagnostics/src/violation.rs b/crates/ruff_diagnostics/src/violation.rs index d57a1b4e38b1b..9c171b8b1d319 100644 --- a/crates/ruff_diagnostics/src/violation.rs +++ b/crates/ruff_diagnostics/src/violation.rs @@ -1,26 +1,26 @@ use std::fmt::{Debug, Display}; #[derive(Debug, Copy, Clone)] -pub enum AutofixKind { +pub enum FixKind { Sometimes, Always, None, } -impl Display for AutofixKind { +impl Display for FixKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - AutofixKind::Sometimes => write!(f, "Autofix is sometimes available."), - AutofixKind::Always => write!(f, "Autofix is always available."), - AutofixKind::None => write!(f, "Autofix is not available."), + FixKind::Sometimes => write!(f, "Fix is sometimes available."), + FixKind::Always => write!(f, "Fix is always available."), + FixKind::None => write!(f, "Fix is not available."), } } } pub trait Violation: Debug + PartialEq + Eq { - /// `None` in the case an autofix is never available or otherwise Some - /// [`AutofixKind`] describing the available autofix. - const AUTOFIX: AutofixKind = AutofixKind::None; + /// `None` in the case an fix is never available or otherwise Some + /// [`FixKind`] describing the available fix. + const FIX_KIND: FixKind = FixKind::None; /// The message used to describe the violation. fn message(&self) -> String; @@ -30,13 +30,13 @@ pub trait Violation: Debug + PartialEq + Eq { None } - // TODO(micha): Move `autofix_title` to `Fix`, add new `advice` method that is shown as an advice. + // TODO(micha): Move `fix_title` to `Fix`, add new `advice` method that is shown as an advice. // Change the `Diagnostic` renderer to show the advice, and render the fix message after the `Suggested fix: ` - /// Returns the title for the autofix. The message is also shown as an advice as part of the diagnostics. + /// Returns the title for the fix. The message is also shown as an advice as part of the diagnostics. /// - /// Required for rules that have autofixes. - fn autofix_title(&self) -> Option { + /// Required for rules that have fixes. + fn fix_title(&self) -> Option { None } @@ -45,8 +45,8 @@ pub trait Violation: Debug + PartialEq + Eq { } /// This trait exists just to make implementing the [`Violation`] trait more -/// convenient for violations that can always be autofixed. -pub trait AlwaysAutofixableViolation: Debug + PartialEq + Eq { +/// convenient for violations that can always be fixed. +pub trait AlwaysFixableViolation: Debug + PartialEq + Eq { /// The message used to describe the violation. fn message(&self) -> String; @@ -55,31 +55,31 @@ pub trait AlwaysAutofixableViolation: Debug + PartialEq + Eq { None } - /// The title displayed for the available autofix. - fn autofix_title(&self) -> String; + /// The title displayed for the available fix. + fn fix_title(&self) -> String; /// Returns the format strings used by - /// [`message`](AlwaysAutofixableViolation::message). + /// [`message`](AlwaysFixableViolation::message). fn message_formats() -> &'static [&'static str]; } /// A blanket implementation. -impl Violation for VA { - const AUTOFIX: AutofixKind = AutofixKind::Always; +impl Violation for V { + const FIX_KIND: FixKind = FixKind::Always; fn message(&self) -> String { - ::message(self) + ::message(self) } fn explanation() -> Option<&'static str> { - ::explanation() + ::explanation() } - fn autofix_title(&self) -> Option { - Some(::autofix_title(self)) + fn fix_title(&self) -> Option { + Some(::fix_title(self)) } fn message_formats() -> &'static [&'static str] { - ::message_formats() + ::message_formats() } } diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_commas/COM81.py b/crates/ruff_linter/resources/test/fixtures/flake8_commas/COM81.py index f76059e98d095..8bc53dcd34760 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_commas/COM81.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_commas/COM81.py @@ -627,7 +627,7 @@ def foo( **{'ham': spam} ) -# Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error. +# Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error. the_first_one = next( (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket ) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT018.py b/crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT018.py index 0eafac016e681..0ccec6f7596ab 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT018.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pytest_style/PT018.py @@ -33,10 +33,10 @@ def test_error(): assert not (a or not (b or c)) assert not (a or not (b and c)) - # detected, but no autofix for messages + # detected, but no fix for messages assert something and something_else, "error message" assert not (something or something_else and something_third), "with message" - # detected, but no autofix for mixed conditions (e.g. `a or b and c`) + # detected, but no fix for mixed conditions (e.g. `a or b and c`) assert not (something or something_else and something_third) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_return/RET504.py b/crates/ruff_linter/resources/test/fixtures/flake8_return/RET504.py index ef71d178ad75b..9899fa15ed6bc 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_return/RET504.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_return/RET504.py @@ -335,7 +335,7 @@ def foo(): return x -# Autofix cases +# Fix cases def foo(): a = 1 b=a diff --git a/crates/ruff_linter/resources/test/fixtures/pyflakes/F841_3.py b/crates/ruff_linter/resources/test/fixtures/pyflakes/F841_3.py index 00c2962223d60..a9aa20d035a99 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyflakes/F841_3.py +++ b/crates/ruff_linter/resources/test/fixtures/pyflakes/F841_3.py @@ -1,4 +1,4 @@ -"""Test case for autofixing F841 violations.""" +"""Test case for fixing F841 violations.""" def f(): diff --git a/crates/ruff_linter/src/cst/matchers.rs b/crates/ruff_linter/src/cst/matchers.rs index 70cc4b3aa351d..fac3be1e41010 100644 --- a/crates/ruff_linter/src/cst/matchers.rs +++ b/crates/ruff_linter/src/cst/matchers.rs @@ -1,4 +1,4 @@ -use crate::autofix::codemods::CodegenStylist; +use crate::fix::codemods::CodegenStylist; use anyhow::{bail, Result}; use libcst_native::{ Arg, Attribute, Call, Comparison, CompoundStatement, Dict, Expression, FunctionDef, diff --git a/crates/ruff_linter/src/autofix/codemods.rs b/crates/ruff_linter/src/fix/codemods.rs similarity index 100% rename from crates/ruff_linter/src/autofix/codemods.rs rename to crates/ruff_linter/src/fix/codemods.rs diff --git a/crates/ruff_linter/src/autofix/edits.rs b/crates/ruff_linter/src/fix/edits.rs similarity index 98% rename from crates/ruff_linter/src/autofix/edits.rs rename to crates/ruff_linter/src/fix/edits.rs index e11d8a53e6719..2698b64209871 100644 --- a/crates/ruff_linter/src/autofix/edits.rs +++ b/crates/ruff_linter/src/fix/edits.rs @@ -1,4 +1,4 @@ -//! Interface for generating autofix edits from higher-level actions (e.g., "remove an argument"). +//! Interface for generating fix edits from higher-level actions (e.g., "remove an argument"). use anyhow::{Context, Result}; @@ -12,7 +12,7 @@ use ruff_python_trivia::{ use ruff_source_file::{Locator, NewlineWithTrailingNewline}; use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; -use crate::autofix::codemods; +use crate::fix::codemods; /// Return the `Fix` to use when deleting a `Stmt`. /// @@ -293,7 +293,7 @@ mod tests { use ruff_source_file::Locator; use ruff_text_size::{Ranged, TextSize}; - use crate::autofix::edits::{next_stmt_break, trailing_semicolon}; + use crate::fix::edits::{next_stmt_break, trailing_semicolon}; #[test] fn find_semicolon() -> Result<()> { diff --git a/crates/ruff_linter/src/autofix/mod.rs b/crates/ruff_linter/src/fix/mod.rs similarity index 99% rename from crates/ruff_linter/src/autofix/mod.rs rename to crates/ruff_linter/src/fix/mod.rs index 6e33cb99a1ed5..563fac9e8396c 100644 --- a/crates/ruff_linter/src/autofix/mod.rs +++ b/crates/ruff_linter/src/fix/mod.rs @@ -141,7 +141,7 @@ mod tests { use ruff_diagnostics::{Diagnostic, Edit, Fix, SourceMarker}; use ruff_source_file::Locator; - use crate::autofix::{apply_fixes, FixResult}; + use crate::fix::{apply_fixes, FixResult}; use crate::rules::pycodestyle::rules::MissingNewlineAtEndOfFile; #[allow(deprecated)] diff --git a/crates/ruff_linter/src/autofix/snippet.rs b/crates/ruff_linter/src/fix/snippet.rs similarity index 100% rename from crates/ruff_linter/src/autofix/snippet.rs rename to crates/ruff_linter/src/fix/snippet.rs diff --git a/crates/ruff_linter/src/importer/mod.rs b/crates/ruff_linter/src/importer/mod.rs index c01884db56399..5241aa4f4c8d3 100644 --- a/crates/ruff_linter/src/importer/mod.rs +++ b/crates/ruff_linter/src/importer/mod.rs @@ -17,9 +17,9 @@ use ruff_python_semantic::SemanticModel; use ruff_python_trivia::textwrap::indent; use ruff_source_file::Locator; -use crate::autofix; -use crate::autofix::codemods::CodegenStylist; use crate::cst::matchers::{match_aliases, match_import_from, match_statement}; +use crate::fix; +use crate::fix::codemods::CodegenStylist; use crate::importer::insertion::Insertion; mod insertion; @@ -91,7 +91,7 @@ impl<'a> Importer<'a> { at: TextSize, ) -> Result { // Generate the modified import statement. - let content = autofix::codemods::retain_imports( + let content = fix::codemods::retain_imports( &import.names, import.statement, self.locator, @@ -124,7 +124,7 @@ impl<'a> Importer<'a> { source_type: PySourceType, ) -> Result { // Generate the modified import statement. - let content = autofix::codemods::retain_imports( + let content = fix::codemods::retain_imports( &import.names, import.statement, self.locator, diff --git a/crates/ruff_linter/src/lib.rs b/crates/ruff_linter/src/lib.rs index ee8f238879da8..857c7fadae5fc 100644 --- a/crates/ruff_linter/src/lib.rs +++ b/crates/ruff_linter/src/lib.rs @@ -14,7 +14,6 @@ pub use rules::pycodestyle::rules::{IOError, SyntaxError}; pub const VERSION: &str = env!("CARGO_PKG_VERSION"); -mod autofix; mod checkers; pub mod codes; mod comments; @@ -22,6 +21,7 @@ mod cst; pub mod directives; mod doc_lines; mod docstrings; +mod fix; pub mod fs; mod importer; mod lex; diff --git a/crates/ruff_linter/src/linter.rs b/crates/ruff_linter/src/linter.rs index f07e3d3f0781a..7178409f10252 100644 --- a/crates/ruff_linter/src/linter.rs +++ b/crates/ruff_linter/src/linter.rs @@ -18,7 +18,6 @@ use ruff_python_parser::{AsMode, ParseError}; use ruff_source_file::{Locator, SourceFileBuilder}; use ruff_text_size::Ranged; -use crate::autofix::{fix_file, FixResult}; use crate::checkers::ast::check_ast; use crate::checkers::filesystem::check_file_path; use crate::checkers::imports::check_imports; @@ -27,6 +26,7 @@ use crate::checkers::physical_lines::check_physical_lines; use crate::checkers::tokens::check_tokens; use crate::directives::Directives; use crate::doc_lines::{doc_lines_from_ast, doc_lines_from_tokens}; +use crate::fix::{fix_file, FixResult}; use crate::logging::DisplayParseError; use crate::message::Message; use crate::noqa::add_noqa; @@ -412,7 +412,7 @@ fn diagnostics_to_messages( .collect() } -/// Generate `Diagnostic`s from source code content, iteratively autofixing +/// Generate `Diagnostic`s from source code content, iteratively fixing /// until stable. pub fn lint_fix<'a>( path: &Path, @@ -433,7 +433,7 @@ pub fn lint_fix<'a>( // Track whether the _initial_ source code was parseable. let mut parseable = false; - // Continuously autofix until the source code stabilizes. + // Continuously fix until the source code stabilizes. loop { // Tokenize once. let tokens: Vec = @@ -478,17 +478,17 @@ pub fn lint_fix<'a>( // longer parseable on a subsequent pass, then we've introduced a // syntax error. Return the original code. if parseable && result.error.is_some() { - report_autofix_syntax_error( + report_fix_syntax_error( path, transformed.source_code(), &result.error.unwrap(), fixed.keys().copied(), ); - return Err(anyhow!("Autofix introduced a syntax error")); + return Err(anyhow!("Fix introduced a syntax error")); } } - // Apply autofix. + // Apply fix. if let Some(FixResult { code: fixed_contents, fixes: applied, @@ -569,7 +569,7 @@ This indicates a bug in Ruff. If you could open an issue at: } #[allow(clippy::print_stderr)] -fn report_autofix_syntax_error( +fn report_fix_syntax_error( path: &Path, transformed: &str, error: &ParseError, @@ -578,7 +578,7 @@ fn report_autofix_syntax_error( let codes = collect_rule_codes(rules); if cfg!(debug_assertions) { eprintln!( - "{}{} Autofix introduced a syntax error in `{}` with rule codes {}: {}\n---\n{}\n---", + "{}{} Fix introduced a syntax error in `{}` with rule codes {}: {}\n---\n{}\n---", "error".red().bold(), ":".bold(), fs::relativize_path(path), @@ -589,11 +589,11 @@ fn report_autofix_syntax_error( } else { eprintln!( r#" -{}{} Autofix introduced a syntax error. Reverting all changes. +{}{} Fix introduced a syntax error. Reverting all changes. This indicates a bug in Ruff. If you could open an issue at: - https://github.com/astral-sh/ruff/issues/new?title=%5BAutofix%20error%5D + https://github.com/astral-sh/ruff/issues/new?title=%5BFix%20error%5D ...quoting the contents of `{}`, the rule codes {}, along with the `pyproject.toml` settings and executed command, we'd be very appreciative! "#, diff --git a/crates/ruff_linter/src/message/text.rs b/crates/ruff_linter/src/message/text.rs index 5abc7fd268b76..ee22415d4a47a 100644 --- a/crates/ruff_linter/src/message/text.rs +++ b/crates/ruff_linter/src/message/text.rs @@ -143,9 +143,9 @@ impl Display for RuleCodeAndBody<'_> { if self.show_fix_status && self.message.fix.is_some() { write!( f, - "{code} {autofix}{body}", + "{code} {fix}{body}", code = kind.rule().noqa_code().to_string().red().bold(), - autofix = format_args!("[{}] ", "*".cyan()), + fix = format_args!("[{}] ", "*".cyan()), body = kind.body, ) } else { diff --git a/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs b/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs index 7c712f20a167e..fd6288fd75dfb 100644 --- a/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs +++ b/crates/ruff_linter/src/rules/eradicate/rules/commented_out_code.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_index::Indexer; use ruff_source_file::Locator; @@ -25,13 +25,13 @@ use super::super::detection::comment_contains_code; #[violation] pub struct CommentedOutCode; -impl AlwaysAutofixableViolation for CommentedOutCode { +impl AlwaysFixableViolation for CommentedOutCode { #[derive_message_formats] fn message(&self) -> String { format!("Found commented-out code") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove commented-out code".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs b/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs index f86e84830c8b6..37831ddc884b3 100644 --- a/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs +++ b/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::ReturnStatementVisitor; use ruff_python_ast::identifier::Identifier; @@ -287,14 +287,14 @@ pub struct MissingReturnTypeSpecialMethod { name: String, } -impl AlwaysAutofixableViolation for MissingReturnTypeSpecialMethod { +impl AlwaysFixableViolation for MissingReturnTypeSpecialMethod { #[derive_message_formats] fn message(&self) -> String { let MissingReturnTypeSpecialMethod { name } = self; format!("Missing return type annotation for special method `{name}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Add `None` return type".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs index 209a79d719895..3e2076a7faa72 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, Stmt}; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_const_false; @@ -33,13 +33,13 @@ use crate::registry::AsRule; #[violation] pub struct AssertFalse; -impl AlwaysAutofixableViolation for AssertFalse { +impl AlwaysFixableViolation for AssertFalse { #[derive_message_formats] fn message(&self) -> String { format!("Do not `assert False` (`python -O` removes these calls), raise `AssertionError()`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace `assert False`".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs index b8daa83ffc705..ca2702757c636 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs @@ -3,7 +3,7 @@ use ruff_python_ast::{self as ast, ExceptHandler, Expr, ExprContext}; use ruff_text_size::{Ranged, TextRange}; use rustc_hash::{FxHashMap, FxHashSet}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path; @@ -86,7 +86,7 @@ pub struct DuplicateHandlerException { pub names: Vec, } -impl AlwaysAutofixableViolation for DuplicateHandlerException { +impl AlwaysFixableViolation for DuplicateHandlerException { #[derive_message_formats] fn message(&self) -> String { let DuplicateHandlerException { names } = self; @@ -98,7 +98,7 @@ impl AlwaysAutofixableViolation for DuplicateHandlerException { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "De-duplicate exceptions".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs index 99097b4137d10..2a902ec414ff8 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/getattr_with_constant.rs @@ -1,5 +1,5 @@ -use crate::autofix::edits::pad; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use crate::fix::edits::pad; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Constant, Expr}; use ruff_python_stdlib::identifiers::{is_identifier, is_mangled_private}; @@ -34,7 +34,7 @@ use crate::registry::AsRule; #[violation] pub struct GetAttrWithConstant; -impl AlwaysAutofixableViolation for GetAttrWithConstant { +impl AlwaysFixableViolation for GetAttrWithConstant { #[derive_message_formats] fn message(&self) -> String { format!( @@ -43,7 +43,7 @@ impl AlwaysAutofixableViolation for GetAttrWithConstant { ) } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace `getattr` with attribute access".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs index f604d18d0c887..d267969bb9d73 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/mutable_argument_default.rs @@ -1,5 +1,5 @@ use ast::call_path::{from_qualified_name, CallPath}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_docstring_stmt; use ruff_python_ast::{self as ast, Expr, Parameter, ParameterWithDefault}; @@ -64,14 +64,14 @@ use crate::registry::AsRule; pub struct MutableArgumentDefault; impl Violation for MutableArgumentDefault { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Do not use mutable data structures for argument defaults") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some(format!("Replace with `None`; initialize within function")) } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs index cabcd9b55843d..afe698dca9279 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/redundant_tuple_in_exception_handler.rs @@ -1,11 +1,11 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::map_starred; use ruff_python_ast::{self as ast, ExceptHandler, Expr}; use ruff_text_size::Ranged; -use crate::autofix::edits::pad; use crate::checkers::ast::Checker; +use crate::fix::edits::pad; use crate::registry::AsRule; /// ## What it does @@ -39,13 +39,13 @@ pub struct RedundantTupleInExceptionHandler { name: String, } -impl AlwaysAutofixableViolation for RedundantTupleInExceptionHandler { +impl AlwaysFixableViolation for RedundantTupleInExceptionHandler { #[derive_message_formats] fn message(&self) -> String { format!("A length-one tuple literal is redundant in exception handlers") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let RedundantTupleInExceptionHandler { name } = self; format!("Replace with `except {name}`") } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs index 5dfbd8d2aa02b..5f70ada572d39 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Constant, Expr, ExprContext, Identifier, Stmt}; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_codegen::Generator; use ruff_python_stdlib::identifiers::{is_identifier, is_mangled_private}; @@ -34,7 +34,7 @@ use crate::registry::AsRule; #[violation] pub struct SetAttrWithConstant; -impl AlwaysAutofixableViolation for SetAttrWithConstant { +impl AlwaysFixableViolation for SetAttrWithConstant { #[derive_message_formats] fn message(&self) -> String { format!( @@ -43,7 +43,7 @@ impl AlwaysAutofixableViolation for SetAttrWithConstant { ) } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace `setattr` with assignment".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs index 0ab04c3e60387..37941c9e7cf4e 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unreliable_callable_check.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{self as ast, Constant, Expr}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -37,7 +37,7 @@ use crate::registry::AsRule; pub struct UnreliableCallableCheck; impl Violation for UnreliableCallableCheck { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -47,7 +47,7 @@ impl Violation for UnreliableCallableCheck { ) } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some(format!("Replace with `callable()`")) } } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs index b2a40527b4a2a..0bfca2726113b 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/unused_loop_control_variable.rs @@ -1,6 +1,6 @@ use rustc_hash::FxHashMap; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::visitor::Visitor; use ruff_python_ast::{self as ast, Expr}; @@ -56,7 +56,7 @@ pub struct UnusedLoopControlVariable { } impl Violation for UnusedLoopControlVariable { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -70,7 +70,7 @@ impl Violation for UnusedLoopControlVariable { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let UnusedLoopControlVariable { rename, name, .. } = self; rename diff --git a/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs b/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs index 3b79acf051e86..eb9f1ec40e53c 100644 --- a/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs +++ b/crates/ruff_linter/src/rules/flake8_commas/rules/trailing_commas.rs @@ -1,6 +1,6 @@ use itertools::Itertools; -use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_parser::lexer::{LexResult, Spanned}; @@ -138,13 +138,13 @@ impl Context { #[violation] pub struct MissingTrailingComma; -impl AlwaysAutofixableViolation for MissingTrailingComma { +impl AlwaysFixableViolation for MissingTrailingComma { #[derive_message_formats] fn message(&self) -> String { format!("Trailing comma missing") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Add trailing comma".to_string() } } @@ -209,13 +209,13 @@ impl Violation for TrailingCommaOnBareTuple { #[violation] pub struct ProhibitedTrailingComma; -impl AlwaysAutofixableViolation for ProhibitedTrailingComma { +impl AlwaysFixableViolation for ProhibitedTrailingComma { #[derive_message_formats] fn message(&self) -> String { format!("Trailing comma prohibited") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove trailing comma".to_string() } } @@ -361,7 +361,7 @@ pub(crate) fn trailing_commas( ); if settings.rules.should_fix(Rule::MissingTrailingComma) { // Create a replacement that includes the final bracket (or other token), - // rather than just inserting a comma at the end. This prevents the UP034 autofix + // rather than just inserting a comma at the end. This prevents the UP034 fix // removing any brackets in the same linter pass - doing both at the same time could // lead to a syntax error. let contents = locator.slice(missing_comma.1); diff --git a/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__COM81.py.snap b/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__COM81.py.snap index 0fa18c2cea99b..fe61754579e6a 100644 --- a/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__COM81.py.snap +++ b/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__COM81.py.snap @@ -917,11 +917,11 @@ COM81.py:627:20: COM812 [*] Trailing comma missing 627 |+ **{'ham': spam}, 628 628 | ) 629 629 | -630 630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error. +630 630 | # Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error. COM81.py:632:42: COM812 [*] Trailing comma missing | -630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error. +630 | # Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error. 631 | the_first_one = next( 632 | (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket | COM812 @@ -931,7 +931,7 @@ COM81.py:632:42: COM812 [*] Trailing comma missing ℹ Fix 629 629 | -630 630 | # Make sure the COM812 and UP034 rules don't autofix simultaneously and cause a syntax error. +630 630 | # Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error. 631 631 | the_first_one = next( 632 |- (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket 632 |+ (i for i in range(10) if i // 2 == 0), # COM812 fix should include the final bracket diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs index 6ede08874185e..2900d9353e000 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/fixes.rs @@ -15,9 +15,9 @@ use ruff_python_semantic::SemanticModel; use ruff_source_file::Locator; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix::codemods::CodegenStylist; -use crate::autofix::edits::pad; use crate::cst::helpers::{negate, space}; +use crate::fix::codemods::CodegenStylist; +use crate::fix::edits::pad; use crate::rules::flake8_comprehensions::rules::ObjectType; use crate::{ checkers::ast::Checker, diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs index bc233cc6651fe..5738ef49b867f 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_call_around_sorted.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -35,14 +35,14 @@ pub struct UnnecessaryCallAroundSorted { func: String, } -impl AlwaysAutofixableViolation for UnnecessaryCallAroundSorted { +impl AlwaysFixableViolation for UnnecessaryCallAroundSorted { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryCallAroundSorted { func } = self; format!("Unnecessary `{func}` call around `sorted()`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let UnnecessaryCallAroundSorted { func } = self; format!("Remove unnecessary `{func}` call") } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs index 01e6e0b38388b..7848fedb12bfe 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_collection_call.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{Expr, Keyword}; use ruff_text_size::Ranged; @@ -37,14 +37,14 @@ pub struct UnnecessaryCollectionCall { obj_type: String, } -impl AlwaysAutofixableViolation for UnnecessaryCollectionCall { +impl AlwaysFixableViolation for UnnecessaryCollectionCall { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryCollectionCall { obj_type } = self; format!("Unnecessary `{obj_type}` call (rewrite as a literal)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Rewrite as a literal".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs index a31ed5fa92d15..18a52b10ceae6 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::{self as ast, Comprehension, Expr}; @@ -34,14 +34,14 @@ pub struct UnnecessaryComprehension { obj_type: String, } -impl AlwaysAutofixableViolation for UnnecessaryComprehension { +impl AlwaysFixableViolation for UnnecessaryComprehension { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryComprehension { obj_type } = self; format!("Unnecessary `{obj_type}` comprehension (rewrite using `{obj_type}()`)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let UnnecessaryComprehension { obj_type } = self; format!("Rewrite using `{obj_type}()`") } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs index d50a5de057414..8655186b4f97a 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_comprehension_any_all.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr, Keyword}; use ruff_diagnostics::Violation; -use ruff_diagnostics::{AutofixKind, Diagnostic}; +use ruff_diagnostics::{Diagnostic, FixKind}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::any_over_expr; use ruff_text_size::Ranged; @@ -44,14 +44,14 @@ use crate::rules::flake8_comprehensions::fixes; pub struct UnnecessaryComprehensionAnyAll; impl Violation for UnnecessaryComprehensionAnyAll { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary list comprehension.") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Remove unnecessary list comprehension".to_string()) } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs index bb4922afd46eb..94ddb8861188e 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_double_cast_or_process.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::ComparableKeyword; use ruff_python_ast::{self as ast, Arguments, Expr, Keyword}; @@ -49,14 +49,14 @@ pub struct UnnecessaryDoubleCastOrProcess { outer: String, } -impl AlwaysAutofixableViolation for UnnecessaryDoubleCastOrProcess { +impl AlwaysFixableViolation for UnnecessaryDoubleCastOrProcess { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryDoubleCastOrProcess { inner, outer } = self; format!("Unnecessary `{inner}` call within `{outer}()`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let UnnecessaryDoubleCastOrProcess { inner, .. } = self; format!("Remove the inner `{inner}` call") } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs index e507c77a1f93a..820444f737890 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_dict.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr, Keyword}; use ruff_text_size::Ranged; @@ -30,13 +30,13 @@ use super::helpers; #[violation] pub struct UnnecessaryGeneratorDict; -impl AlwaysAutofixableViolation for UnnecessaryGeneratorDict { +impl AlwaysFixableViolation for UnnecessaryGeneratorDict { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary generator (rewrite as a `dict` comprehension)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Rewrite as a `dict` comprehension".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs index 8c8b43591e53d..a15912dfe2493 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_list.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{Expr, Keyword}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -31,13 +31,13 @@ use super::helpers; #[violation] pub struct UnnecessaryGeneratorList; -impl AlwaysAutofixableViolation for UnnecessaryGeneratorList { +impl AlwaysFixableViolation for UnnecessaryGeneratorList { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary generator (rewrite as a `list` comprehension)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Rewrite as a `list` comprehension".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs index d4fd13c33e2d7..7a76389c22973 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_generator_set.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{Expr, Keyword}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -31,13 +31,13 @@ use super::helpers; #[violation] pub struct UnnecessaryGeneratorSet; -impl AlwaysAutofixableViolation for UnnecessaryGeneratorSet { +impl AlwaysFixableViolation for UnnecessaryGeneratorSet { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary generator (rewrite as a `set` comprehension)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Rewrite as a `set` comprehension".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs index 1f4cf31a830cd..0e7599475677f 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_call.rs @@ -1,6 +1,6 @@ use ruff_python_ast::Expr; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -28,13 +28,13 @@ use super::helpers; #[violation] pub struct UnnecessaryListCall; -impl AlwaysAutofixableViolation for UnnecessaryListCall { +impl AlwaysFixableViolation for UnnecessaryListCall { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary `list` call (remove the outer call to `list()`)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove outer `list` call".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs index e92d5b6663d12..ce308b1f8a928 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_dict.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr, Keyword}; use ruff_text_size::Ranged; @@ -28,13 +28,13 @@ use super::helpers; #[violation] pub struct UnnecessaryListComprehensionDict; -impl AlwaysAutofixableViolation for UnnecessaryListComprehensionDict { +impl AlwaysFixableViolation for UnnecessaryListComprehensionDict { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary `list` comprehension (rewrite as a `dict` comprehension)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Rewrite as a `dict` comprehension".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs index 34e775fc39407..796319293d7d7 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_list_comprehension_set.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{Expr, Keyword}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -29,13 +29,13 @@ use super::helpers; #[violation] pub struct UnnecessaryListComprehensionSet; -impl AlwaysAutofixableViolation for UnnecessaryListComprehensionSet { +impl AlwaysFixableViolation for UnnecessaryListComprehensionSet { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary `list` comprehension (rewrite as a `set` comprehension)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Rewrite as a `set` comprehension".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs index 36403f70c6bf3..80d7d48ef58d2 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_dict.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr, Keyword}; use ruff_text_size::Ranged; @@ -34,14 +34,14 @@ pub struct UnnecessaryLiteralDict { obj_type: String, } -impl AlwaysAutofixableViolation for UnnecessaryLiteralDict { +impl AlwaysFixableViolation for UnnecessaryLiteralDict { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryLiteralDict { obj_type } = self; format!("Unnecessary `{obj_type}` literal (rewrite as a `dict` literal)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Rewrite as a `dict` literal".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs index 2d22f0b804a57..facf6a9de5c5c 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_set.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{Expr, Keyword}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -36,14 +36,14 @@ pub struct UnnecessaryLiteralSet { obj_type: String, } -impl AlwaysAutofixableViolation for UnnecessaryLiteralSet { +impl AlwaysFixableViolation for UnnecessaryLiteralSet { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryLiteralSet { obj_type } = self; format!("Unnecessary `{obj_type}` literal (rewrite as a `set` literal)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Rewrite as a `set` literal".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs index 5ee01a75276c2..7e01ea03c18d7 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_dict_call.rs @@ -2,7 +2,7 @@ use std::fmt; use ruff_python_ast::{Expr, Keyword}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -51,14 +51,14 @@ pub struct UnnecessaryLiteralWithinDictCall { kind: DictKind, } -impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinDictCall { +impl AlwaysFixableViolation for UnnecessaryLiteralWithinDictCall { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryLiteralWithinDictCall { kind } = self; format!("Unnecessary `dict` {kind} passed to `dict()` (remove the outer call to `dict()`)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove outer `dict` call".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs index f6810ad4468e2..8d90154080942 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_list_call.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{Expr, Keyword}; use ruff_text_size::Ranged; @@ -37,7 +37,7 @@ pub struct UnnecessaryLiteralWithinListCall { literal: String, } -impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinListCall { +impl AlwaysFixableViolation for UnnecessaryLiteralWithinListCall { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryLiteralWithinListCall { literal } = self; @@ -53,7 +53,7 @@ impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinListCall { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let UnnecessaryLiteralWithinListCall { literal } = self; { if literal == "list" { diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs index 83ae8d141093d..6bc002ca171f2 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_literal_within_tuple_call.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{Expr, Keyword}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -38,7 +38,7 @@ pub struct UnnecessaryLiteralWithinTupleCall { literal: String, } -impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinTupleCall { +impl AlwaysFixableViolation for UnnecessaryLiteralWithinTupleCall { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryLiteralWithinTupleCall { literal } = self; @@ -55,7 +55,7 @@ impl AlwaysAutofixableViolation for UnnecessaryLiteralWithinTupleCall { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let UnnecessaryLiteralWithinTupleCall { literal } = self; { if literal == "list" { diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs index 2dd0fa0025656..463588b81034c 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_map.rs @@ -1,7 +1,7 @@ use std::fmt; -use ruff_diagnostics::{AutofixKind, Violation}; use ruff_diagnostics::{Diagnostic, Fix}; +use ruff_diagnostics::{FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::visitor; use ruff_python_ast::visitor::Visitor; @@ -47,7 +47,7 @@ pub struct UnnecessaryMap { } impl Violation for UnnecessaryMap { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -55,7 +55,7 @@ impl Violation for UnnecessaryMap { format!("Unnecessary `map` usage (rewrite using a {object_type})") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let UnnecessaryMap { object_type } = self; Some(format!("Replace `map` with a {object_type}")) } diff --git a/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs b/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs index d3668322a1aac..02b4e004554ad 100644 --- a/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_errmsg/rules/string_in_exception.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Arguments, Constant, Expr, ExprContext, Stmt}; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::whitespace; use ruff_python_codegen::{Generator, Stylist}; @@ -50,14 +50,14 @@ use crate::registry::{AsRule, Rule}; pub struct RawStringInException; impl Violation for RawStringInException { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Exception must not use a string literal, assign to variable first") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Assign to variable; remove string literal".to_string()) } } @@ -104,14 +104,14 @@ impl Violation for RawStringInException { pub struct FStringInException; impl Violation for FStringInException { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Exception must not use an f-string literal, assign to variable first") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Assign to variable; remove f-string literal".to_string()) } } @@ -160,14 +160,14 @@ impl Violation for FStringInException { pub struct DotFormatInException; impl Violation for DotFormatInException { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Exception must not use a `.format()` string directly, assign to variable first") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Assign to variable; remove `.format()` string".to_string()) } } diff --git a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs index 7055a3061e192..bd6dcac142a72 100644 --- a/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs +++ b/crates/ruff_linter/src/rules/flake8_executable/rules/shebang_leading_whitespace.rs @@ -1,6 +1,6 @@ use ruff_text_size::{TextRange, TextSize}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_trivia::is_python_whitespace; use ruff_source_file::Locator; @@ -35,13 +35,13 @@ use crate::settings::LinterSettings; #[violation] pub struct ShebangLeadingWhitespace; -impl AlwaysAutofixableViolation for ShebangLeadingWhitespace { +impl AlwaysFixableViolation for ShebangLeadingWhitespace { #[derive_message_formats] fn message(&self) -> String { format!("Avoid whitespace before shebang") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Remove whitespace before shebang") } } diff --git a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs index 0a2e381a55a9a..3d6394a958d35 100644 --- a/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs +++ b/crates/ruff_linter/src/rules/flake8_implicit_str_concat/rules/implicit.rs @@ -2,7 +2,7 @@ use itertools::Itertools; use ruff_python_parser::lexer::LexResult; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::str::{leading_quote, trailing_quote}; use ruff_source_file::Locator; @@ -34,14 +34,14 @@ use crate::rules::flake8_implicit_str_concat::settings::Settings; pub struct SingleLineImplicitStringConcatenation; impl Violation for SingleLineImplicitStringConcatenation { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Implicitly concatenated string literals on one line") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Combine string literals".to_string()) } } diff --git a/crates/ruff_linter/src/rules/flake8_import_conventions/rules/unconventional_import_alias.rs b/crates/ruff_linter/src/rules/flake8_import_conventions/rules/unconventional_import_alias.rs index 4fb54aa1c531a..6de3466e871bf 100644 --- a/crates/ruff_linter/src/rules/flake8_import_conventions/rules/unconventional_import_alias.rs +++ b/crates/ruff_linter/src/rules/flake8_import_conventions/rules/unconventional_import_alias.rs @@ -1,6 +1,6 @@ use rustc_hash::FxHashMap; -use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::{Binding, Imported}; use ruff_text_size::Ranged; @@ -37,7 +37,7 @@ pub struct UnconventionalImportAlias { } impl Violation for UnconventionalImportAlias { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -45,7 +45,7 @@ impl Violation for UnconventionalImportAlias { format!("`{name}` should be imported as `{asname}`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let UnconventionalImportAlias { name, asname } = self; Some(format!("Alias `{name}` to `{asname}`")) } diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs index c0c2893e736da..7833ffb620ff7 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/direct_logger_instantiation.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast as ast; use ruff_text_size::Ranged; @@ -41,14 +41,14 @@ use crate::registry::AsRule; pub struct DirectLoggerInstantiation; impl Violation for DirectLoggerInstantiation { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use `logging.getLogger()` to instantiate loggers") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some(format!("Replace with `logging.getLogger()`")) } } diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs index 80f3b2bc62833..a2c0a214dd675 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/invalid_get_logger_argument.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -44,14 +44,14 @@ use crate::registry::AsRule; pub struct InvalidGetLoggerArgument; impl Violation for InvalidGetLoggerArgument { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use `__name__` with `logging.getLogger()`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some(format!("Replace with `__name__`")) } } diff --git a/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs b/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs index d09b32da891d9..2a28142aea0d7 100644 --- a/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs +++ b/crates/ruff_linter/src/rules/flake8_logging/rules/undocumented_warn.rs @@ -1,6 +1,6 @@ use ruff_python_ast::Expr; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -36,13 +36,13 @@ use crate::registry::AsRule; pub struct UndocumentedWarn; impl Violation for UndocumentedWarn { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use of undocumented `logging.WARN` constant") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some(format!("Replace `logging.WARN` with `logging.WARNING`")) } } diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs b/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs index 77a96c7fce53f..114a1fa68a538 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs +++ b/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_macros::{derive_message_formats, violation}; /// ## What it does @@ -376,13 +376,13 @@ impl Violation for LoggingFString { #[violation] pub struct LoggingWarn; -impl AlwaysAutofixableViolation for LoggingWarn { +impl AlwaysFixableViolation for LoggingWarn { #[derive_message_formats] fn message(&self) -> String { format!("Logging statement uses `warn` instead of `warning`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Convert to `warn`".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs index 07c49fcd41529..eba237f90c6df 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/duplicate_class_field_definition.rs @@ -1,13 +1,13 @@ use rustc_hash::FxHashSet; use ruff_diagnostics::Diagnostic; -use ruff_diagnostics::{AlwaysAutofixableViolation, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_text_size::Ranged; -use crate::autofix; use crate::checkers::ast::Checker; +use crate::fix; use crate::registry::AsRule; /// ## What it does @@ -36,14 +36,14 @@ pub struct DuplicateClassFieldDefinition { name: String, } -impl AlwaysAutofixableViolation for DuplicateClassFieldDefinition { +impl AlwaysFixableViolation for DuplicateClassFieldDefinition { #[derive_message_formats] fn message(&self) -> String { let DuplicateClassFieldDefinition { name } = self; format!("Class field `{name}` is defined multiple times") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let DuplicateClassFieldDefinition { name } = self; format!("Remove duplicate field definition for `{name}`") } @@ -80,12 +80,8 @@ pub(crate) fn duplicate_class_field_definition(checker: &mut Checker, body: &[St stmt.range(), ); if checker.patch(diagnostic.kind.rule()) { - let edit = autofix::edits::delete_stmt( - stmt, - Some(stmt), - checker.locator(), - checker.indexer(), - ); + let edit = + fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer()); diagnostic.set_fix(Fix::suggested(edit).isolate(Checker::isolation(Some( checker.semantic().current_statement_id(), )))); diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs index 9a1f55194d537..4ab05a1e70d37 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs @@ -7,7 +7,7 @@ use ruff_text_size::{Ranged, TextRange}; use ruff_python_ast::{self as ast, Arguments, BoolOp, Expr, ExprContext, Identifier}; -use ruff_diagnostics::AlwaysAutofixableViolation; +use ruff_diagnostics::AlwaysFixableViolation; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; @@ -45,14 +45,14 @@ pub struct MultipleStartsEndsWith { attr: String, } -impl AlwaysAutofixableViolation for MultipleStartsEndsWith { +impl AlwaysFixableViolation for MultipleStartsEndsWith { #[derive_message_formats] fn message(&self) -> String { let MultipleStartsEndsWith { attr } = self; format!("Call `{attr}` once with a `tuple`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let MultipleStartsEndsWith { attr } = self; format!("Merge into a single `{attr}` call") } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/no_unnecessary_pass.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/no_unnecessary_pass.rs index 569c8a66d87a4..bcc54da6e152f 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/no_unnecessary_pass.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/no_unnecessary_pass.rs @@ -1,14 +1,14 @@ use ruff_python_ast::Stmt; -use ruff_diagnostics::AlwaysAutofixableViolation; +use ruff_diagnostics::AlwaysFixableViolation; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_docstring_stmt; use ruff_python_ast::whitespace::trailing_comment_start_offset; use ruff_text_size::Ranged; -use crate::autofix; use crate::checkers::ast::Checker; +use crate::fix; use crate::registry::AsRule; /// ## What it does @@ -38,13 +38,13 @@ use crate::registry::AsRule; #[violation] pub struct UnnecessaryPass; -impl AlwaysAutofixableViolation for UnnecessaryPass { +impl AlwaysFixableViolation for UnnecessaryPass { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary `pass` statement") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove unnecessary `pass`".to_string() } } @@ -70,7 +70,7 @@ pub(crate) fn no_unnecessary_pass(checker: &mut Checker, body: &[Stmt]) { let edit = if let Some(index) = trailing_comment_start_offset(second, checker.locator()) { Edit::range_deletion(second.range().add_end(index)) } else { - autofix::edits::delete_stmt(second, None, checker.locator(), checker.indexer()) + fix::edits::delete_stmt(second, None, checker.locator(), checker.indexer()) }; diagnostic.set_fix(Fix::automatic(edit)); } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs index 3903b7cfe6027..9866b91db6f99 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_list_builtin.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr, ExprLambda}; -use ruff_diagnostics::{AutofixKind, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; +use ruff_diagnostics::{FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -40,14 +40,14 @@ use crate::registry::AsRule; pub struct ReimplementedListBuiltin; impl Violation for ReimplementedListBuiltin { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Prefer `list` over useless lambda") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Replace with `list`".to_string()) } } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs index a6275ac602644..71b41499d6d16 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_range_start.rs @@ -1,13 +1,13 @@ use num_bigint::BigInt; use ruff_diagnostics::Diagnostic; -use ruff_diagnostics::{AlwaysAutofixableViolation, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Constant, Expr}; use ruff_text_size::Ranged; -use crate::autofix::edits::{remove_argument, Parentheses}; use crate::checkers::ast::Checker; +use crate::fix::edits::{remove_argument, Parentheses}; use crate::registry::AsRule; /// ## What it does @@ -33,13 +33,13 @@ use crate::registry::AsRule; #[violation] pub struct UnnecessaryRangeStart; -impl AlwaysAutofixableViolation for UnnecessaryRangeStart { +impl AlwaysFixableViolation for UnnecessaryRangeStart { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary `start` argument in `range`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Remove `start` argument") } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs index d26879e414b77..2230fb1bc7395 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/any_eq_ne_annotation.rs @@ -1,6 +1,6 @@ use ruff_python_ast::Parameters; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -41,14 +41,14 @@ pub struct AnyEqNeAnnotation { method_name: String, } -impl AlwaysAutofixableViolation for AnyEqNeAnnotation { +impl AlwaysFixableViolation for AnyEqNeAnnotation { #[derive_message_formats] fn message(&self) -> String { let AnyEqNeAnnotation { method_name } = self; format!("Prefer `object` to `Any` for the second parameter to `{method_name}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Replace with `object`") } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs index 6166d1aee1bad..b045a443746e6 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/collections_named_tuple.rs @@ -43,7 +43,7 @@ impl Violation for CollectionsNamedTuple { format!("Use `typing.NamedTuple` instead of `collections.namedtuple`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some(format!("Replace with `typing.NamedTuple`")) } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs index c36c4f5a51f78..c87f96dde063d 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs @@ -5,7 +5,7 @@ use std::collections::HashSet; use crate::checkers::ast::Checker; use crate::registry::AsRule; use crate::rules::flake8_pyi::helpers::traverse_union; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::ComparableExpr; use ruff_text_size::Ranged; @@ -34,14 +34,14 @@ pub struct DuplicateUnionMember { } impl Violation for DuplicateUnionMember { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Duplicate union member `{}`", self.duplicate_name) } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some(format!( "Remove duplicate union member `{}`", self.duplicate_name diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs index c29b24697de53..d503c99b846ca 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/ellipsis_in_non_empty_class_body.rs @@ -1,10 +1,10 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{Constant, Expr, ExprConstant, Stmt, StmtExpr}; use ruff_text_size::Ranged; -use crate::autofix; use crate::checkers::ast::Checker; +use crate::fix; use crate::registry::AsRule; /// ## What it does @@ -31,14 +31,14 @@ use crate::registry::AsRule; pub struct EllipsisInNonEmptyClassBody; impl Violation for EllipsisInNonEmptyClassBody { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Non-empty class body must not contain `...`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Remove unnecessary `...`".to_string()) } } @@ -64,12 +64,8 @@ pub(crate) fn ellipsis_in_non_empty_class_body(checker: &mut Checker, body: &[St ) { let mut diagnostic = Diagnostic::new(EllipsisInNonEmptyClassBody, stmt.range()); if checker.patch(diagnostic.kind.rule()) { - let edit = autofix::edits::delete_stmt( - stmt, - Some(stmt), - checker.locator(), - checker.indexer(), - ); + let edit = + fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer()); diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(Some( checker.semantic().current_statement_id(), )))); diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs index 4add4c70abfc9..6c182e3db7041 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/exit_annotations.rs @@ -6,7 +6,7 @@ use ruff_python_ast::{ }; use smallvec::SmallVec; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_const_none; use ruff_python_semantic::SemanticModel; @@ -49,7 +49,7 @@ pub struct BadExitAnnotation { } impl Violation for BadExitAnnotation { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -65,7 +65,7 @@ impl Violation for BadExitAnnotation { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { if matches!(self.error_kind, ErrorKind::StarArgsNotAnnotated) { Some("Annotate star-args with `object`".to_string()) } else { diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs index 86f2a42ae8b71..ac9f1de1e6531 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_empty_stub_body.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_docstring_stmt; use ruff_python_ast::{self as ast, Expr, Stmt}; @@ -31,13 +31,13 @@ use crate::registry::Rule; #[violation] pub struct NonEmptyStubBody; -impl AlwaysAutofixableViolation for NonEmptyStubBody { +impl AlwaysFixableViolation for NonEmptyStubBody { #[derive_message_formats] fn message(&self) -> String { format!("Function body must contain only `...`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Replace function body with `...`") } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs index 0f251297cb6f1..ad8902dd46570 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rs @@ -104,7 +104,7 @@ impl Violation for NonSelfReturnType { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Consider using `typing_extensions.Self` as return type".to_string()) } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs index 2eaaf64a27edb..de9293585d349 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/numeric_literal_too_long.rs @@ -1,7 +1,7 @@ use ruff_python_ast::Expr; use ruff_text_size::{Ranged, TextSize}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use crate::checkers::ast::Checker; @@ -30,13 +30,13 @@ pub struct NumericLiteralTooLong; /// ```python /// def foo(arg: int = ...) -> None: ... /// ``` -impl AlwaysAutofixableViolation for NumericLiteralTooLong { +impl AlwaysFixableViolation for NumericLiteralTooLong { #[derive_message_formats] fn message(&self) -> String { format!("Numeric literals with a string representation longer than ten characters are not permitted") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with `...`".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs index 81028788408b8..b6275313567d0 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_in_class_body.rs @@ -1,22 +1,22 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast}; use ruff_text_size::Ranged; -use crate::autofix; use crate::checkers::ast::Checker; +use crate::fix; use crate::registry::AsRule; #[violation] pub struct PassInClassBody; -impl AlwaysAutofixableViolation for PassInClassBody { +impl AlwaysFixableViolation for PassInClassBody { #[derive_message_formats] fn message(&self) -> String { format!("Class body must not contain `pass`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Remove unnecessary `pass`") } } @@ -36,7 +36,7 @@ pub(crate) fn pass_in_class_body(checker: &mut Checker, class_def: &ast::StmtCla let mut diagnostic = Diagnostic::new(PassInClassBody, stmt.range()); if checker.patch(diagnostic.kind.rule()) { let edit = - autofix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer()); + fix::edits::delete_stmt(stmt, Some(stmt), checker.locator(), checker.indexer()); diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(Some( checker.semantic().current_statement_id(), )))); diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs index 3dd8f13b868f0..71cce841b68ee 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/pass_statement_stub_body.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::Stmt; use ruff_text_size::Ranged; @@ -29,13 +29,13 @@ use crate::registry::Rule; #[violation] pub struct PassStatementStubBody; -impl AlwaysAutofixableViolation for PassStatementStubBody { +impl AlwaysFixableViolation for PassStatementStubBody { #[derive_message_formats] fn message(&self) -> String { format!("Empty body should contain `...`, not `pass`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Replace `pass` with `...`") } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs index 49e624735a1d6..871bb460c5005 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/quoted_annotation_in_stub.rs @@ -1,6 +1,6 @@ use ruff_text_size::TextRange; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use crate::checkers::ast::Checker; @@ -9,13 +9,13 @@ use crate::registry::Rule; #[violation] pub struct QuotedAnnotationInStub; -impl AlwaysAutofixableViolation for QuotedAnnotationInStub { +impl AlwaysFixableViolation for QuotedAnnotationInStub { #[derive_message_formats] fn message(&self) -> String { format!("Quoted annotations should not be included in stubs") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove quotes".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs index f486da3fd4cde..dcd080c66a5e6 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_literal_union.rs @@ -8,7 +8,7 @@ use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::SemanticModel; use ruff_text_size::Ranged; -use crate::autofix::snippet::SourceCodeSnippet; +use crate::fix::snippet::SourceCodeSnippet; use crate::{checkers::ast::Checker, rules::flake8_pyi::helpers::traverse_union}; /// ## What it does diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs index 9ca545ebc7744..356346def40f9 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path::CallPath; use ruff_python_ast::{ @@ -18,13 +18,13 @@ use crate::settings::types::PythonVersion; #[violation] pub struct TypedArgumentDefaultInStub; -impl AlwaysAutofixableViolation for TypedArgumentDefaultInStub { +impl AlwaysFixableViolation for TypedArgumentDefaultInStub { #[derive_message_formats] fn message(&self) -> String { format!("Only simple default values allowed for typed arguments") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace default value with `...`".to_string() } } @@ -32,13 +32,13 @@ impl AlwaysAutofixableViolation for TypedArgumentDefaultInStub { #[violation] pub struct ArgumentDefaultInStub; -impl AlwaysAutofixableViolation for ArgumentDefaultInStub { +impl AlwaysFixableViolation for ArgumentDefaultInStub { #[derive_message_formats] fn message(&self) -> String { format!("Only simple default values allowed for arguments") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace default value with `...`".to_string() } } @@ -46,13 +46,13 @@ impl AlwaysAutofixableViolation for ArgumentDefaultInStub { #[violation] pub struct AssignmentDefaultInStub; -impl AlwaysAutofixableViolation for AssignmentDefaultInStub { +impl AlwaysFixableViolation for AssignmentDefaultInStub { #[derive_message_formats] fn message(&self) -> String { format!("Only simple default values allowed for assignments") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace default value with `...`".to_string() } } @@ -131,7 +131,7 @@ pub struct TypeAliasWithoutAnnotation { value: String, } -impl AlwaysAutofixableViolation for TypeAliasWithoutAnnotation { +impl AlwaysFixableViolation for TypeAliasWithoutAnnotation { #[derive_message_formats] fn message(&self) -> String { let TypeAliasWithoutAnnotation { @@ -142,7 +142,7 @@ impl AlwaysAutofixableViolation for TypeAliasWithoutAnnotation { format!("Use `{module}.TypeAlias` for type alias, e.g., `{name}: TypeAlias = {value}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Add `TypeAlias` annotation".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs index 6676c9009e213..d4f98db0f75b9 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/str_or_repr_defined_in_stub.rs @@ -1,13 +1,13 @@ use ruff_python_ast as ast; use ruff_python_ast::Stmt; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::identifier::Identifier; use ruff_python_semantic::analyze::visibility::is_abstract; -use crate::autofix::edits::delete_stmt; use crate::checkers::ast::Checker; +use crate::fix::edits::delete_stmt; use crate::registry::AsRule; /// ## What it does @@ -29,14 +29,14 @@ pub struct StrOrReprDefinedInStub { name: String, } -impl AlwaysAutofixableViolation for StrOrReprDefinedInStub { +impl AlwaysFixableViolation for StrOrReprDefinedInStub { #[derive_message_formats] fn message(&self) -> String { let StrOrReprDefinedInStub { name } = self; format!("Defining `{name}` in a stub is almost always redundant") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let StrOrReprDefinedInStub { name } = self; format!("Remove definition of `{name}`") } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs index bbf20bda6273c..485dbe2b4b4dd 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{self as ast, Constant, Expr}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_docstring_stmt; use ruff_text_size::Ranged; @@ -30,13 +30,13 @@ pub struct StringOrBytesTooLong; /// ```python /// def foo(arg: str = ...) -> None: ... /// ``` -impl AlwaysAutofixableViolation for StringOrBytesTooLong { +impl AlwaysFixableViolation for StringOrBytesTooLong { #[derive_message_formats] fn message(&self) -> String { format!("String and bytes literals longer than 50 characters are not permitted") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with `...`".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unaliased_collections_abc_set_import.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unaliased_collections_abc_set_import.rs index 8ec902316e95a..fd36a49254ede 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unaliased_collections_abc_set_import.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unaliased_collections_abc_set_import.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::Imported; use ruff_python_semantic::{Binding, BindingKind}; @@ -33,7 +33,7 @@ use crate::renamer::Renamer; pub struct UnaliasedCollectionsAbcSetImport; impl Violation for UnaliasedCollectionsAbcSetImport { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -42,7 +42,7 @@ impl Violation for UnaliasedCollectionsAbcSetImport { ) } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some(format!("Alias `Set` to `AbstractSet`")) } } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs index b3de92653322d..3d51ed37bcfe3 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/assertion.rs @@ -7,7 +7,7 @@ use libcst_native::{ SimpleWhitespace, SmallStatement, Statement, TrailingWhitespace, }; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::Truthiness; use ruff_python_ast::parenthesize::parenthesized_range; @@ -20,11 +20,11 @@ use ruff_python_codegen::Stylist; use ruff_source_file::Locator; use ruff_text_size::Ranged; -use crate::autofix::codemods::CodegenStylist; use crate::checkers::ast::Checker; use crate::cst::helpers::negate; use crate::cst::matchers::match_indented_block; use crate::cst::matchers::match_module; +use crate::fix::codemods::CodegenStylist; use crate::importer::ImportRequest; use crate::registry::AsRule; @@ -62,14 +62,14 @@ use super::unittest_assert::UnittestAssert; pub struct PytestCompositeAssertion; impl Violation for PytestCompositeAssertion { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Assertion should be broken down into multiple parts") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Break down assertion into multiple parts".to_string()) } } @@ -192,7 +192,7 @@ pub struct PytestUnittestAssertion { } impl Violation for PytestUnittestAssertion { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -200,7 +200,7 @@ impl Violation for PytestUnittestAssertion { format!("Use a regular `assert` instead of unittest-style `{assertion}`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let PytestUnittestAssertion { assertion } = self; Some(format!("Replace `{assertion}(...)` with `assert ...`")) } @@ -354,7 +354,7 @@ pub struct PytestUnittestRaisesAssertion { } impl Violation for PytestUnittestRaisesAssertion { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -362,7 +362,7 @@ impl Violation for PytestUnittestRaisesAssertion { format!("Use `pytest.raises` instead of unittest-style `{assertion}`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let PytestUnittestRaisesAssertion { assertion } = self; Some(format!("Replace `{assertion}` with `pytest.raises`")) } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs index b3374ba07ee5d..c877e4f7ba92b 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/fixture.rs @@ -1,6 +1,6 @@ use std::fmt; -use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path::collect_call_path; @@ -14,8 +14,8 @@ use ruff_python_semantic::SemanticModel; use ruff_text_size::Ranged; use ruff_text_size::{TextLen, TextRange}; -use crate::autofix::edits; use crate::checkers::ast::Checker; +use crate::fix::edits; use crate::registry::{AsRule, Rule}; use super::helpers::{ @@ -65,14 +65,14 @@ pub struct PytestFixtureIncorrectParenthesesStyle { actual: Parentheses, } -impl AlwaysAutofixableViolation for PytestFixtureIncorrectParenthesesStyle { +impl AlwaysFixableViolation for PytestFixtureIncorrectParenthesesStyle { #[derive_message_formats] fn message(&self) -> String { let PytestFixtureIncorrectParenthesesStyle { expected, actual } = self; format!("Use `@pytest.fixture{expected}` over `@pytest.fixture{actual}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let PytestFixtureIncorrectParenthesesStyle { expected, .. } = self; match expected { Parentheses::None => "Remove parentheses".to_string(), @@ -154,13 +154,13 @@ impl Violation for PytestFixturePositionalArgs { #[violation] pub struct PytestExtraneousScopeFunction; -impl AlwaysAutofixableViolation for PytestExtraneousScopeFunction { +impl AlwaysFixableViolation for PytestExtraneousScopeFunction { #[derive_message_formats] fn message(&self) -> String { format!("`scope='function'` is implied in `@pytest.fixture()`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove implied `scope` argument".to_string() } } @@ -488,14 +488,14 @@ pub struct PytestUselessYieldFixture { name: String, } -impl AlwaysAutofixableViolation for PytestUselessYieldFixture { +impl AlwaysFixableViolation for PytestUselessYieldFixture { #[derive_message_formats] fn message(&self) -> String { let PytestUselessYieldFixture { name } = self; format!("No teardown in fixture `{name}`, use `return` instead of `yield`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace `yield` with `return`".to_string() } } @@ -543,13 +543,13 @@ impl AlwaysAutofixableViolation for PytestUselessYieldFixture { #[violation] pub struct PytestErroneousUseFixturesOnFixture; -impl AlwaysAutofixableViolation for PytestErroneousUseFixturesOnFixture { +impl AlwaysFixableViolation for PytestErroneousUseFixturesOnFixture { #[derive_message_formats] fn message(&self) -> String { format!("`pytest.mark.usefixtures` has no effect on fixtures") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove `pytest.mark.usefixtures`".to_string() } } @@ -586,13 +586,13 @@ impl AlwaysAutofixableViolation for PytestErroneousUseFixturesOnFixture { #[violation] pub struct PytestUnnecessaryAsyncioMarkOnFixture; -impl AlwaysAutofixableViolation for PytestUnnecessaryAsyncioMarkOnFixture { +impl AlwaysFixableViolation for PytestUnnecessaryAsyncioMarkOnFixture { #[derive_message_formats] fn message(&self) -> String { format!("`pytest.mark.asyncio` is unnecessary for fixtures") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove `pytest.mark.asyncio`".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs index 01a3d3fc60da4..f3aaef28433f9 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/marks.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{self as ast, Arguments, Decorator, Expr}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path::CallPath; use ruff_text_size::Ranged; @@ -54,7 +54,7 @@ pub struct PytestIncorrectMarkParenthesesStyle { actual_parens: String, } -impl AlwaysAutofixableViolation for PytestIncorrectMarkParenthesesStyle { +impl AlwaysFixableViolation for PytestIncorrectMarkParenthesesStyle { #[derive_message_formats] fn message(&self) -> String { let PytestIncorrectMarkParenthesesStyle { @@ -68,7 +68,7 @@ impl AlwaysAutofixableViolation for PytestIncorrectMarkParenthesesStyle { ) } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Add/remove parentheses".to_string() } } @@ -103,13 +103,13 @@ impl AlwaysAutofixableViolation for PytestIncorrectMarkParenthesesStyle { #[violation] pub struct PytestUseFixturesWithoutParameters; -impl AlwaysAutofixableViolation for PytestUseFixturesWithoutParameters { +impl AlwaysFixableViolation for PytestUseFixturesWithoutParameters { #[derive_message_formats] fn message(&self) -> String { format!("Useless `pytest.mark.usefixtures` without parameters") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove `usefixtures` decorator or pass parameters".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs index 293c4b8f08c75..dff1572afc187 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -2,7 +2,7 @@ use std::hash::BuildHasherDefault; use rustc_hash::FxHashMap; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::node::AstNode; @@ -77,7 +77,7 @@ pub struct PytestParametrizeNamesWrongType { } impl Violation for PytestParametrizeNamesWrongType { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -85,7 +85,7 @@ impl Violation for PytestParametrizeNamesWrongType { format!("Wrong name(s) type in `@pytest.mark.parametrize`, expected `{expected}`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let PytestParametrizeNamesWrongType { expected } = self; Some(format!("Use a `{expected}` for parameter names")) } @@ -234,7 +234,7 @@ pub struct PytestDuplicateParametrizeTestCases { } impl Violation for PytestDuplicateParametrizeTestCases { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -242,7 +242,7 @@ impl Violation for PytestDuplicateParametrizeTestCases { format!("Duplicate of test case at index {index} in `@pytest_mark.parametrize`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Remove duplicate test case".to_string()) } } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs index d319cd32b3ea7..5dcbf58f2e0dc 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs @@ -453,7 +453,7 @@ impl UnittestAssert { Ok(assert(&node.into(), msg)) } } - _ => bail!("Cannot autofix `{self}`"), + _ => bail!("Cannot fix `{self}`"), } } } diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT018.snap b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT018.snap index c32ecf025b444..a656a5c666f59 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT018.snap +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/snapshots/ruff_linter__rules__flake8_pytest_style__tests__PT018.snap @@ -228,7 +228,7 @@ PT018.py:33:5: PT018 [*] Assertion should be broken down into multiple parts 34 |+ assert (b or c) 34 35 | assert not (a or not (b and c)) 35 36 | -36 37 | # detected, but no autofix for messages +36 37 | # detected, but no fix for messages PT018.py:34:5: PT018 [*] Assertion should be broken down into multiple parts | @@ -237,7 +237,7 @@ PT018.py:34:5: PT018 [*] Assertion should be broken down into multiple parts 34 | assert not (a or not (b and c)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 35 | -36 | # detected, but no autofix for messages +36 | # detected, but no fix for messages | = help: Break down assertion into multiple parts @@ -249,26 +249,26 @@ PT018.py:34:5: PT018 [*] Assertion should be broken down into multiple parts 34 |+ assert not a 35 |+ assert (b and c) 35 36 | -36 37 | # detected, but no autofix for messages +36 37 | # detected, but no fix for messages 37 38 | assert something and something_else, "error message" PT018.py:37:5: PT018 Assertion should be broken down into multiple parts | -36 | # detected, but no autofix for messages +36 | # detected, but no fix for messages 37 | assert something and something_else, "error message" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 38 | assert not (something or something_else and something_third), "with message" -39 | # detected, but no autofix for mixed conditions (e.g. `a or b and c`) +39 | # detected, but no fix for mixed conditions (e.g. `a or b and c`) | = help: Break down assertion into multiple parts PT018.py:38:5: PT018 Assertion should be broken down into multiple parts | -36 | # detected, but no autofix for messages +36 | # detected, but no fix for messages 37 | assert something and something_else, "error message" 38 | assert not (something or something_else and something_third), "with message" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 -39 | # detected, but no autofix for mixed conditions (e.g. `a or b and c`) +39 | # detected, but no fix for mixed conditions (e.g. `a or b and c`) 40 | assert not (something or something_else and something_third) | = help: Break down assertion into multiple parts @@ -276,7 +276,7 @@ PT018.py:38:5: PT018 Assertion should be broken down into multiple parts PT018.py:40:5: PT018 Assertion should be broken down into multiple parts | 38 | assert not (something or something_else and something_third), "with message" -39 | # detected, but no autofix for mixed conditions (e.g. `a or b and c`) +39 | # detected, but no fix for mixed conditions (e.g. `a or b and c`) 40 | assert not (something or something_else and something_third) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PT018 | diff --git a/crates/ruff_linter/src/rules/flake8_quotes/rules/from_tokens.rs b/crates/ruff_linter/src/rules/flake8_quotes/rules/from_tokens.rs index 7cb159008147a..b3aad1a65f010 100644 --- a/crates/ruff_linter/src/rules/flake8_quotes/rules/from_tokens.rs +++ b/crates/ruff_linter/src/rules/flake8_quotes/rules/from_tokens.rs @@ -2,7 +2,7 @@ use ruff_python_parser::lexer::LexResult; use ruff_python_parser::Tok; use ruff_text_size::TextRange; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::Locator; @@ -37,7 +37,7 @@ pub struct BadQuotesInlineString { quote: Quote, } -impl AlwaysAutofixableViolation for BadQuotesInlineString { +impl AlwaysFixableViolation for BadQuotesInlineString { #[derive_message_formats] fn message(&self) -> String { let BadQuotesInlineString { quote } = self; @@ -47,7 +47,7 @@ impl AlwaysAutofixableViolation for BadQuotesInlineString { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let BadQuotesInlineString { quote } = self; match quote { Quote::Double => "Replace single quotes with double quotes".to_string(), @@ -86,7 +86,7 @@ pub struct BadQuotesMultilineString { quote: Quote, } -impl AlwaysAutofixableViolation for BadQuotesMultilineString { +impl AlwaysFixableViolation for BadQuotesMultilineString { #[derive_message_formats] fn message(&self) -> String { let BadQuotesMultilineString { quote } = self; @@ -96,7 +96,7 @@ impl AlwaysAutofixableViolation for BadQuotesMultilineString { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let BadQuotesMultilineString { quote } = self; match quote { Quote::Double => "Replace single multiline quotes with double quotes".to_string(), @@ -134,7 +134,7 @@ pub struct BadQuotesDocstring { quote: Quote, } -impl AlwaysAutofixableViolation for BadQuotesDocstring { +impl AlwaysFixableViolation for BadQuotesDocstring { #[derive_message_formats] fn message(&self) -> String { let BadQuotesDocstring { quote } = self; @@ -144,7 +144,7 @@ impl AlwaysAutofixableViolation for BadQuotesDocstring { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let BadQuotesDocstring { quote } = self; match quote { Quote::Double => "Replace single quotes docstring with double quotes".to_string(), @@ -173,13 +173,13 @@ impl AlwaysAutofixableViolation for BadQuotesDocstring { #[violation] pub struct AvoidableEscapedQuote; -impl AlwaysAutofixableViolation for AvoidableEscapedQuote { +impl AlwaysFixableViolation for AvoidableEscapedQuote { #[derive_message_formats] fn message(&self) -> String { format!("Change outer quotes to avoid escaping inner quotes") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Change outer quotes to avoid escaping inner quotes".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs b/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs index 2b8895dc60f3d..53febbdc012e8 100644 --- a/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_raise/rules/unnecessary_paren_on_raise_exception.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; @@ -31,13 +31,13 @@ use crate::registry::AsRule; #[violation] pub struct UnnecessaryParenOnRaiseException; -impl AlwaysAutofixableViolation for UnnecessaryParenOnRaiseException { +impl AlwaysFixableViolation for UnnecessaryParenOnRaiseException { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary parentheses on raised exception") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Remove unnecessary parentheses") } } diff --git a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs index a3002e9bac758..6ec87d50df88c 100644 --- a/crates/ruff_linter/src/rules/flake8_return/rules/function.rs +++ b/crates/ruff_linter/src/rules/flake8_return/rules/function.rs @@ -3,7 +3,7 @@ use std::ops::Add; use ruff_python_ast::{self as ast, ElifElseClause, Expr, Stmt}; use ruff_text_size::{Ranged, TextRange, TextSize}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_const_none; @@ -14,8 +14,8 @@ use ruff_python_ast::whitespace::indentation; use ruff_python_semantic::SemanticModel; use ruff_python_trivia::is_python_whitespace; -use crate::autofix::edits; use crate::checkers::ast::Checker; +use crate::fix::edits; use crate::registry::{AsRule, Rule}; use crate::rules::flake8_return::helpers::end_of_last_statement; @@ -51,7 +51,7 @@ use super::super::visitor::{ReturnVisitor, Stack}; #[violation] pub struct UnnecessaryReturnNone; -impl AlwaysAutofixableViolation for UnnecessaryReturnNone { +impl AlwaysFixableViolation for UnnecessaryReturnNone { #[derive_message_formats] fn message(&self) -> String { format!( @@ -59,7 +59,7 @@ impl AlwaysAutofixableViolation for UnnecessaryReturnNone { ) } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove explicit `return None`".to_string() } } @@ -93,13 +93,13 @@ impl AlwaysAutofixableViolation for UnnecessaryReturnNone { #[violation] pub struct ImplicitReturnValue; -impl AlwaysAutofixableViolation for ImplicitReturnValue { +impl AlwaysFixableViolation for ImplicitReturnValue { #[derive_message_formats] fn message(&self) -> String { format!("Do not implicitly `return None` in function able to return non-`None` value") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Add explicit `None` return value".to_string() } } @@ -131,13 +131,13 @@ impl AlwaysAutofixableViolation for ImplicitReturnValue { #[violation] pub struct ImplicitReturn; -impl AlwaysAutofixableViolation for ImplicitReturn { +impl AlwaysFixableViolation for ImplicitReturn { #[derive_message_formats] fn message(&self) -> String { format!("Missing explicit `return` at the end of function able to return non-`None` value") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Add explicit `return` statement".to_string() } } @@ -167,14 +167,14 @@ pub struct UnnecessaryAssign { name: String, } -impl AlwaysAutofixableViolation for UnnecessaryAssign { +impl AlwaysFixableViolation for UnnecessaryAssign { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryAssign { name } = self; format!("Unnecessary assignment to `{name}` before `return` statement") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove unnecessary assignment".to_string() } } diff --git a/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__RET504_RET504.py.snap b/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__RET504_RET504.py.snap index 0d2fea7fe3a2e..c9bcc8798437d 100644 --- a/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__RET504_RET504.py.snap +++ b/crates/ruff_linter/src/rules/flake8_return/snapshots/ruff_linter__rules__flake8_return__tests__RET504_RET504.py.snap @@ -131,7 +131,7 @@ RET504.py:342:12: RET504 [*] Unnecessary assignment to `b` before `return` state = help: Remove unnecessary assignment ℹ Suggested fix -338 338 | # Autofix cases +338 338 | # Fix cases 339 339 | def foo(): 340 340 | a = 1 341 |- b=a diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs index b60b5de1228c8..b559813b7fcb3 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -7,7 +7,7 @@ use ruff_python_ast::{self as ast, Arguments, BoolOp, CmpOp, Expr, ExprContext, use ruff_text_size::{Ranged, TextRange}; use rustc_hash::FxHashMap; -use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::{contains_effect, Truthiness}; @@ -49,7 +49,7 @@ pub struct DuplicateIsinstanceCall { } impl Violation for DuplicateIsinstanceCall { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -61,7 +61,7 @@ impl Violation for DuplicateIsinstanceCall { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let DuplicateIsinstanceCall { name } = self; Some(if let Some(name) = name { @@ -99,14 +99,14 @@ pub struct CompareWithTuple { replacement: String, } -impl AlwaysAutofixableViolation for CompareWithTuple { +impl AlwaysFixableViolation for CompareWithTuple { #[derive_message_formats] fn message(&self) -> String { let CompareWithTuple { replacement } = self; format!("Use `{replacement}` instead of multiple equality comparisons") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let CompareWithTuple { replacement } = self; format!("Replace with `{replacement}`") } @@ -132,14 +132,14 @@ pub struct ExprAndNotExpr { name: String, } -impl AlwaysAutofixableViolation for ExprAndNotExpr { +impl AlwaysFixableViolation for ExprAndNotExpr { #[derive_message_formats] fn message(&self) -> String { let ExprAndNotExpr { name } = self; format!("Use `False` instead of `{name} and not {name}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with `False`".to_string() } } @@ -164,14 +164,14 @@ pub struct ExprOrNotExpr { name: String, } -impl AlwaysAutofixableViolation for ExprOrNotExpr { +impl AlwaysFixableViolation for ExprOrNotExpr { #[derive_message_formats] fn message(&self) -> String { let ExprOrNotExpr { name } = self; format!("Use `True` instead of `{name} or not {name}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with `True`".to_string() } } @@ -217,7 +217,7 @@ pub struct ExprOrTrue { remove: ContentAround, } -impl AlwaysAutofixableViolation for ExprOrTrue { +impl AlwaysFixableViolation for ExprOrTrue { #[derive_message_formats] fn message(&self) -> String { let ExprOrTrue { expr, remove } = self; @@ -229,7 +229,7 @@ impl AlwaysAutofixableViolation for ExprOrTrue { format!("Use `{expr}` instead of `{replaced}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let ExprOrTrue { expr, .. } = self; format!("Replace with `{expr}`") } @@ -269,7 +269,7 @@ pub struct ExprAndFalse { remove: ContentAround, } -impl AlwaysAutofixableViolation for ExprAndFalse { +impl AlwaysFixableViolation for ExprAndFalse { #[derive_message_formats] fn message(&self) -> String { let ExprAndFalse { expr, remove } = self; @@ -281,7 +281,7 @@ impl AlwaysAutofixableViolation for ExprAndFalse { format!("Use `{expr}` instead of `{replaced}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let ExprAndFalse { expr, .. } = self; format!("Replace with `{expr}`") } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs index 40ac939d0bf5e..26e8f4e3c5f17 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs @@ -1,8 +1,8 @@ use ruff_python_ast::{self as ast, Arguments, Constant, Expr}; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix::snippet::SourceCodeSnippet; -use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Edit, Fix, Violation}; +use crate::fix::snippet::SourceCodeSnippet; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_const_none; @@ -41,7 +41,7 @@ pub struct UncapitalizedEnvironmentVariables { } impl Violation for UncapitalizedEnvironmentVariables { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -53,7 +53,7 @@ impl Violation for UncapitalizedEnvironmentVariables { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let UncapitalizedEnvironmentVariables { expected, actual } = self; if let (Some(expected), Some(actual)) = (expected.full_display(), actual.full_display()) { Some(format!("Replace `{actual}` with `{expected}`")) @@ -90,7 +90,7 @@ pub struct DictGetWithNoneDefault { actual: SourceCodeSnippet, } -impl AlwaysAutofixableViolation for DictGetWithNoneDefault { +impl AlwaysFixableViolation for DictGetWithNoneDefault { #[derive_message_formats] fn message(&self) -> String { let DictGetWithNoneDefault { expected, actual } = self; @@ -101,7 +101,7 @@ impl AlwaysAutofixableViolation for DictGetWithNoneDefault { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let DictGetWithNoneDefault { expected, actual } = self; if let (Some(expected), Some(actual)) = (expected.full_display(), actual.full_display()) { format!("Replace `{actual}` with `{expected}`") diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_if.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_if.rs index 3ceee59438b68..5403db4b56992 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_if.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_if.rs @@ -5,7 +5,7 @@ use ruff_python_ast::{ use ruff_text_size::{Ranged, TextRange}; use rustc_hash::FxHashSet; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::{ComparableConstant, ComparableExpr, ComparableStmt}; use ruff_python_ast::helpers::{any_over_expr, contains_effect}; @@ -56,14 +56,14 @@ fn compare_stmt(stmt1: &ComparableStmt, stmt2: &ComparableStmt) -> bool { pub struct CollapsibleIf; impl Violation for CollapsibleIf { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use a single `if` statement instead of nested `if` statements") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Combine `if` statements using `and`".to_string()) } } @@ -96,7 +96,7 @@ pub struct NeedlessBool { } impl Violation for NeedlessBool { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -104,7 +104,7 @@ impl Violation for NeedlessBool { format!("Return the condition `{condition}` directly") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let NeedlessBool { condition } = self; Some(format!("Replace with `return {condition}`")) } @@ -168,7 +168,7 @@ pub struct IfElseBlockInsteadOfIfExp { } impl Violation for IfElseBlockInsteadOfIfExp { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -176,7 +176,7 @@ impl Violation for IfElseBlockInsteadOfIfExp { format!("Use ternary operator `{contents}` instead of `if`-`else`-block") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let IfElseBlockInsteadOfIfExp { contents } = self; Some(format!("Replace `if`-`else`-block with `{contents}`")) } @@ -242,7 +242,7 @@ pub struct IfElseBlockInsteadOfDictGet { } impl Violation for IfElseBlockInsteadOfDictGet { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -250,7 +250,7 @@ impl Violation for IfElseBlockInsteadOfDictGet { format!("Use `{contents}` instead of an `if` block") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let IfElseBlockInsteadOfDictGet { contents } = self; Some(format!("Replace with `{contents}`")) } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs index f5d890f61b5eb..1b1974d58ec2d 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Arguments, Expr, ExprContext, UnaryOp}; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::{is_const_false, is_const_true}; use ruff_python_ast::parenthesize::parenthesized_range; @@ -35,7 +35,7 @@ pub struct IfExprWithTrueFalse { } impl Violation for IfExprWithTrueFalse { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -47,7 +47,7 @@ impl Violation for IfExprWithTrueFalse { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let IfExprWithTrueFalse { is_compare } = self; if *is_compare { Some(format!("Remove unnecessary `True if ... else False`")) @@ -81,13 +81,13 @@ impl Violation for IfExprWithTrueFalse { #[violation] pub struct IfExprWithFalseTrue; -impl AlwaysAutofixableViolation for IfExprWithFalseTrue { +impl AlwaysFixableViolation for IfExprWithFalseTrue { #[derive_message_formats] fn message(&self) -> String { format!("Use `not ...` instead of `False if ... else True`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Replace with `not ...`") } } @@ -117,7 +117,7 @@ pub struct IfExprWithTwistedArms { expr_else: String, } -impl AlwaysAutofixableViolation for IfExprWithTwistedArms { +impl AlwaysFixableViolation for IfExprWithTwistedArms { #[derive_message_formats] fn message(&self) -> String { let IfExprWithTwistedArms { @@ -130,7 +130,7 @@ impl AlwaysAutofixableViolation for IfExprWithTwistedArms { ) } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let IfExprWithTwistedArms { expr_body, expr_else, diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs index e6636fb7007c4..c7210c1d87f3f 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Arguments, CmpOp, Expr, ExprContext, Stmt, UnaryOp}; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::ScopeKind; @@ -33,14 +33,14 @@ pub struct NegateEqualOp { right: String, } -impl AlwaysAutofixableViolation for NegateEqualOp { +impl AlwaysFixableViolation for NegateEqualOp { #[derive_message_formats] fn message(&self) -> String { let NegateEqualOp { left, right } = self; format!("Use `{left} != {right}` instead of `not {left} == {right}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with `!=` operator".to_string() } } @@ -70,14 +70,14 @@ pub struct NegateNotEqualOp { right: String, } -impl AlwaysAutofixableViolation for NegateNotEqualOp { +impl AlwaysFixableViolation for NegateNotEqualOp { #[derive_message_formats] fn message(&self) -> String { let NegateNotEqualOp { left, right } = self; format!("Use `{left} == {right}` instead of `not {left} != {right}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with `==` operator".to_string() } } @@ -106,14 +106,14 @@ pub struct DoubleNegation { expr: String, } -impl AlwaysAutofixableViolation for DoubleNegation { +impl AlwaysFixableViolation for DoubleNegation { #[derive_message_formats] fn message(&self) -> String { let DoubleNegation { expr } = self; format!("Use `{expr}` instead of `not (not {expr})`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let DoubleNegation { expr } = self; format!("Replace with `{expr}`") } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs index da34dc0841bcd..3b1241d5e4585 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_with.rs @@ -1,7 +1,7 @@ use log::error; -use ruff_diagnostics::{AutofixKind, Violation}; use ruff_diagnostics::{Diagnostic, Fix}; +use ruff_diagnostics::{FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Stmt, WithItem}; use ruff_python_trivia::{SimpleTokenKind, SimpleTokenizer}; @@ -45,7 +45,7 @@ use super::fix_with; pub struct MultipleWithStatements; impl Violation for MultipleWithStatements { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -55,7 +55,7 @@ impl Violation for MultipleWithStatements { ) } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Combine `with` statements".to_string()) } } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/fix_if.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/fix_if.rs index e03b685abb5a2..f308adf710730 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/fix_if.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/fix_if.rs @@ -12,9 +12,9 @@ use ruff_python_codegen::Stylist; use ruff_source_file::Locator; use ruff_text_size::TextRange; -use crate::autofix::codemods::CodegenStylist; use crate::cst::helpers::space; use crate::cst::matchers::{match_function_def, match_if, match_indented_block, match_statement}; +use crate::fix::codemods::CodegenStylist; fn parenthesize_and_operand(expr: Expression) -> Expression { match &expr { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/fix_with.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/fix_with.rs index 3e0f6f0b13832..1738aa8023142 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/fix_with.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/fix_with.rs @@ -8,8 +8,8 @@ use ruff_python_codegen::Stylist; use ruff_source_file::Locator; use ruff_text_size::Ranged; -use crate::autofix::codemods::CodegenStylist; use crate::cst::matchers::{match_function_def, match_indented_block, match_statement, match_with}; +use crate::fix::codemods::CodegenStylist; /// (SIM117) Convert `with a: with b:` to `with a, b:`. pub(crate) fn fix_multiple_with_statements( diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs index bddbeffc84158..c7d37748ef9ca 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/key_in_dict.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Edit; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::node::AnyNodeRef; use ruff_python_ast::parenthesize::parenthesized_range; @@ -35,14 +35,14 @@ pub struct InDictKeys { operator: String, } -impl AlwaysAutofixableViolation for InDictKeys { +impl AlwaysFixableViolation for InDictKeys { #[derive_message_formats] fn message(&self) -> String { let InDictKeys { operator } = self; format!("Use `key {operator} dict` instead of `key {operator} dict.keys()`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let InDictKeys { operator: _ } = self; format!("Remove `.keys()`") } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs index 7529ba9ee4854..4d5f37f6b5b39 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -3,7 +3,7 @@ use ruff_python_ast::{ }; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::any_over_expr; use ruff_python_ast::traversal; @@ -43,7 +43,7 @@ pub struct ReimplementedBuiltin { } impl Violation for ReimplementedBuiltin { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -51,7 +51,7 @@ impl Violation for ReimplementedBuiltin { format!("Use `{replacement}` instead of `for` loop") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let ReimplementedBuiltin { replacement } = self; Some(format!("Replace with `{replacement}`")) } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs index 03e4b2f08c232..a874020c42a31 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/suppressible_exception.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path::compose_call_path; use ruff_python_ast::helpers; @@ -48,7 +48,7 @@ pub struct SuppressibleException { } impl Violation for SuppressibleException { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -56,7 +56,7 @@ impl Violation for SuppressibleException { format!("Use `contextlib.suppress({exception})` instead of `try`-`except`-`pass`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let SuppressibleException { exception } = self; Some(format!("Replace with `contextlib.suppress({exception})`")) } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs index 2fc1ae1fb11f1..a3a65d8d3b80a 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs @@ -1,7 +1,7 @@ use anyhow::Result; use libcst_native::CompOp; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, CmpOp, Expr, UnaryOp}; use ruff_python_codegen::Stylist; @@ -9,11 +9,11 @@ use ruff_python_stdlib::str::{self}; use ruff_source_file::Locator; use ruff_text_size::Ranged; -use crate::autofix::edits::pad; -use crate::autofix::snippet::SourceCodeSnippet; use crate::checkers::ast::Checker; use crate::cst::helpers::or_space; use crate::cst::matchers::{match_comparison, transform_expression}; +use crate::fix::edits::pad; +use crate::fix::snippet::SourceCodeSnippet; use crate::registry::AsRule; /// ## What it does @@ -52,7 +52,7 @@ pub struct YodaConditions { } impl Violation for YodaConditions { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -67,7 +67,7 @@ impl Violation for YodaConditions { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let YodaConditions { suggestion } = self; suggestion.as_ref().map(|suggestion| { if let Some(suggestion) = suggestion.full_display() { diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs index 143f35f7d4a6d..91c11ef11d128 100644 --- a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs +++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Identifier, Stmt}; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::resolve_imported_module_path; use ruff_python_codegen::Generator; @@ -51,7 +51,7 @@ pub struct RelativeImports { } impl Violation for RelativeImports { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -61,7 +61,7 @@ impl Violation for RelativeImports { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let RelativeImports { strictness } = self; Some(match strictness { Strictness::Parents => { diff --git a/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs b/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs index 5e6f84253b77f..6f932fe344aa7 100644 --- a/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs +++ b/crates/ruff_linter/src/rules/flake8_todos/rules/todos.rs @@ -4,7 +4,7 @@ use ruff_python_index::Indexer; use ruff_source_file::Locator; use ruff_text_size::{TextLen, TextRange, TextSize}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix, Violation}; use ruff_macros::{derive_message_formats, violation}; use crate::settings::LinterSettings; @@ -184,14 +184,14 @@ pub struct InvalidTodoCapitalization { tag: String, } -impl AlwaysAutofixableViolation for InvalidTodoCapitalization { +impl AlwaysFixableViolation for InvalidTodoCapitalization { #[derive_message_formats] fn message(&self) -> String { let InvalidTodoCapitalization { tag } = self; format!("Invalid TODO capitalization: `{tag}` should be `TODO`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let InvalidTodoCapitalization { tag } = self; format!("Replace `{tag}` with `TODO`") } diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs index 1a00637c85b80..c7181e01e07c9 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/empty_type_checking_block.rs @@ -1,11 +1,11 @@ use ruff_python_ast as ast; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; -use crate::autofix; use crate::checkers::ast::Checker; +use crate::fix; use crate::registry::AsRule; /// ## What it does @@ -35,13 +35,13 @@ use crate::registry::AsRule; #[violation] pub struct EmptyTypeCheckingBlock; -impl AlwaysAutofixableViolation for EmptyTypeCheckingBlock { +impl AlwaysFixableViolation for EmptyTypeCheckingBlock { #[derive_message_formats] fn message(&self) -> String { format!("Found empty type-checking block") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Delete empty type-checking block") } } @@ -60,7 +60,7 @@ pub(crate) fn empty_type_checking_block(checker: &mut Checker, stmt: &ast::StmtI // Delete the entire type-checking block. let stmt = checker.semantic().current_statement(); let parent = checker.semantic().current_statement_parent(); - let edit = autofix::edits::delete_stmt(stmt, parent, checker.locator(), checker.indexer()); + let edit = fix::edits::delete_stmt(stmt, parent, checker.locator(), checker.indexer()); diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation( checker.semantic().current_statement_parent_id(), ))); diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs index 3f39d4ad542af..ce4e5b9f78487 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/runtime_import_in_type_checking_block.rs @@ -3,14 +3,14 @@ use std::borrow::Cow; use anyhow::Result; use rustc_hash::FxHashMap; -use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::{AnyImport, Imported, NodeId, ResolvedReferenceId, Scope}; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix; use crate::checkers::ast::Checker; use crate::codes::Rule; +use crate::fix; use crate::importer::ImportedMembers; /// ## What it does @@ -49,7 +49,7 @@ pub struct RuntimeImportInTypeCheckingBlock { } impl Violation for RuntimeImportInTypeCheckingBlock { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -59,7 +59,7 @@ impl Violation for RuntimeImportInTypeCheckingBlock { ) } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Move out of type-checking block".to_string()) } } @@ -216,7 +216,7 @@ fn fix_imports(checker: &Checker, node_id: NodeId, imports: &[ImportBinding]) -> .expect("Expected at least one import"); // Step 1) Remove the import. - let remove_import_edit = autofix::edits::remove_unused_imports( + let remove_import_edit = fix::edits::remove_unused_imports( member_names.iter().map(AsRef::as_ref), statement, parent, diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs b/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs index eb933f2c31e9a..7952c0d309180 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/rules/typing_only_runtime_import.rs @@ -3,14 +3,14 @@ use std::borrow::Cow; use anyhow::Result; use rustc_hash::FxHashMap; -use ruff_diagnostics::{AutofixKind, Diagnostic, DiagnosticKind, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::{AnyImport, Binding, Imported, NodeId, ResolvedReferenceId, Scope}; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix; use crate::checkers::ast::Checker; use crate::codes::Rule; +use crate::fix; use crate::importer::ImportedMembers; use crate::rules::isort::{categorize, ImportSection, ImportType}; @@ -67,7 +67,7 @@ pub struct TypingOnlyFirstPartyImport { } impl Violation for TypingOnlyFirstPartyImport { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -77,7 +77,7 @@ impl Violation for TypingOnlyFirstPartyImport { ) } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Move into type-checking block".to_string()) } } @@ -135,7 +135,7 @@ pub struct TypingOnlyThirdPartyImport { } impl Violation for TypingOnlyThirdPartyImport { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -145,7 +145,7 @@ impl Violation for TypingOnlyThirdPartyImport { ) } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Move into type-checking block".to_string()) } } @@ -203,7 +203,7 @@ pub struct TypingOnlyStandardLibraryImport { } impl Violation for TypingOnlyStandardLibraryImport { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -213,7 +213,7 @@ impl Violation for TypingOnlyStandardLibraryImport { ) } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Move into type-checking block".to_string()) } } @@ -465,7 +465,7 @@ fn fix_imports(checker: &Checker, node_id: NodeId, imports: &[ImportBinding]) -> .expect("Expected at least one import"); // Step 1) Remove the import. - let remove_import_edit = autofix::edits::remove_unused_imports( + let remove_import_edit = fix::edits::remove_unused_imports( member_names.iter().map(AsRef::as_ref), statement, parent, diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs index 3103f0577e235..4f74c490241a1 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/path_constructor_current_directory.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{self as ast, Arguments, Constant, Expr, ExprCall, ExprConstant}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use crate::checkers::ast::Checker; @@ -33,13 +33,13 @@ use crate::registry::AsRule; #[violation] pub struct PathConstructorCurrentDirectory; -impl AlwaysAutofixableViolation for PathConstructorCurrentDirectory { +impl AlwaysFixableViolation for PathConstructorCurrentDirectory { #[derive_message_formats] fn message(&self) -> String { format!("Do not pass the current directory explicitly to `Path`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove the current directory argument".to_string() } } diff --git a/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs b/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs index 969b7cf94bed0..003d5cad2d10e 100644 --- a/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs +++ b/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs @@ -1,13 +1,13 @@ use itertools::Itertools; -use crate::autofix::edits::pad; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use crate::fix::edits::pad; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Arguments, Constant, Expr}; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix::snippet::SourceCodeSnippet; use crate::checkers::ast::Checker; +use crate::fix::snippet::SourceCodeSnippet; use crate::registry::AsRule; use crate::rules::flynt::helpers; @@ -34,7 +34,7 @@ pub struct StaticJoinToFString { expression: SourceCodeSnippet, } -impl AlwaysAutofixableViolation for StaticJoinToFString { +impl AlwaysFixableViolation for StaticJoinToFString { #[derive_message_formats] fn message(&self) -> String { let StaticJoinToFString { expression } = self; @@ -45,7 +45,7 @@ impl AlwaysAutofixableViolation for StaticJoinToFString { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let StaticJoinToFString { expression } = self; if let Some(expression) = expression.full_display() { format!("Replace with `{expression}`") diff --git a/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs b/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs index cc4e017ff665c..edda5aaf4c267 100644 --- a/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs +++ b/crates/ruff_linter/src/rules/isort/rules/add_required_imports.rs @@ -1,6 +1,6 @@ use log::error; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_docstring_stmt; use ruff_python_ast::imports::{Alias, AnyImport, FutureImport, Import, ImportFrom}; @@ -40,14 +40,14 @@ use crate::settings::LinterSettings; #[violation] pub struct MissingRequiredImport(pub String); -impl AlwaysAutofixableViolation for MissingRequiredImport { +impl AlwaysFixableViolation for MissingRequiredImport { #[derive_message_formats] fn message(&self) -> String { let MissingRequiredImport(name) = self; format!("Missing required import: `{name}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let MissingRequiredImport(name) = self; format!("Insert required import: `{name}`") } diff --git a/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs b/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs index 62b2043f8c49a..44dbaa6f03fd8 100644 --- a/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs +++ b/crates/ruff_linter/src/rules/isort/rules/organize_imports.rs @@ -2,7 +2,7 @@ use std::path::Path; use itertools::{EitherOrBoth, Itertools}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::whitespace::trailing_lines_end; use ruff_python_ast::{PySourceType, Stmt}; @@ -41,14 +41,14 @@ use super::super::{comments, format_imports}; pub struct UnsortedImports; impl Violation for UnsortedImports { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Import block is un-sorted or un-formatted") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Organize imports".to_string()) } } diff --git a/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs b/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs index b88581fe914d8..50a1e19859983 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/deprecated_function.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::Expr; use ruff_text_size::Ranged; @@ -37,7 +37,7 @@ pub struct NumpyDeprecatedFunction { } impl Violation for NumpyDeprecatedFunction { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -48,7 +48,7 @@ impl Violation for NumpyDeprecatedFunction { format!("`np.{existing}` is deprecated; use `np.{replacement}` instead") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let NumpyDeprecatedFunction { replacement, .. } = self; Some(format!("Replace with `np.{replacement}`")) } diff --git a/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs b/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs index fe24ec08dd382..5d40292c5935e 100644 --- a/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs +++ b/crates/ruff_linter/src/rules/numpy/rules/deprecated_type_alias.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::Expr; use ruff_text_size::Ranged; @@ -34,7 +34,7 @@ pub struct NumpyDeprecatedTypeAlias { } impl Violation for NumpyDeprecatedTypeAlias { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -42,7 +42,7 @@ impl Violation for NumpyDeprecatedTypeAlias { format!("Type alias `np.{type_name}` is deprecated, replace with builtin type") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let NumpyDeprecatedTypeAlias { type_name } = self; Some(format!("Replace `np.{type_name}` with builtin type")) } diff --git a/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs b/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs index 417b76959194f..c6159d0a3cffb 100644 --- a/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs +++ b/crates/ruff_linter/src/rules/pandas_vet/rules/inplace_argument.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_const_true; use ruff_python_ast::parenthesize::parenthesized_range; @@ -7,8 +7,8 @@ use ruff_python_trivia::CommentRanges; use ruff_source_file::Locator; use ruff_text_size::Ranged; -use crate::autofix::edits::{remove_argument, Parentheses}; use crate::checkers::ast::Checker; +use crate::fix::edits::{remove_argument, Parentheses}; use crate::registry::AsRule; /// ## What it does @@ -39,14 +39,14 @@ use crate::registry::AsRule; pub struct PandasUseOfInplaceArgument; impl Violation for PandasUseOfInplaceArgument { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("`inplace=True` should be avoided; it has inconsistent behavior") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Assign to variable; remove `inplace` arg".to_string()) } } diff --git a/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs b/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs index ab693beae8b26..4534b0e5705d9 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/incorrect_dict_iterator.rs @@ -1,7 +1,7 @@ use std::fmt; -use crate::autofix::edits::pad; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use crate::fix::edits::pad; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast as ast; use ruff_python_ast::{Arguments, Expr}; @@ -43,14 +43,14 @@ pub struct IncorrectDictIterator { subset: DictSubset, } -impl AlwaysAutofixableViolation for IncorrectDictIterator { +impl AlwaysFixableViolation for IncorrectDictIterator { #[derive_message_formats] fn message(&self) -> String { let IncorrectDictIterator { subset } = self; format!("When using only the {subset} of a dict use the `{subset}()` method") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let IncorrectDictIterator { subset } = self; format!("Replace `.items()` with `.{subset}()`") } diff --git a/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs b/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs index a9d062554a90f..74853d5127a59 100644 --- a/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs +++ b/crates/ruff_linter/src/rules/perflint/rules/unnecessary_list_cast.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::Stmt; use ruff_python_ast::{self as ast, Arguments, Expr}; @@ -38,13 +38,13 @@ use crate::registry::AsRule; #[violation] pub struct UnnecessaryListCast; -impl AlwaysAutofixableViolation for UnnecessaryListCast { +impl AlwaysFixableViolation for UnnecessaryListCast { #[derive_message_formats] fn message(&self) -> String { format!("Do not cast an iterable to `list` before iterating over it") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Remove `list()` cast") } } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs index 2ca7657ff273d..8480a78a4c9b3 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/compound_statements.rs @@ -2,7 +2,7 @@ use ruff_python_parser::lexer::LexResult; use ruff_python_parser::Tok; use ruff_text_size::TextRange; -use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_index::Indexer; @@ -87,13 +87,13 @@ impl Violation for MultipleStatementsOnOneLineSemicolon { #[violation] pub struct UselessSemicolon; -impl AlwaysAutofixableViolation for UselessSemicolon { +impl AlwaysFixableViolation for UselessSemicolon { #[derive_message_formats] fn message(&self) -> String { format!("Statement ends with an unnecessary semicolon") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Remove unnecessary semicolon") } } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs index 8cf0466c5cdb6..01ffcebcb9112 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/invalid_escape_sequence.rs @@ -1,12 +1,12 @@ use memchr::memchr_iter; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::str::{leading_quote, trailing_quote}; use ruff_source_file::Locator; use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; -use crate::autofix::edits::pad_start; +use crate::fix::edits::pad_start; /// ## What it does /// Checks for invalid escape sequences. @@ -29,14 +29,14 @@ use crate::autofix::edits::pad_start; #[violation] pub struct InvalidEscapeSequence(char); -impl AlwaysAutofixableViolation for InvalidEscapeSequence { +impl AlwaysFixableViolation for InvalidEscapeSequence { #[derive_message_formats] fn message(&self) -> String { let InvalidEscapeSequence(char) = self; format!("Invalid escape sequence: `\\{char}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Add backslash to escape sequence".to_string() } } @@ -46,7 +46,7 @@ pub(crate) fn invalid_escape_sequence( diagnostics: &mut Vec, locator: &Locator, range: TextRange, - autofix: bool, + fix: bool, ) { let text = locator.slice(range); @@ -125,7 +125,7 @@ pub(crate) fn invalid_escape_sequence( invalid_escape_sequence.push(Diagnostic::new(InvalidEscapeSequence(next_char), range)); } - if autofix { + if fix { if contains_valid_escape_sequence { // Escape with backslash. for diagnostic in &mut invalid_escape_sequence { diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs index 5f45d647bd840..1c9fad267add3 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -3,7 +3,7 @@ use ruff_python_ast::{ }; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_codegen::Generator; use ruff_python_semantic::SemanticModel; @@ -42,14 +42,14 @@ pub struct LambdaAssignment { } impl Violation for LambdaAssignment { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Do not assign a `lambda` expression, use a `def`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let LambdaAssignment { name } = self; Some(format!("Rewrite `{name}` as a `def`")) } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs index 2abf9faf65d37..4a580c67b0a1a 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/literal_comparisons.rs @@ -1,6 +1,6 @@ use rustc_hash::FxHashMap; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers; use ruff_python_ast::helpers::is_const_none; @@ -53,7 +53,7 @@ impl EqCmpOp { #[violation] pub struct NoneComparison(EqCmpOp); -impl AlwaysAutofixableViolation for NoneComparison { +impl AlwaysFixableViolation for NoneComparison { #[derive_message_formats] fn message(&self) -> String { let NoneComparison(op) = self; @@ -63,7 +63,7 @@ impl AlwaysAutofixableViolation for NoneComparison { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let NoneComparison(op) = self; match op { EqCmpOp::Eq => "Replace with `cond is None`".to_string(), @@ -99,7 +99,7 @@ impl AlwaysAutofixableViolation for NoneComparison { #[violation] pub struct TrueFalseComparison(bool, EqCmpOp); -impl AlwaysAutofixableViolation for TrueFalseComparison { +impl AlwaysFixableViolation for TrueFalseComparison { #[derive_message_formats] fn message(&self) -> String { let TrueFalseComparison(value, op) = self; @@ -119,7 +119,7 @@ impl AlwaysAutofixableViolation for TrueFalseComparison { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let TrueFalseComparison(value, op) = self; match (value, op) { (true, EqCmpOp::Eq) => "Replace with `cond is True`".to_string(), diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs index 3d01fad8dbd21..93d42501d3baf 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/extraneous_whitespace.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::AlwaysAutofixableViolation; +use ruff_diagnostics::AlwaysFixableViolation; use ruff_diagnostics::Diagnostic; use ruff_diagnostics::Edit; use ruff_diagnostics::Fix; @@ -36,14 +36,14 @@ pub struct WhitespaceAfterOpenBracket { symbol: char, } -impl AlwaysAutofixableViolation for WhitespaceAfterOpenBracket { +impl AlwaysFixableViolation for WhitespaceAfterOpenBracket { #[derive_message_formats] fn message(&self) -> String { let WhitespaceAfterOpenBracket { symbol } = self; format!("Whitespace after '{symbol}'") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let WhitespaceAfterOpenBracket { symbol } = self; format!("Remove whitespace before '{symbol}'") } @@ -75,14 +75,14 @@ pub struct WhitespaceBeforeCloseBracket { symbol: char, } -impl AlwaysAutofixableViolation for WhitespaceBeforeCloseBracket { +impl AlwaysFixableViolation for WhitespaceBeforeCloseBracket { #[derive_message_formats] fn message(&self) -> String { let WhitespaceBeforeCloseBracket { symbol } = self; format!("Whitespace before '{symbol}'") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let WhitespaceBeforeCloseBracket { symbol } = self; format!("Remove whitespace before '{symbol}'") } @@ -112,14 +112,14 @@ pub struct WhitespaceBeforePunctuation { symbol: char, } -impl AlwaysAutofixableViolation for WhitespaceBeforePunctuation { +impl AlwaysFixableViolation for WhitespaceBeforePunctuation { #[derive_message_formats] fn message(&self) -> String { let WhitespaceBeforePunctuation { symbol } = self; format!("Whitespace before '{symbol}'") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let WhitespaceBeforePunctuation { symbol } = self; format!("Remove whitespace before '{symbol}'") } @@ -129,9 +129,9 @@ impl AlwaysAutofixableViolation for WhitespaceBeforePunctuation { pub(crate) fn extraneous_whitespace( line: &LogicalLine, context: &mut LogicalLinesContext, - autofix_after_open_bracket: bool, - autofix_before_close_bracket: bool, - autofix_before_punctuation: bool, + fix_after_open_bracket: bool, + fix_before_close_bracket: bool, + fix_before_punctuation: bool, ) { let mut prev_token = None; @@ -146,7 +146,7 @@ pub(crate) fn extraneous_whitespace( WhitespaceAfterOpenBracket { symbol }, TextRange::at(token.end(), trailing_len), ); - if autofix_after_open_bracket { + if fix_after_open_bracket { diagnostic .set_fix(Fix::automatic(Edit::range_deletion(diagnostic.range()))); } @@ -162,7 +162,7 @@ pub(crate) fn extraneous_whitespace( WhitespaceBeforeCloseBracket { symbol }, TextRange::at(token.start() - offset, offset), ); - if autofix_before_close_bracket { + if fix_before_close_bracket { diagnostic.set_fix(Fix::automatic(Edit::range_deletion( diagnostic.range(), ))); @@ -180,7 +180,7 @@ pub(crate) fn extraneous_whitespace( WhitespaceBeforePunctuation { symbol }, TextRange::at(token.start() - offset, offset), ); - if autofix_before_punctuation { + if fix_before_punctuation { diagnostic.set_fix(Fix::automatic(Edit::range_deletion( diagnostic.range(), ))); diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs index 89a6d038c1abc..5163dfbb28630 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/missing_whitespace.rs @@ -1,5 +1,5 @@ use ruff_diagnostics::Edit; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_parser::TokenKind; use ruff_text_size::{Ranged, TextSize}; @@ -39,25 +39,21 @@ impl MissingWhitespace { } } -impl AlwaysAutofixableViolation for MissingWhitespace { +impl AlwaysFixableViolation for MissingWhitespace { #[derive_message_formats] fn message(&self) -> String { let token = self.token_text(); format!("Missing whitespace after '{token}'") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let token = self.token_text(); format!("Added missing whitespace after '{token}'") } } /// E231 -pub(crate) fn missing_whitespace( - line: &LogicalLine, - autofix: bool, - context: &mut LogicalLinesContext, -) { +pub(crate) fn missing_whitespace(line: &LogicalLine, fix: bool, context: &mut LogicalLinesContext) { let mut open_parentheses = 0u32; let mut prev_lsqb = TextSize::default(); let mut prev_lbrace = TextSize::default(); @@ -105,7 +101,7 @@ pub(crate) fn missing_whitespace( let kind = MissingWhitespace { token: kind }; let mut diagnostic = Diagnostic::new(kind, token.range()); - if autofix { + if fix { diagnostic.set_fix(Fix::automatic(Edit::insertion( " ".to_string(), token.end(), diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs index 0afe2e8ffb326..84f07c5a18303 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/logical_lines/whitespace_before_parameters.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_parser::TokenKind; use ruff_text_size::{Ranged, TextRange, TextSize}; @@ -40,14 +40,14 @@ impl WhitespaceBeforeParameters { } } -impl AlwaysAutofixableViolation for WhitespaceBeforeParameters { +impl AlwaysFixableViolation for WhitespaceBeforeParameters { #[derive_message_formats] fn message(&self) -> String { let bracket = self.bracket_text(); format!("Whitespace before '{bracket}'") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let bracket = self.bracket_text(); format!("Removed whitespace before '{bracket}'") } @@ -56,7 +56,7 @@ impl AlwaysAutofixableViolation for WhitespaceBeforeParameters { /// E211 pub(crate) fn whitespace_before_parameters( line: &LogicalLine, - autofix: bool, + fix: bool, context: &mut LogicalLinesContext, ) { let previous = line.tokens().first().unwrap(); @@ -82,7 +82,7 @@ pub(crate) fn whitespace_before_parameters( let mut diagnostic = Diagnostic::new(kind, TextRange::new(start, end)); - if autofix { + if fix { diagnostic.set_fix(Fix::automatic(Edit::deletion(start, end))); } context.push_diagnostic(diagnostic); diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs index be44b9951fcea..a59576fb6bc32 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/missing_newline_at_end_of_file.rs @@ -1,6 +1,6 @@ use ruff_text_size::{TextLen, TextRange}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_codegen::Stylist; use ruff_source_file::Locator; @@ -24,13 +24,13 @@ use ruff_source_file::Locator; #[violation] pub struct MissingNewlineAtEndOfFile; -impl AlwaysAutofixableViolation for MissingNewlineAtEndOfFile { +impl AlwaysFixableViolation for MissingNewlineAtEndOfFile { #[derive_message_formats] fn message(&self) -> String { format!("No newline at end of file") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Add trailing newline".to_string() } } @@ -39,7 +39,7 @@ impl AlwaysAutofixableViolation for MissingNewlineAtEndOfFile { pub(crate) fn no_newline_at_end_of_file( locator: &Locator, stylist: &Stylist, - autofix: bool, + fix: bool, ) -> Option { let source = locator.contents(); @@ -55,7 +55,7 @@ pub(crate) fn no_newline_at_end_of_file( let range = TextRange::empty(locator.contents().text_len()); let mut diagnostic = Diagnostic::new(MissingNewlineAtEndOfFile, range); - if autofix { + if fix { diagnostic.set_fix(Fix::automatic(Edit::insertion( stylist.line_ending().to_string(), range.start(), diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs index 908ac0baa36cf..61328cff39b4b 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/not_tests.rs @@ -1,5 +1,5 @@ -use crate::autofix::edits::pad; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use crate::fix::edits::pad; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, CmpOp, Expr}; use ruff_text_size::Ranged; @@ -30,13 +30,13 @@ use crate::rules::pycodestyle::helpers::generate_comparison; #[violation] pub struct NotInTest; -impl AlwaysAutofixableViolation for NotInTest { +impl AlwaysFixableViolation for NotInTest { #[derive_message_formats] fn message(&self) -> String { format!("Test for membership should be `not in`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Convert to `not in`".to_string() } } @@ -63,13 +63,13 @@ impl AlwaysAutofixableViolation for NotInTest { #[violation] pub struct NotIsTest; -impl AlwaysAutofixableViolation for NotIsTest { +impl AlwaysFixableViolation for NotIsTest { #[derive_message_formats] fn message(&self) -> String { format!("Test for object identity should be `is not`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Convert to `is not`".to_string() } } diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs index 88483409e5850..27cac8082fea9 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/trailing_whitespace.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_index::Indexer; use ruff_source_file::{Line, Locator}; @@ -28,13 +28,13 @@ use crate::settings::LinterSettings; #[violation] pub struct TrailingWhitespace; -impl AlwaysAutofixableViolation for TrailingWhitespace { +impl AlwaysFixableViolation for TrailingWhitespace { #[derive_message_formats] fn message(&self) -> String { format!("Trailing whitespace") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove trailing whitespace".to_string() } } @@ -60,13 +60,13 @@ impl AlwaysAutofixableViolation for TrailingWhitespace { #[violation] pub struct BlankLineWithWhitespace; -impl AlwaysAutofixableViolation for BlankLineWithWhitespace { +impl AlwaysFixableViolation for BlankLineWithWhitespace { #[derive_message_formats] fn message(&self) -> String { format!("Blank line contains whitespace") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove whitespace from blank line".to_string() } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs index 1672ad8a23af4..e01b82bbcefca 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_after_summary.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use ruff_text_size::Ranged; @@ -47,7 +47,7 @@ pub struct BlankLineAfterSummary { } impl Violation for BlankLineAfterSummary { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -61,7 +61,7 @@ impl Violation for BlankLineAfterSummary { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Insert single blank line".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs index 4f74fb736dc2d..8e0dde539c2b1 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_class.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_trivia::{indentation_at_offset, PythonWhitespace}; use ruff_source_file::{Line, UniversalNewlineIterator}; @@ -43,13 +43,13 @@ use crate::registry::{AsRule, Rule}; #[violation] pub struct OneBlankLineBeforeClass; -impl AlwaysAutofixableViolation for OneBlankLineBeforeClass { +impl AlwaysFixableViolation for OneBlankLineBeforeClass { #[derive_message_formats] fn message(&self) -> String { format!("1 blank line required before class docstring") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Insert 1 blank line before class docstring".to_string() } } @@ -95,13 +95,13 @@ impl AlwaysAutofixableViolation for OneBlankLineBeforeClass { #[violation] pub struct OneBlankLineAfterClass; -impl AlwaysAutofixableViolation for OneBlankLineAfterClass { +impl AlwaysFixableViolation for OneBlankLineAfterClass { #[derive_message_formats] fn message(&self) -> String { format!("1 blank line required after class docstring") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Insert 1 blank line after class docstring".to_string() } } @@ -140,13 +140,13 @@ impl AlwaysAutofixableViolation for OneBlankLineAfterClass { #[violation] pub struct BlankLineBeforeClass; -impl AlwaysAutofixableViolation for BlankLineBeforeClass { +impl AlwaysFixableViolation for BlankLineBeforeClass { #[derive_message_formats] fn message(&self) -> String { format!("No blank lines allowed before class docstring") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove blank line(s) before class docstring".to_string() } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs index 66428fa76ecf8..d010bc64a11eb 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/blank_before_after_function.rs @@ -1,7 +1,7 @@ use once_cell::sync::Lazy; use regex::Regex; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_trivia::PythonWhitespace; use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; @@ -42,14 +42,14 @@ pub struct NoBlankLineBeforeFunction { num_lines: usize, } -impl AlwaysAutofixableViolation for NoBlankLineBeforeFunction { +impl AlwaysFixableViolation for NoBlankLineBeforeFunction { #[derive_message_formats] fn message(&self) -> String { let NoBlankLineBeforeFunction { num_lines } = self; format!("No blank lines allowed before function docstring (found {num_lines})") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove blank line(s) before function docstring".to_string() } } @@ -86,14 +86,14 @@ pub struct NoBlankLineAfterFunction { num_lines: usize, } -impl AlwaysAutofixableViolation for NoBlankLineAfterFunction { +impl AlwaysFixableViolation for NoBlankLineAfterFunction { #[derive_message_formats] fn message(&self) -> String { let NoBlankLineAfterFunction { num_lines } = self; format!("No blank lines allowed after function docstring (found {num_lines})") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove blank line(s) after function docstring".to_string() } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs index afcc313c80f6d..209fae42f551b 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/capitalized.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; use ruff_text_size::{TextLen, TextRange}; @@ -36,7 +36,7 @@ pub struct FirstLineCapitalized { capitalized_word: String, } -impl AlwaysAutofixableViolation for FirstLineCapitalized { +impl AlwaysFixableViolation for FirstLineCapitalized { #[derive_message_formats] fn message(&self) -> String { format!( @@ -45,7 +45,7 @@ impl AlwaysAutofixableViolation for FirstLineCapitalized { ) } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!( "Capitalize `{}` to `{}`", self.first_word, self.capitalized_word diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs index 57c2b63fd0016..01830140e558a 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_period.rs @@ -1,7 +1,7 @@ use ruff_text_size::TextLen; use strum::IntoEnumIterator; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use ruff_text_size::Ranged; @@ -47,13 +47,13 @@ use crate::rules::pydocstyle::helpers::logical_line; #[violation] pub struct EndsInPeriod; -impl AlwaysAutofixableViolation for EndsInPeriod { +impl AlwaysFixableViolation for EndsInPeriod { #[derive_message_formats] fn message(&self) -> String { format!("First line should end with a period") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Add period".to_string() } } @@ -103,7 +103,7 @@ pub(crate) fn ends_with_period(checker: &mut Checker, docstring: &Docstring) { if !trimmed.ends_with('.') { let mut diagnostic = Diagnostic::new(EndsInPeriod, docstring.range()); - // Best-effort autofix: avoid adding a period after other punctuation marks. + // Best-effort fix: avoid adding a period after other punctuation marks. if checker.patch(diagnostic.kind.rule()) && !trimmed.ends_with([':', ';']) { diagnostic.set_fix(Fix::suggested(Edit::insertion( ".".to_string(), diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs index 05ec17ddb1500..8abc42f855b11 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/ends_with_punctuation.rs @@ -1,7 +1,7 @@ use ruff_text_size::TextLen; use strum::IntoEnumIterator; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::{UniversalNewlineIterator, UniversalNewlines}; use ruff_text_size::Ranged; @@ -46,13 +46,13 @@ use crate::rules::pydocstyle::helpers::logical_line; #[violation] pub struct EndsInPunctuation; -impl AlwaysAutofixableViolation for EndsInPunctuation { +impl AlwaysFixableViolation for EndsInPunctuation { #[derive_message_formats] fn message(&self) -> String { format!("First line should end with a period, question mark, or exclamation point") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Add closing punctuation".to_string() } } @@ -102,7 +102,7 @@ pub(crate) fn ends_with_punctuation(checker: &mut Checker, docstring: &Docstring if !trimmed.ends_with(['.', '!', '?']) { let mut diagnostic = Diagnostic::new(EndsInPunctuation, docstring.range()); - // Best-effort autofix: avoid adding a period after other punctuation marks. + // Best-effort fix: avoid adding a period after other punctuation marks. if checker.patch(diagnostic.kind.rule()) && !trimmed.ends_with([':', ';']) { diagnostic.set_fix(Fix::suggested(Edit::insertion( ".".to_string(), diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs index c33bbea24a6d8..702227dc92e15 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/indent.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::docstrings::{clean_space, leading_space}; @@ -88,13 +88,13 @@ impl Violation for IndentWithSpaces { #[violation] pub struct UnderIndentation; -impl AlwaysAutofixableViolation for UnderIndentation { +impl AlwaysFixableViolation for UnderIndentation { #[derive_message_formats] fn message(&self) -> String { format!("Docstring is under-indented") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Increase indentation".to_string() } } @@ -135,13 +135,13 @@ impl AlwaysAutofixableViolation for UnderIndentation { #[violation] pub struct OverIndentation; -impl AlwaysAutofixableViolation for OverIndentation { +impl AlwaysFixableViolation for OverIndentation { #[derive_message_formats] fn message(&self) -> String { format!("Docstring is over-indented") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove over-indentation".to_string() } } @@ -182,7 +182,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) { if checker.enabled(Rule::UnderIndentation) { // We report under-indentation on every line. This isn't great, but enables - // autofix. + // fix. if (i == lines.len() - 1 || !is_blank) && line_indent.len() < docstring.indentation.len() { @@ -226,7 +226,7 @@ pub(crate) fn indent(checker: &mut Checker, docstring: &Docstring) { if is_over_indented { for over_indented in over_indented_lines { // We report over-indentation on every line. This isn't great, but - // enables autofix. + // enables fix. let mut diagnostic = Diagnostic::new(OverIndentation, TextRange::empty(over_indented.start())); if checker.patch(diagnostic.kind.rule()) { diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs index f354a718dd4e8..cd0a0cde9f3ee 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/multi_line_summary_start.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::str::{is_triple_quote, leading_quote}; use ruff_python_semantic::Definition; @@ -52,13 +52,13 @@ use crate::registry::{AsRule, Rule}; #[violation] pub struct MultiLineSummaryFirstLine; -impl AlwaysAutofixableViolation for MultiLineSummaryFirstLine { +impl AlwaysFixableViolation for MultiLineSummaryFirstLine { #[derive_message_formats] fn message(&self) -> String { format!("Multi-line docstring summary should start at the first line") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove whitespace after opening quotes".to_string() } } @@ -106,13 +106,13 @@ impl AlwaysAutofixableViolation for MultiLineSummaryFirstLine { #[violation] pub struct MultiLineSummarySecondLine; -impl AlwaysAutofixableViolation for MultiLineSummarySecondLine { +impl AlwaysFixableViolation for MultiLineSummarySecondLine { #[derive_message_formats] fn message(&self) -> String { format!("Multi-line docstring summary should start at the second line") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Insert line break and indentation after opening quotes".to_string() } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs index 55b5c2015329d..0e0be209a36a7 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/newline_after_last_paragraph.rs @@ -1,6 +1,6 @@ use ruff_text_size::{TextLen, TextSize}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::docstrings::clean_space; use ruff_source_file::{NewlineWithTrailingNewline, UniversalNewlines}; @@ -47,13 +47,13 @@ use crate::registry::AsRule; #[violation] pub struct NewLineAfterLastParagraph; -impl AlwaysAutofixableViolation for NewLineAfterLastParagraph { +impl AlwaysFixableViolation for NewLineAfterLastParagraph { #[derive_message_formats] fn message(&self) -> String { format!("Multi-line docstring closing quotes should be on a separate line") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Move closing quotes to new line".to_string() } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs index f4f4223255146..1ac7ed09cf074 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/no_surrounding_whitespace.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::NewlineWithTrailingNewline; use ruff_text_size::Ranged; @@ -35,14 +35,14 @@ use crate::rules::pydocstyle::helpers::ends_with_backslash; pub struct SurroundingWhitespace; impl Violation for SurroundingWhitespace { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("No whitespaces allowed surrounding docstring text") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Trim surrounding whitespace".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs index dea59eae98ce2..e11ce65c039c5 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/one_liner.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::str::{leading_quote, trailing_quote}; use ruff_source_file::NewlineWithTrailingNewline; @@ -37,14 +37,14 @@ use crate::registry::AsRule; pub struct FitsOnOneLine; impl Violation for FitsOnOneLine { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("One-line docstring should fit on one line") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Reformat to one line".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs index c075ecacace09..66a0b8ad7199a 100644 --- a/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs +++ b/crates/ruff_linter/src/rules/pydocstyle/rules/sections.rs @@ -3,7 +3,7 @@ use once_cell::sync::Lazy; use regex::Regex; use rustc_hash::FxHashSet; -use ruff_diagnostics::{AlwaysAutofixableViolation, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Violation}; use ruff_diagnostics::{Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::docstrings::{clean_space, leading_space}; @@ -88,14 +88,14 @@ pub struct SectionNotOverIndented { name: String, } -impl AlwaysAutofixableViolation for SectionNotOverIndented { +impl AlwaysFixableViolation for SectionNotOverIndented { #[derive_message_formats] fn message(&self) -> String { let SectionNotOverIndented { name } = self; format!("Section is over-indented (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let SectionNotOverIndented { name } = self; format!("Remove over-indentation from \"{name}\"") } @@ -186,14 +186,14 @@ pub struct SectionUnderlineNotOverIndented { name: String, } -impl AlwaysAutofixableViolation for SectionUnderlineNotOverIndented { +impl AlwaysFixableViolation for SectionUnderlineNotOverIndented { #[derive_message_formats] fn message(&self) -> String { let SectionUnderlineNotOverIndented { name } = self; format!("Section underline is over-indented (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let SectionUnderlineNotOverIndented { name } = self; format!("Remove over-indentation from \"{name}\" underline") } @@ -265,14 +265,14 @@ pub struct CapitalizeSectionName { name: String, } -impl AlwaysAutofixableViolation for CapitalizeSectionName { +impl AlwaysFixableViolation for CapitalizeSectionName { #[derive_message_formats] fn message(&self) -> String { let CapitalizeSectionName { name } = self; format!("Section name should be properly capitalized (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let CapitalizeSectionName { name } = self; format!("Capitalize \"{name}\"") } @@ -361,14 +361,14 @@ pub struct NewLineAfterSectionName { name: String, } -impl AlwaysAutofixableViolation for NewLineAfterSectionName { +impl AlwaysFixableViolation for NewLineAfterSectionName { #[derive_message_formats] fn message(&self) -> String { let NewLineAfterSectionName { name } = self; format!("Section name should end with a newline (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let NewLineAfterSectionName { name } = self; format!("Add newline after \"{name}\"") } @@ -457,14 +457,14 @@ pub struct DashedUnderlineAfterSection { name: String, } -impl AlwaysAutofixableViolation for DashedUnderlineAfterSection { +impl AlwaysFixableViolation for DashedUnderlineAfterSection { #[derive_message_formats] fn message(&self) -> String { let DashedUnderlineAfterSection { name } = self; format!("Missing dashed underline after section (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let DashedUnderlineAfterSection { name } = self; format!("Add dashed line under \"{name}\"") } @@ -559,14 +559,14 @@ pub struct SectionUnderlineAfterName { name: String, } -impl AlwaysAutofixableViolation for SectionUnderlineAfterName { +impl AlwaysFixableViolation for SectionUnderlineAfterName { #[derive_message_formats] fn message(&self) -> String { let SectionUnderlineAfterName { name } = self; format!("Section underline should be in the line following the section's name (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let SectionUnderlineAfterName { name } = self; format!("Add underline to \"{name}\"") } @@ -658,14 +658,14 @@ pub struct SectionUnderlineMatchesSectionLength { name: String, } -impl AlwaysAutofixableViolation for SectionUnderlineMatchesSectionLength { +impl AlwaysFixableViolation for SectionUnderlineMatchesSectionLength { #[derive_message_formats] fn message(&self) -> String { let SectionUnderlineMatchesSectionLength { name } = self; format!("Section underline should match the length of its name (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let SectionUnderlineMatchesSectionLength { name } = self; format!("Adjust underline length to match \"{name}\"") } @@ -753,14 +753,14 @@ pub struct NoBlankLineAfterSection { name: String, } -impl AlwaysAutofixableViolation for NoBlankLineAfterSection { +impl AlwaysFixableViolation for NoBlankLineAfterSection { #[derive_message_formats] fn message(&self) -> String { let NoBlankLineAfterSection { name } = self; format!("Missing blank line after section (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let NoBlankLineAfterSection { name } = self; format!("Add blank line after \"{name}\"") } @@ -846,14 +846,14 @@ pub struct NoBlankLineBeforeSection { name: String, } -impl AlwaysAutofixableViolation for NoBlankLineBeforeSection { +impl AlwaysFixableViolation for NoBlankLineBeforeSection { #[derive_message_formats] fn message(&self) -> String { let NoBlankLineBeforeSection { name } = self; format!("Missing blank line before section (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let NoBlankLineBeforeSection { name } = self; format!("Add blank line before \"{name}\"") } @@ -942,14 +942,14 @@ pub struct BlankLineAfterLastSection { name: String, } -impl AlwaysAutofixableViolation for BlankLineAfterLastSection { +impl AlwaysFixableViolation for BlankLineAfterLastSection { #[derive_message_formats] fn message(&self) -> String { let BlankLineAfterLastSection { name } = self; format!("Missing blank line after last section (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let BlankLineAfterLastSection { name } = self; format!("Add blank line after \"{name}\"") } @@ -1109,14 +1109,14 @@ pub struct SectionNameEndsInColon { name: String, } -impl AlwaysAutofixableViolation for SectionNameEndsInColon { +impl AlwaysFixableViolation for SectionNameEndsInColon { #[derive_message_formats] fn message(&self) -> String { let SectionNameEndsInColon { name } = self; format!("Section name should end with a colon (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let SectionNameEndsInColon { name } = self; format!("Add colon to \"{name}\"") } @@ -1276,14 +1276,14 @@ pub struct BlankLinesBetweenHeaderAndContent { name: String, } -impl AlwaysAutofixableViolation for BlankLinesBetweenHeaderAndContent { +impl AlwaysFixableViolation for BlankLinesBetweenHeaderAndContent { #[derive_message_formats] fn message(&self) -> String { let BlankLinesBetweenHeaderAndContent { name } = self; format!("No blank lines allowed between a section header and its content (\"{name}\")") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove blank line(s)".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs b/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs index 779ed539bb7c1..f4912caf61d79 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/f_string_missing_placeholders.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{Expr, PySourceType}; use ruff_python_parser::{lexer, AsMode, StringKind, Tok}; @@ -36,13 +36,13 @@ use crate::registry::AsRule; #[violation] pub struct FStringMissingPlaceholders; -impl AlwaysAutofixableViolation for FStringMissingPlaceholders { +impl AlwaysFixableViolation for FStringMissingPlaceholders { #[derive_message_formats] fn message(&self) -> String { format!("f-string without any placeholders") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove extraneous `f` prefix".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs index c4d0364b28456..8beed9661a634 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/invalid_literal_comparisons.rs @@ -1,7 +1,7 @@ use log::error; use ruff_python_ast::{CmpOp, Expr}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers; use ruff_python_parser::locate_cmp_ops; @@ -50,7 +50,7 @@ pub struct IsLiteral { cmp_op: IsCmpOp, } -impl AlwaysAutofixableViolation for IsLiteral { +impl AlwaysFixableViolation for IsLiteral { #[derive_message_formats] fn message(&self) -> String { let IsLiteral { cmp_op } = self; @@ -60,7 +60,7 @@ impl AlwaysAutofixableViolation for IsLiteral { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let IsLiteral { cmp_op } = self; match cmp_op { IsCmpOp::Is => "Replace `is` with `==`".to_string(), diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs b/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs index 6fad3fde6d869..6998e19d4249c 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/raise_not_implemented.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{self as ast, Expr}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -39,14 +39,14 @@ use crate::registry::AsRule; pub struct RaiseNotImplemented; impl Violation for RaiseNotImplemented { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("`raise NotImplemented` should be `raise NotImplementedError`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Use `raise NotImplementedError`".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs b/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs index 6926d15d675a9..e4f53392568f3 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs @@ -2,15 +2,15 @@ use std::hash::BuildHasherDefault; use rustc_hash::{FxHashMap, FxHashSet}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; -use crate::autofix::snippet::SourceCodeSnippet; use crate::checkers::ast::Checker; +use crate::fix::snippet::SourceCodeSnippet; use crate::registry::{AsRule, Rule}; /// ## What it does @@ -49,7 +49,7 @@ pub struct MultiValueRepeatedKeyLiteral { } impl Violation for MultiValueRepeatedKeyLiteral { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -61,7 +61,7 @@ impl Violation for MultiValueRepeatedKeyLiteral { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let MultiValueRepeatedKeyLiteral { name } = self; if let Some(name) = name.full_display() { Some(format!("Remove repeated key literal `{name}`")) @@ -106,7 +106,7 @@ pub struct MultiValueRepeatedKeyVariable { } impl Violation for MultiValueRepeatedKeyVariable { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -118,7 +118,7 @@ impl Violation for MultiValueRepeatedKeyVariable { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let MultiValueRepeatedKeyVariable { name } = self; if let Some(name) = name.full_display() { Some(format!("Remove repeated key `{name}`")) diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs index 3d4de1a14808a..28f30928280fc 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs @@ -2,7 +2,7 @@ use std::string::ToString; use rustc_hash::FxHashSet; -use ruff_diagnostics::{AlwaysAutofixableViolation, AutofixKind, Diagnostic, Fix, Violation}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Constant, Expr, Identifier, Keyword}; use ruff_text_size::{Ranged, TextRange}; @@ -145,7 +145,7 @@ pub struct PercentFormatExtraNamedArguments { missing: Vec, } -impl AlwaysAutofixableViolation for PercentFormatExtraNamedArguments { +impl AlwaysFixableViolation for PercentFormatExtraNamedArguments { #[derive_message_formats] fn message(&self) -> String { let PercentFormatExtraNamedArguments { missing } = self; @@ -153,7 +153,7 @@ impl AlwaysAutofixableViolation for PercentFormatExtraNamedArguments { format!("`%`-format string has unused named argument(s): {message}") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let PercentFormatExtraNamedArguments { missing } = self; let message = missing.join(", "); format!("Remove extra named arguments: {message}") @@ -387,7 +387,7 @@ pub struct StringDotFormatExtraNamedArguments { } impl Violation for StringDotFormatExtraNamedArguments { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -396,7 +396,7 @@ impl Violation for StringDotFormatExtraNamedArguments { format!("`.format` call has unused named argument(s): {message}") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let StringDotFormatExtraNamedArguments { missing } = self; let message = missing.join(", "); Some(format!("Remove extra named arguments: {message}")) @@ -428,7 +428,7 @@ pub struct StringDotFormatExtraPositionalArguments { } impl Violation for StringDotFormatExtraPositionalArguments { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -437,7 +437,7 @@ impl Violation for StringDotFormatExtraPositionalArguments { format!("`.format` call has unused arguments at position(s): {message}") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let StringDotFormatExtraPositionalArguments { missing } = self; let message = missing.join(", "); Some(format!( diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs index d9899a483f1cd..ed4c671a4ec29 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs @@ -3,13 +3,13 @@ use std::borrow::Cow; use anyhow::Result; use rustc_hash::FxHashMap; -use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::{AnyImport, Exceptions, Imported, NodeId, Scope}; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix; use crate::checkers::ast::Checker; +use crate::fix; use crate::registry::Rule; #[derive(Debug, Copy, Clone, Eq, PartialEq)] @@ -67,7 +67,7 @@ pub struct UnusedImport { } impl Violation for UnusedImport { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -87,7 +87,7 @@ impl Violation for UnusedImport { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let UnusedImport { name, multiple, .. } = self; Some(if *multiple { "Remove unused import".to_string() @@ -243,7 +243,7 @@ fn fix_imports(checker: &Checker, node_id: NodeId, imports: &[ImportBinding]) -> .map(Imported::member_name) .collect(); - let edit = autofix::edits::remove_unused_imports( + let edit = fix::edits::remove_unused_imports( member_names.iter().map(AsRef::as_ref), statement, parent, diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs b/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs index 64aaa16e757dc..66f1d1449a1a4 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_variable.rs @@ -1,6 +1,6 @@ use itertools::Itertools; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::contains_effect; use ruff_python_ast::parenthesize::parenthesized_range; @@ -10,8 +10,8 @@ use ruff_python_semantic::{Binding, Scope}; use ruff_source_file::Locator; use ruff_text_size::{Ranged, TextRange, TextSize}; -use crate::autofix::edits::delete_stmt; use crate::checkers::ast::Checker; +use crate::fix::edits::delete_stmt; use crate::registry::AsRule; /// ## What it does @@ -48,7 +48,7 @@ pub struct UnusedVariable { } impl Violation for UnusedVariable { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -56,7 +56,7 @@ impl Violation for UnusedVariable { format!("Local variable `{name}` is assigned to but never used") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let UnusedVariable { name } = self; Some(format!("Remove assignment to unused variable `{name}`")) } diff --git a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs index 9132100f0817e..ce02b12fff433 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/comparison_with_itself.rs @@ -1,6 +1,6 @@ use itertools::Itertools; -use crate::autofix::snippet::SourceCodeSnippet; +use crate::fix::snippet::SourceCodeSnippet; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{CmpOp, Expr}; diff --git a/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs b/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs index 2bd640f326c4a..36e191cddc49e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/invalid_string_characters.rs @@ -1,6 +1,6 @@ use ruff_text_size::{TextLen, TextRange, TextSize}; -use ruff_diagnostics::AlwaysAutofixableViolation; +use ruff_diagnostics::AlwaysFixableViolation; use ruff_diagnostics::Edit; use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix}; use ruff_macros::{derive_message_formats, violation}; @@ -28,13 +28,13 @@ use ruff_source_file::Locator; #[violation] pub struct InvalidCharacterBackspace; -impl AlwaysAutofixableViolation for InvalidCharacterBackspace { +impl AlwaysFixableViolation for InvalidCharacterBackspace { #[derive_message_formats] fn message(&self) -> String { format!("Invalid unescaped character backspace, use \"\\b\" instead") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with escape sequence".to_string() } } @@ -61,13 +61,13 @@ impl AlwaysAutofixableViolation for InvalidCharacterBackspace { #[violation] pub struct InvalidCharacterSub; -impl AlwaysAutofixableViolation for InvalidCharacterSub { +impl AlwaysFixableViolation for InvalidCharacterSub { #[derive_message_formats] fn message(&self) -> String { format!("Invalid unescaped character SUB, use \"\\x1A\" instead") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with escape sequence".to_string() } } @@ -94,13 +94,13 @@ impl AlwaysAutofixableViolation for InvalidCharacterSub { #[violation] pub struct InvalidCharacterEsc; -impl AlwaysAutofixableViolation for InvalidCharacterEsc { +impl AlwaysFixableViolation for InvalidCharacterEsc { #[derive_message_formats] fn message(&self) -> String { format!("Invalid unescaped character ESC, use \"\\x1B\" instead") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with escape sequence".to_string() } } @@ -127,13 +127,13 @@ impl AlwaysAutofixableViolation for InvalidCharacterEsc { #[violation] pub struct InvalidCharacterNul; -impl AlwaysAutofixableViolation for InvalidCharacterNul { +impl AlwaysFixableViolation for InvalidCharacterNul { #[derive_message_formats] fn message(&self) -> String { format!("Invalid unescaped character NUL, use \"\\0\" instead") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with escape sequence".to_string() } } @@ -159,13 +159,13 @@ impl AlwaysAutofixableViolation for InvalidCharacterNul { #[violation] pub struct InvalidCharacterZeroWidthSpace; -impl AlwaysAutofixableViolation for InvalidCharacterZeroWidthSpace { +impl AlwaysFixableViolation for InvalidCharacterZeroWidthSpace { #[derive_message_formats] fn message(&self) -> String { format!("Invalid unescaped character zero-width-space, use \"\\u200B\" instead") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with escape sequence".to_string() } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs b/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs index c3c91f08f7e58..05d035fee28d5 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Alias, Identifier, Stmt}; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use crate::checkers::ast::Checker; @@ -33,7 +33,7 @@ pub struct ManualFromImport { } impl Violation for ManualFromImport { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -41,7 +41,7 @@ impl Violation for ManualFromImport { format!("Use `from {module} import {name}` in lieu of alias") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let ManualFromImport { module, name } = self; Some(format!("Replace with `from {module} import {name}`")) } diff --git a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs index 7e76598817495..758fd845e62d6 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Arguments, Expr, Keyword}; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_semantic::SemanticModel; @@ -43,7 +43,7 @@ pub struct NestedMinMax { } impl Violation for NestedMinMax { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] @@ -52,7 +52,7 @@ impl Violation for NestedMinMax { format!("Nested `{func}` calls can be flattened") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let NestedMinMax { func } = self; Some(format!("Flatten nested `{func}` calls")) } diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs index 67b7c2c069c88..2f6a4e66e2b32 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs @@ -12,8 +12,8 @@ use ruff_python_ast::{self as ast, BoolOp, CmpOp, Expr}; use ruff_source_file::Locator; use ruff_text_size::{Ranged, TextSize}; -use crate::autofix::snippet::SourceCodeSnippet; use crate::checkers::ast::Checker; +use crate::fix::snippet::SourceCodeSnippet; /// ## What it does /// Checks for repeated equality comparisons that can rewritten as a membership diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs index 9b7e40a09233c..b038d8f15e8a1 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_isinstance_calls.rs @@ -2,9 +2,9 @@ use itertools::Itertools; use ruff_python_ast::{self as ast, Arguments, BoolOp, Expr}; use rustc_hash::{FxHashMap, FxHashSet}; -use crate::autofix::edits::pad; -use crate::autofix::snippet::SourceCodeSnippet; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use crate::fix::edits::pad; +use crate::fix::snippet::SourceCodeSnippet; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::hashable::HashableExpr; use ruff_text_size::Ranged; @@ -49,7 +49,7 @@ pub struct RepeatedIsinstanceCalls { expression: SourceCodeSnippet, } -impl AlwaysAutofixableViolation for RepeatedIsinstanceCalls { +impl AlwaysFixableViolation for RepeatedIsinstanceCalls { #[derive_message_formats] fn message(&self) -> String { let RepeatedIsinstanceCalls { expression } = self; @@ -60,7 +60,7 @@ impl AlwaysAutofixableViolation for RepeatedIsinstanceCalls { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let RepeatedIsinstanceCalls { expression } = self; if let Some(expression) = expression.full_display() { format!("Replace with `{expression}`") diff --git a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs index 3fe8cacf5036d..558717c255f3c 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/sys_exit_alias.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{self as ast, Expr}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -43,7 +43,7 @@ pub struct SysExitAlias { } impl Violation for SysExitAlias { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -51,7 +51,7 @@ impl Violation for SysExitAlias { format!("Use `sys.exit()` instead of `{name}`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let SysExitAlias { name } = self; Some(format!("Replace `{name}` with `sys.exit()`")) } diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs index fabdc4e91cc4e..ce6ac9ad0c73e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_import_alias.rs @@ -1,6 +1,6 @@ use ruff_python_ast::Alias; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -25,13 +25,13 @@ use crate::registry::AsRule; #[violation] pub struct UselessImportAlias; -impl AlwaysAutofixableViolation for UselessImportAlias { +impl AlwaysFixableViolation for UselessImportAlias { #[derive_message_formats] fn message(&self) -> String { format!("Import alias does not rename original package") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove import alias".to_string() } } diff --git a/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs b/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs index 6df823f386ee8..3effece5698cb 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/useless_return.rs @@ -1,13 +1,13 @@ use ruff_python_ast::{self as ast, Constant, Expr, Stmt}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::{is_const_none, ReturnStatementVisitor}; use ruff_python_ast::statement_visitor::StatementVisitor; use ruff_text_size::Ranged; -use crate::autofix; use crate::checkers::ast::Checker; +use crate::fix; use crate::registry::AsRule; /// ## What it does @@ -33,13 +33,13 @@ use crate::registry::AsRule; #[violation] pub struct UselessReturn; -impl AlwaysAutofixableViolation for UselessReturn { +impl AlwaysFixableViolation for UselessReturn { #[derive_message_formats] fn message(&self) -> String { format!("Useless `return` statement at end of function") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Remove useless `return` statement") } } @@ -104,12 +104,8 @@ pub(crate) fn useless_return( let mut diagnostic = Diagnostic::new(UselessReturn, last_stmt.range()); if checker.patch(diagnostic.kind.rule()) { - let edit = autofix::edits::delete_stmt( - last_stmt, - Some(stmt), - checker.locator(), - checker.indexer(), - ); + let edit = + fix::edits::delete_stmt(last_stmt, Some(stmt), checker.locator(), checker.indexer()); diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation(Some( checker.semantic().current_statement_id(), )))); diff --git a/crates/ruff_linter/src/rules/pyupgrade/fixes.rs b/crates/ruff_linter/src/rules/pyupgrade/fixes.rs index 648d644f3c43e..f890fa55cb1ee 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/fixes.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/fixes.rs @@ -5,8 +5,8 @@ use ruff_python_parser::{lexer, Mode, Tok}; use ruff_source_file::Locator; use ruff_text_size::{TextRange, TextSize}; -use crate::autofix::codemods::CodegenStylist; use crate::cst::matchers::{match_function_def, match_indented_block, match_statement}; +use crate::fix::codemods::CodegenStylist; /// Safely adjust the indentation of the indented block at [`TextRange`]. pub(crate) fn adjust_indentation( diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs index 3bb6b2a28ca2f..e090bd3275283 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs @@ -1,6 +1,6 @@ use log::debug; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_dunder; use ruff_python_ast::{ @@ -50,7 +50,7 @@ pub struct ConvertNamedTupleFunctionalToClass { } impl Violation for ConvertNamedTupleFunctionalToClass { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -58,7 +58,7 @@ impl Violation for ConvertNamedTupleFunctionalToClass { format!("Convert `{name}` from `NamedTuple` functional to class syntax") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let ConvertNamedTupleFunctionalToClass { name } = self; Some(format!("Convert `{name}` to class syntax")) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs index 1ef6f69e84289..688ef4c46a527 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_dunder; use ruff_python_ast::{ @@ -47,7 +47,7 @@ pub struct ConvertTypedDictFunctionalToClass { } impl Violation for ConvertTypedDictFunctionalToClass { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -55,7 +55,7 @@ impl Violation for ConvertTypedDictFunctionalToClass { format!("Convert `{name}` from `TypedDict` functional to class syntax") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let ConvertTypedDictFunctionalToClass { name } = self; Some(format!("Convert `{name}` to class syntax")) } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs index 7c8314083f8b1..715c780c94f79 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/datetime_utc_alias.rs @@ -1,6 +1,6 @@ use ruff_python_ast::Expr; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -38,14 +38,14 @@ use crate::registry::AsRule; pub struct DatetimeTimezoneUTC; impl Violation for DatetimeTimezoneUTC { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use `datetime.UTC` alias") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Convert to `datetime.UTC` alias".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs index f3e35e08d573c..4e663531c4e1a 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_c_element_tree.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Stmt}; use ruff_text_size::Ranged; @@ -28,13 +28,13 @@ use crate::registry::AsRule; #[violation] pub struct DeprecatedCElementTree; -impl AlwaysAutofixableViolation for DeprecatedCElementTree { +impl AlwaysFixableViolation for DeprecatedCElementTree { #[derive_message_formats] fn message(&self) -> String { format!("`cElementTree` is deprecated, use `ElementTree`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with `ElementTree`".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs index 6a2f385215b04..f54b9e501b121 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_import.rs @@ -1,7 +1,7 @@ use itertools::Itertools; use ruff_python_ast::{Alias, Stmt}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::whitespace::indentation; use ruff_python_codegen::Stylist; @@ -66,7 +66,7 @@ pub struct DeprecatedImport { } impl Violation for DeprecatedImport { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -87,7 +87,7 @@ impl Violation for DeprecatedImport { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { if let Deprecation::WithoutRename(WithoutRename { target, .. }) = &self.deprecation { Some(format!("Import from `{target}`")) } else { diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs index 2272d6aabaa99..6a0b1016eb774 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_mock_import.rs @@ -6,8 +6,8 @@ use libcst_native::{ use log::error; use ruff_python_ast::{self as ast, Expr, Stmt}; -use crate::autofix::codemods::CodegenStylist; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use crate::fix::codemods::CodegenStylist; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path::collect_call_path; use ruff_python_ast::whitespace::indentation; @@ -52,13 +52,13 @@ pub struct DeprecatedMockImport { reference_type: MockReference, } -impl AlwaysAutofixableViolation for DeprecatedMockImport { +impl AlwaysFixableViolation for DeprecatedMockImport { #[derive_message_formats] fn message(&self) -> String { format!("`mock` is deprecated, use `unittest.mock`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let DeprecatedMockImport { reference_type } = self; match reference_type { MockReference::Import => "Import from `unittest.mock` instead".to_string(), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs index 3f64f64395b5b..aa32e5b2da830 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/deprecated_unittest_alias.rs @@ -2,7 +2,7 @@ use once_cell::sync::Lazy; use ruff_python_ast::{self as ast, Expr}; use rustc_hash::FxHashMap; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -45,14 +45,14 @@ pub struct DeprecatedUnittestAlias { target: String, } -impl AlwaysAutofixableViolation for DeprecatedUnittestAlias { +impl AlwaysFixableViolation for DeprecatedUnittestAlias { #[derive_message_formats] fn message(&self) -> String { let DeprecatedUnittestAlias { alias, target } = self; format!("`{alias}` is deprecated, use `{target}`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let DeprecatedUnittestAlias { alias, target } = self; format!("Replace `{target}` with `{alias}`") } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs index 7e82eaf2b297d..8bf7b35f80285 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/extraneous_parentheses.rs @@ -2,7 +2,7 @@ use ruff_python_parser::lexer::LexResult; use ruff_python_parser::Tok; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_source_file::Locator; @@ -28,13 +28,13 @@ use crate::settings::LinterSettings; #[violation] pub struct ExtraneousParentheses; -impl AlwaysAutofixableViolation for ExtraneousParentheses { +impl AlwaysFixableViolation for ExtraneousParentheses { #[derive_message_formats] fn message(&self) -> String { format!("Avoid extraneous parentheses") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove extraneous parentheses".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs index 7241591956f84..996bb31e35902 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/f_strings.rs @@ -3,7 +3,7 @@ use std::borrow::Cow; use anyhow::{Context, Result}; use rustc_hash::FxHashMap; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::str::{leading_quote, trailing_quote}; use ruff_python_ast::{self as ast, Constant, Expr, Keyword}; @@ -44,14 +44,14 @@ use crate::rules::pyupgrade::helpers::curly_escape; pub struct FString; impl Violation for FString { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use f-string instead of `format` call") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Convert to f-string".to_string()) } } @@ -413,7 +413,7 @@ pub(crate) fn f_strings( let mut diagnostic = Diagnostic::new(FString, call.range()); - // Avoid autofix if there are comments within the call: + // Avoid fix if there are comments within the call: // ``` // "{}".format( // 0, # 0 diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs index cf689fef3cf96..7d52f58b78033 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/format_literals.rs @@ -3,18 +3,18 @@ use libcst_native::{Arg, Expression}; use once_cell::sync::Lazy; use regex::Regex; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_codegen::Stylist; use ruff_source_file::Locator; use ruff_text_size::Ranged; -use crate::autofix::codemods::CodegenStylist; use crate::checkers::ast::Checker; use crate::cst::matchers::{ match_attribute, match_call_mut, match_expression, transform_expression_text, }; +use crate::fix::codemods::CodegenStylist; use crate::registry::AsRule; use crate::rules::pyflakes::format::FormatSummary; @@ -46,14 +46,14 @@ use crate::rules::pyflakes::format::FormatSummary; pub struct FormatLiterals; impl Violation for FormatLiterals { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use implicit references for positional format fields") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Remove explicit positional indices".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs index accf01c3fc463..e45108505a666 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_with_maxsize_none.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Arguments, Decorator, Expr, Keyword}; use ruff_text_size::{Ranged, TextRange}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_const_none; @@ -45,13 +45,13 @@ use crate::registry::AsRule; #[violation] pub struct LRUCacheWithMaxsizeNone; -impl AlwaysAutofixableViolation for LRUCacheWithMaxsizeNone { +impl AlwaysFixableViolation for LRUCacheWithMaxsizeNone { #[derive_message_formats] fn message(&self) -> String { format!("Use `@functools.cache` instead of `@functools.lru_cache(maxsize=None)`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Rewrite with `@functools.cache".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs index 7553ca937a0e3..7c7d5399150af 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Decorator, Expr}; use ruff_text_size::{Ranged, TextRange}; @@ -42,13 +42,13 @@ use crate::registry::AsRule; #[violation] pub struct LRUCacheWithoutParameters; -impl AlwaysAutofixableViolation for LRUCacheWithoutParameters { +impl AlwaysFixableViolation for LRUCacheWithoutParameters { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary parentheses to `functools.lru_cache`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove unnecessary parentheses".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs index 18b9670acb7be..de105146ebcc7 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use num_bigint::BigInt; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Constant, Expr}; use ruff_text_size::Ranged; @@ -109,14 +109,14 @@ pub struct NativeLiterals { literal_type: LiteralType, } -impl AlwaysAutofixableViolation for NativeLiterals { +impl AlwaysFixableViolation for NativeLiterals { #[derive_message_formats] fn message(&self) -> String { let NativeLiterals { literal_type } = self; format!("Unnecessary `{literal_type}` call (rewrite as a literal)") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let NativeLiterals { literal_type } = self; match literal_type { LiteralType::Str => "Replace with empty string".to_string(), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs index 7b93725354b7c..b34b610a54535 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/open_alias.rs @@ -1,6 +1,6 @@ use ruff_python_ast::Expr; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -34,14 +34,14 @@ use crate::registry::AsRule; pub struct OpenAlias; impl Violation for OpenAlias { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use builtin `open`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Replace with builtin `open`".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs index b8295556195a2..6cdb8bfff0a04 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs @@ -1,8 +1,8 @@ use ruff_python_ast::{self as ast, ExceptHandler, Expr, ExprContext}; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix::edits::pad; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use crate::fix::edits::pad; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path::compose_call_path; use ruff_python_semantic::SemanticModel; @@ -40,13 +40,13 @@ pub struct OSErrorAlias { name: Option, } -impl AlwaysAutofixableViolation for OSErrorAlias { +impl AlwaysFixableViolation for OSErrorAlias { #[derive_message_formats] fn message(&self) -> String { format!("Replace aliased errors with `OSError`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let OSErrorAlias { name } = self; match name { None => "Replace with builtin `OSError`".to_string(), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs index 3fdcd57245df8..9632eeed2c8eb 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/outdated_version_block.rs @@ -2,15 +2,15 @@ use std::cmp::Ordering; use num_bigint::{BigInt, Sign}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::stmt_if::{if_elif_branches, BranchKind, IfElifBranch}; use ruff_python_ast::whitespace::indentation; use ruff_python_ast::{self as ast, CmpOp, Constant, ElifElseClause, Expr, StmtIf}; use ruff_text_size::{Ranged, TextLen, TextRange}; -use crate::autofix::edits::delete_stmt; use crate::checkers::ast::Checker; +use crate::fix::edits::delete_stmt; use crate::registry::AsRule; use crate::rules::pyupgrade::fixes::adjust_indentation; use crate::settings::types::PythonVersion; @@ -49,13 +49,13 @@ use crate::settings::types::PythonVersion; #[violation] pub struct OutdatedVersionBlock; -impl AlwaysAutofixableViolation for OutdatedVersionBlock { +impl AlwaysFixableViolation for OutdatedVersionBlock { #[derive_message_formats] fn message(&self) -> String { format!("Version block is outdated for minimum Python version") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove outdated version block".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs index 1d78d2a38b090..73bb0c73a7f23 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs @@ -1,6 +1,6 @@ use std::str::FromStr; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::str::{leading_quote, trailing_quote}; use ruff_python_ast::whitespace::indentation; @@ -44,14 +44,14 @@ use crate::rules::pyupgrade::helpers::curly_escape; pub struct PrintfStringFormatting; impl Violation for PrintfStringFormatting { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use format specifiers instead of percent format") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Replace with format specifiers".to_string()) } } @@ -465,7 +465,7 @@ pub(crate) fn printf_string_formatting(checker: &mut Checker, expr: &Expr, right contents.push_str(&format!(".format{params_string}")); let mut diagnostic = Diagnostic::new(PrintfStringFormatting, expr.range()); - // Avoid autofix if there are comments within the right-hand side: + // Avoid fix if there are comments within the right-hand side: // ``` // "%s" % ( // 0, # 0 diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs index 749e3011f5061..047d6366a96db 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/quoted_annotation.rs @@ -1,6 +1,6 @@ use ruff_text_size::TextRange; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use crate::checkers::ast::Checker; @@ -39,13 +39,13 @@ use crate::registry::Rule; #[violation] pub struct QuotedAnnotation; -impl AlwaysAutofixableViolation for QuotedAnnotation { +impl AlwaysFixableViolation for QuotedAnnotation { #[derive_message_formats] fn message(&self) -> String { format!("Remove quotes from type annotation") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove quotes".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs index cb6b496cc3077..6ae4acddc1e15 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/redundant_open_modes.rs @@ -2,7 +2,7 @@ use std::str::FromStr; use anyhow::{anyhow, Result}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Constant, Expr, PySourceType}; use ruff_python_parser::{lexer, AsMode}; @@ -39,7 +39,7 @@ pub struct RedundantOpenModes { replacement: Option, } -impl AlwaysAutofixableViolation for RedundantOpenModes { +impl AlwaysFixableViolation for RedundantOpenModes { #[derive_message_formats] fn message(&self) -> String { let RedundantOpenModes { replacement } = self; @@ -51,7 +51,7 @@ impl AlwaysAutofixableViolation for RedundantOpenModes { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let RedundantOpenModes { replacement } = self; match replacement { None => "Remove open mode parameters".to_string(), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs index 67ddaa118f2f3..2c862994ca7a8 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_stdout_stderr.rs @@ -1,12 +1,12 @@ use anyhow::Result; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Keyword}; use ruff_text_size::Ranged; -use crate::autofix::edits::{remove_argument, Parentheses}; use crate::checkers::ast::Checker; +use crate::fix::edits::{remove_argument, Parentheses}; use crate::registry::AsRule; /// ## What it does @@ -40,14 +40,14 @@ use crate::registry::AsRule; pub struct ReplaceStdoutStderr; impl Violation for ReplaceStdoutStderr { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Sending `stdout` and `stderr` to `PIPE` is deprecated, use `capture_output`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Replace with `capture_output` keyword argument".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs index 6f82e5940fec4..b7a61047ac89a 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/replace_universal_newlines.rs @@ -1,10 +1,10 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast as ast; use ruff_text_size::Ranged; -use crate::autofix::edits::{remove_argument, Parentheses}; use crate::checkers::ast::Checker; +use crate::fix::edits::{remove_argument, Parentheses}; use crate::registry::AsRule; /// ## What it does @@ -37,13 +37,13 @@ use crate::registry::AsRule; #[violation] pub struct ReplaceUniversalNewlines; -impl AlwaysAutofixableViolation for ReplaceUniversalNewlines { +impl AlwaysFixableViolation for ReplaceUniversalNewlines { #[derive_message_formats] fn message(&self) -> String { format!("`universal_newlines` is deprecated, use `text`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with `text` keyword argument".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs index b118baa3859ed..4f00a905c8395 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/super_call_with_parameters.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr, Parameter, ParameterWithDefault, Stmt}; use ruff_text_size::{Ranged, TextSize}; @@ -47,13 +47,13 @@ use crate::registry::AsRule; #[violation] pub struct SuperCallWithParameters; -impl AlwaysAutofixableViolation for SuperCallWithParameters { +impl AlwaysFixableViolation for SuperCallWithParameters { #[derive_message_formats] fn message(&self) -> String { format!("Use `super()` instead of `super(__class__, self)`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove `__super__` parameters".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs index 61e1643ce73d2..2ff6c4cc36d78 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/type_of_primitive.rs @@ -1,7 +1,7 @@ use ruff_python_ast::{self as ast, Expr}; -use crate::autofix::edits::pad; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use crate::fix::edits::pad; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -37,7 +37,7 @@ pub struct TypeOfPrimitive { } impl Violation for TypeOfPrimitive { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -45,7 +45,7 @@ impl Violation for TypeOfPrimitive { format!("Use `{}` instead of `type(...)`", primitive.builtin()) } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let TypeOfPrimitive { primitive } = self; Some(format!( "Replace `type(...)` with `{}`", diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs index fe749515c776b..52d99a95a90c5 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/typing_text_str_alias.rs @@ -1,6 +1,6 @@ use ruff_python_ast::Expr; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; @@ -33,14 +33,14 @@ use crate::registry::AsRule; pub struct TypingTextStrAlias; impl Violation for TypingTextStrAlias { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("`typing.Text` is deprecated, use `str`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Replace with `str`".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs index 887b98cb300c1..b3589e0fbe076 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unicode_kind_prefix.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::Expr; use ruff_text_size::{Ranged, TextRange, TextSize}; @@ -28,13 +28,13 @@ use crate::registry::AsRule; #[violation] pub struct UnicodeKindPrefix; -impl AlwaysAutofixableViolation for UnicodeKindPrefix { +impl AlwaysFixableViolation for UnicodeKindPrefix { #[derive_message_formats] fn message(&self) -> String { format!("Remove unicode literals from strings") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove unicode prefix".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs index 6a1f0553d18d1..f72a1f47192e2 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_builtin_import.rs @@ -1,12 +1,12 @@ use itertools::Itertools; use ruff_python_ast::{Alias, Stmt}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; -use crate::autofix; use crate::checkers::ast::Checker; +use crate::fix; use crate::registry::AsRule; /// ## What it does @@ -35,7 +35,7 @@ pub struct UnnecessaryBuiltinImport { pub names: Vec, } -impl AlwaysAutofixableViolation for UnnecessaryBuiltinImport { +impl AlwaysFixableViolation for UnnecessaryBuiltinImport { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryBuiltinImport { names } = self; @@ -48,7 +48,7 @@ impl AlwaysAutofixableViolation for UnnecessaryBuiltinImport { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove unnecessary builtin import".to_string() } } @@ -125,7 +125,7 @@ pub(crate) fn unnecessary_builtin_import( diagnostic.try_set_fix(|| { let statement = checker.semantic().current_statement(); let parent = checker.semantic().current_statement_parent(); - let edit = autofix::edits::remove_unused_imports( + let edit = fix::edits::remove_unused_imports( unused_imports .iter() .map(|alias| &alias.name) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs index 989cdb67304cf..4ba44b3b06ae2 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast}; use ruff_text_size::Ranged; @@ -28,13 +28,13 @@ use crate::registry::AsRule; #[violation] pub struct UnnecessaryClassParentheses; -impl AlwaysAutofixableViolation for UnnecessaryClassParentheses { +impl AlwaysFixableViolation for UnnecessaryClassParentheses { #[derive_message_formats] fn message(&self) -> String { format!("Unnecessary parentheses after class definition") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove parentheses".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs index d80d72e599215..7a64de5a26242 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_coding_comment.rs @@ -1,7 +1,7 @@ use once_cell::sync::Lazy; use regex::Regex; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_index::Indexer; use ruff_source_file::Locator; @@ -32,13 +32,13 @@ use crate::settings::LinterSettings; #[violation] pub struct UTF8EncodingDeclaration; -impl AlwaysAutofixableViolation for UTF8EncodingDeclaration { +impl AlwaysFixableViolation for UTF8EncodingDeclaration { #[derive_message_formats] fn message(&self) -> String { format!("UTF-8 encoding declaration is unnecessary") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove unnecessary coding comment".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs index 16c81e65feff9..79b900d32f104 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_encode_utf8.rs @@ -1,12 +1,12 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Arguments, Constant, Expr, Keyword, PySourceType}; use ruff_python_parser::{lexer, AsMode, Tok}; use ruff_source_file::Locator; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix::edits::{pad, remove_argument, Parentheses}; use crate::checkers::ast::Checker; +use crate::fix::edits::{pad, remove_argument, Parentheses}; use crate::registry::Rule; #[derive(Debug, PartialEq, Eq)] @@ -39,7 +39,7 @@ pub struct UnnecessaryEncodeUTF8 { reason: Reason, } -impl AlwaysAutofixableViolation for UnnecessaryEncodeUTF8 { +impl AlwaysFixableViolation for UnnecessaryEncodeUTF8 { #[derive_message_formats] fn message(&self) -> String { match self.reason { @@ -48,7 +48,7 @@ impl AlwaysAutofixableViolation for UnnecessaryEncodeUTF8 { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { match self.reason { Reason::BytesLiteral => "Rewrite as bytes literal".to_string(), Reason::DefaultArgument => "Remove unnecessary `encoding` argument".to_string(), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs index 4a7a432ce1579..f2398a163d82b 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs @@ -1,12 +1,12 @@ use itertools::Itertools; use ruff_python_ast::{Alias, Stmt}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; -use crate::autofix; use crate::checkers::ast::Checker; +use crate::fix; use crate::registry::AsRule; /// ## What it does @@ -41,7 +41,7 @@ pub struct UnnecessaryFutureImport { pub names: Vec, } -impl AlwaysAutofixableViolation for UnnecessaryFutureImport { +impl AlwaysFixableViolation for UnnecessaryFutureImport { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryFutureImport { names } = self; @@ -54,7 +54,7 @@ impl AlwaysAutofixableViolation for UnnecessaryFutureImport { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove unnecessary `__future__` import".to_string() } } @@ -114,7 +114,7 @@ pub(crate) fn unnecessary_future_import(checker: &mut Checker, stmt: &Stmt, name diagnostic.try_set_fix(|| { let statement = checker.semantic().current_statement(); let parent = checker.semantic().current_statement_parent(); - let edit = autofix::edits::remove_unused_imports( + let edit = fix::edits::remove_unused_imports( unused_imports .iter() .map(|alias| &alias.name) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs index ab910d634a919..ab95815c58239 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unpacked_list_comprehension.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{self as ast, Expr}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::any_over_expr; use ruff_text_size::Ranged; @@ -32,13 +32,13 @@ use crate::registry::AsRule; #[violation] pub struct UnpackedListComprehension; -impl AlwaysAutofixableViolation for UnpackedListComprehension { +impl AlwaysFixableViolation for UnpackedListComprehension { #[derive_message_formats] fn message(&self) -> String { format!("Replace unpacked list comprehension with a generator expression") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with generator expression".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs index aaeef4bba0ffb..2c1f5a3298b3c 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep585_annotation.rs @@ -1,6 +1,6 @@ use ruff_python_ast::Expr; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::call_path::compose_call_path; use ruff_python_semantic::analyze::typing::ModuleMember; @@ -56,7 +56,7 @@ pub struct NonPEP585Annotation { } impl Violation for NonPEP585Annotation { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -64,7 +64,7 @@ impl Violation for NonPEP585Annotation { format!("Use `{to}` instead of `{from}` for type annotation") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let NonPEP585Annotation { to, .. } = self; Some(format!("Replace with `{to}`")) } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs index c1fbbfa6cec22..c666e21c54359 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs @@ -1,11 +1,11 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Constant, Expr, ExprContext, Operator}; use ruff_python_semantic::analyze::typing::Pep604Operator; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix::edits::pad; use crate::checkers::ast::Checker; +use crate::fix::edits::pad; use crate::registry::AsRule; /// ## What it does @@ -45,14 +45,14 @@ use crate::registry::AsRule; pub struct NonPEP604Annotation; impl Violation for NonPEP604Annotation { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use `X | Y` for type annotations") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Convert to `X | Y`".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs index 3da0483432a2b..bd3536a9e5c67 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_isinstance.rs @@ -1,6 +1,6 @@ use std::fmt; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr, Operator}; use ruff_text_size::{Ranged, TextRange}; @@ -65,13 +65,13 @@ pub struct NonPEP604Isinstance { kind: CallKind, } -impl AlwaysAutofixableViolation for NonPEP604Isinstance { +impl AlwaysFixableViolation for NonPEP604Isinstance { #[derive_message_formats] fn message(&self) -> String { format!("Use `X | Y` in `{}` call instead of `(X, Y)`", self.kind) } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Convert to `X | Y`".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs index bd649693e8853..590d0491a39e6 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep695_type_alias.rs @@ -1,5 +1,5 @@ use ast::{Constant, ExprCall, ExprConstant}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{ self as ast, @@ -49,7 +49,7 @@ pub struct NonPEP695TypeAlias { } impl Violation for NonPEP695TypeAlias { - const AUTOFIX: AutofixKind = AutofixKind::Always; + const FIX_KIND: FixKind = FixKind::Always; #[derive_message_formats] fn message(&self) -> String { @@ -57,7 +57,7 @@ impl Violation for NonPEP695TypeAlias { format!("Type alias `{name}` uses `TypeAlias` annotation instead of the `type` keyword") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Use the `type` keyword".to_string()) } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs index f089ae91ab4df..cb4f9137d1a65 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_metaclass_type.rs @@ -1,11 +1,11 @@ use ruff_python_ast::{self as ast, Expr, Stmt}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_text_size::Ranged; -use crate::autofix; use crate::checkers::ast::Checker; +use crate::fix; use crate::registry::AsRule; /// ## What it does @@ -31,13 +31,13 @@ use crate::registry::AsRule; #[violation] pub struct UselessMetaclassType; -impl AlwaysAutofixableViolation for UselessMetaclassType { +impl AlwaysFixableViolation for UselessMetaclassType { #[derive_message_formats] fn message(&self) -> String { format!("`__metaclass__ = type` is implied") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove `__metaclass__ = type`".to_string() } } @@ -66,7 +66,7 @@ pub(crate) fn useless_metaclass_type( if checker.patch(diagnostic.kind.rule()) { let stmt = checker.semantic().current_statement(); let parent = checker.semantic().current_statement_parent(); - let edit = autofix::edits::delete_stmt(stmt, parent, checker.locator(), checker.indexer()); + let edit = fix::edits::delete_stmt(stmt, parent, checker.locator(), checker.indexer()); diagnostic.set_fix(Fix::automatic(edit).isolate(Checker::isolation( checker.semantic().current_statement_parent_id(), ))); diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs index a3a6093deed08..a1d55abe200d5 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/useless_object_inheritance.rs @@ -1,10 +1,10 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr}; use ruff_text_size::Ranged; -use crate::autofix::edits::{remove_argument, Parentheses}; use crate::checkers::ast::Checker; +use crate::fix::edits::{remove_argument, Parentheses}; use crate::registry::AsRule; /// ## What it does @@ -33,14 +33,14 @@ pub struct UselessObjectInheritance { name: String, } -impl AlwaysAutofixableViolation for UselessObjectInheritance { +impl AlwaysFixableViolation for UselessObjectInheritance { #[derive_message_formats] fn message(&self) -> String { let UselessObjectInheritance { name } = self; format!("Class `{name}` inherits from `object`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove `object` inheritance".to_string() } } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs index c9558966e5b42..90ecb927041dd 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/yield_in_for_loop.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::parenthesize::parenthesized_range; use ruff_python_ast::{self as ast, Expr, Stmt}; @@ -31,13 +31,13 @@ use crate::registry::AsRule; #[violation] pub struct YieldInForLoop; -impl AlwaysAutofixableViolation for YieldInForLoop { +impl AlwaysFixableViolation for YieldInForLoop { #[derive_message_formats] fn message(&self) -> String { format!("Replace `yield` over `for` loop with `yield from`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with `yield from`".to_string() } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs index fd2d46028957e..6a3bc5767f61f 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::helpers::contains_effect; @@ -7,8 +7,8 @@ use ruff_python_codegen::Generator; use ruff_python_semantic::analyze::typing::is_set; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix::snippet::SourceCodeSnippet; use crate::checkers::ast::Checker; +use crate::fix::snippet::SourceCodeSnippet; use crate::registry::AsRule; /// ## What it does @@ -54,14 +54,14 @@ impl CheckAndRemoveFromSet { } } -impl AlwaysAutofixableViolation for CheckAndRemoveFromSet { +impl AlwaysFixableViolation for CheckAndRemoveFromSet { #[derive_message_formats] fn message(&self) -> String { let suggestion = self.suggestion(); format!("Use `{suggestion}` instead of check and `remove`") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let suggestion = self.suggestion(); format!("Replace with `{suggestion}`") } diff --git a/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs b/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs index e84b081761e56..e5c17ddc00a10 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/delete_full_slice.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::analyze::typing::{is_dict, is_list}; @@ -47,14 +47,14 @@ use crate::rules::refurb::helpers::generate_method_call; pub struct DeleteFullSlice; impl Violation for DeleteFullSlice { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Prefer `clear` over deleting a full slice") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Replace with `clear()`".to_string()) } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs index be131ed09360a..36c5349b75495 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/print_empty_string.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Constant, Expr}; use ruff_python_codegen::Generator; @@ -43,7 +43,7 @@ enum Reason { } impl Violation for PrintEmptyString { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -55,7 +55,7 @@ impl Violation for PrintEmptyString { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let PrintEmptyString { reason } = self; match reason { Reason::EmptyArgument => Some("Remove empty string".to_string()), diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs index f8994b4cb995a..79933c10ea603 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs @@ -1,5 +1,5 @@ use anyhow::{bail, Result}; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::comparable::ComparableExpr; use ruff_python_ast::{self as ast, Expr}; @@ -57,14 +57,14 @@ use crate::registry::AsRule; pub struct ReimplementedStarmap; impl Violation for ReimplementedStarmap { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Use `itertools.starmap` instead of the generator") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some(format!("Replace with `itertools.starmap`")) } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs index 90737de73979b..6f927a029404c 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs @@ -1,7 +1,7 @@ use rustc_hash::FxHashMap; use ast::traversal; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr, Stmt}; use ruff_python_codegen::Generator; @@ -9,8 +9,8 @@ use ruff_python_semantic::analyze::typing::is_list; use ruff_python_semantic::{Binding, BindingId, DefinitionId, SemanticModel}; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix::snippet::SourceCodeSnippet; use crate::checkers::ast::Checker; +use crate::fix::snippet::SourceCodeSnippet; use crate::registry::AsRule; /// ## What it does @@ -60,7 +60,7 @@ impl RepeatedAppend { } impl Violation for RepeatedAppend { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -69,7 +69,7 @@ impl Violation for RepeatedAppend { format!("Use `{suggestion}` instead of repeatedly calling `{name}.append()`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let suggestion = self.suggestion(); Some(format!("Replace with `{suggestion}`")) } diff --git a/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs b/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs index 348c7772766f9..671bb3c3c1920 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/slice_copy.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr}; use ruff_python_semantic::analyze::typing::is_list; @@ -39,14 +39,14 @@ use crate::rules::refurb::helpers::generate_method_call; pub struct SliceCopy; impl Violation for SliceCopy { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("Prefer `copy` method over slicing") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { Some("Replace with `copy()`".to_string()) } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs index a8a6fceffd198..5a933a61d1b8c 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs @@ -2,15 +2,15 @@ use std::fmt; use num_traits::Zero; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast as ast; use ruff_python_ast::{Arguments, Constant, Expr}; use ruff_python_codegen::Generator; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix::edits::pad; use crate::checkers::ast::Checker; +use crate::fix::edits::pad; use crate::registry::AsRule; /// ## What it does @@ -53,7 +53,7 @@ pub struct UnnecessaryEnumerate { } impl Violation for UnnecessaryEnumerate { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -68,7 +68,7 @@ impl Violation for UnnecessaryEnumerate { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let UnnecessaryEnumerate { subset } = self; match subset { EnumerateSubset::Indices => Some("Replace with `range(len(...))`".to_string()), diff --git a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs index 012fab42a3659..686aa4c1bfcf1 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs @@ -1,10 +1,10 @@ -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Expr, ExprContext, Operator}; use ruff_text_size::{Ranged, TextRange}; -use crate::autofix::snippet::SourceCodeSnippet; use crate::checkers::ast::Checker; +use crate::fix::snippet::SourceCodeSnippet; use crate::registry::AsRule; /// ## What it does @@ -43,7 +43,7 @@ pub struct CollectionLiteralConcatenation { } impl Violation for CollectionLiteralConcatenation { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { @@ -55,7 +55,7 @@ impl Violation for CollectionLiteralConcatenation { } } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let CollectionLiteralConcatenation { expression } = self; if let Some(expression) = expression.full_display() { Some(format!("Replace with `{expression}`")) diff --git a/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs b/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs index 11302f4ba295d..f485b6a8e69d2 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/explicit_f_string_type_conversion.rs @@ -3,7 +3,7 @@ use libcst_native::{ ConcatenatedString, Expression, FormattedStringContent, FormattedStringExpression, }; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Arguments, Expr}; use ruff_python_codegen::Stylist; @@ -41,13 +41,13 @@ use crate::registry::AsRule; #[violation] pub struct ExplicitFStringTypeConversion; -impl AlwaysAutofixableViolation for ExplicitFStringTypeConversion { +impl AlwaysFixableViolation for ExplicitFStringTypeConversion { #[derive_message_formats] fn message(&self) -> String { format!("Use explicit conversion flag") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Replace with conversion flag".to_string() } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs b/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs index 1a87b6471c435..0d097c89526b1 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs @@ -2,7 +2,7 @@ use std::fmt; use anyhow::Result; -use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation}; +use ruff_diagnostics::{Diagnostic, Edit, Fix, FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_const_none; use ruff_python_ast::{self as ast, Constant, Expr, Operator, ParameterWithDefault, Parameters}; @@ -80,14 +80,14 @@ pub struct ImplicitOptional { } impl Violation for ImplicitOptional { - const AUTOFIX: AutofixKind = AutofixKind::Sometimes; + const FIX_KIND: FixKind = FixKind::Sometimes; #[derive_message_formats] fn message(&self) -> String { format!("PEP 484 prohibits implicit `Optional`") } - fn autofix_title(&self) -> Option { + fn fix_title(&self) -> Option { let ImplicitOptional { conversion_type } = self; Some(format!("Convert to `{conversion_type}`")) } diff --git a/crates/ruff_linter/src/rules/ruff/rules/invalid_pyproject_toml.rs b/crates/ruff_linter/src/rules/ruff/rules/invalid_pyproject_toml.rs index fc5482b9c24e2..45755d790e595 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/invalid_pyproject_toml.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/invalid_pyproject_toml.rs @@ -1,4 +1,4 @@ -use ruff_diagnostics::{AutofixKind, Violation}; +use ruff_diagnostics::{FixKind, Violation}; use ruff_macros::{derive_message_formats, violation}; /// ## What it does @@ -36,7 +36,7 @@ pub struct InvalidPyprojectToml { } impl Violation for InvalidPyprojectToml { - const AUTOFIX: AutofixKind = AutofixKind::None; + const FIX_KIND: FixKind = FixKind::None; #[derive_message_formats] fn message(&self) -> String { diff --git a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs index 1d85555132c8f..3fa4047e24db4 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/quadratic_list_summation.rs @@ -1,7 +1,7 @@ use anyhow::Result; use itertools::Itertools; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Arguments, Expr}; use ruff_python_semantic::SemanticModel; @@ -48,13 +48,13 @@ use crate::{checkers::ast::Checker, registry::Rule}; #[violation] pub struct QuadraticListSummation; -impl AlwaysAutofixableViolation for QuadraticListSummation { +impl AlwaysFixableViolation for QuadraticListSummation { #[derive_message_formats] fn message(&self) -> String { format!("Avoid quadratic list summation") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Replace with `functools.reduce`") } } diff --git a/crates/ruff_linter/src/rules/ruff/rules/static_key_dict_comprehension.rs b/crates/ruff_linter/src/rules/ruff/rules/static_key_dict_comprehension.rs index f119eaacd44b3..460495e262ea6 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/static_key_dict_comprehension.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/static_key_dict_comprehension.rs @@ -1,6 +1,6 @@ use ruff_python_ast::Expr; -use crate::autofix::snippet::SourceCodeSnippet; +use crate::fix::snippet::SourceCodeSnippet; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::helpers::is_constant; diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs index fe574e09a633d..4d3044799ec19 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_iterable_allocation_for_first_element.rs @@ -2,14 +2,14 @@ use std::borrow::Cow; use num_traits::Zero; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::{self as ast, Arguments, Comprehension, Constant, Expr}; use ruff_python_semantic::SemanticModel; use ruff_text_size::{Ranged, TextRange, TextSize}; -use crate::autofix::snippet::SourceCodeSnippet; use crate::checkers::ast::Checker; +use crate::fix::snippet::SourceCodeSnippet; use crate::registry::AsRule; /// ## What it does @@ -50,7 +50,7 @@ pub(crate) struct UnnecessaryIterableAllocationForFirstElement { iterable: SourceCodeSnippet, } -impl AlwaysAutofixableViolation for UnnecessaryIterableAllocationForFirstElement { +impl AlwaysFixableViolation for UnnecessaryIterableAllocationForFirstElement { #[derive_message_formats] fn message(&self) -> String { let UnnecessaryIterableAllocationForFirstElement { iterable } = self; @@ -58,7 +58,7 @@ impl AlwaysAutofixableViolation for UnnecessaryIterableAllocationForFirstElement format!("Prefer `next({iterable})` over single element slice") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { let UnnecessaryIterableAllocationForFirstElement { iterable } = self; let iterable = iterable.truncated_display(); format!("Replace with `next({iterable})`") diff --git a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs index 877983cb9a76a..b0a8662bade08 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unused_noqa.rs @@ -1,6 +1,6 @@ use itertools::Itertools; -use ruff_diagnostics::AlwaysAutofixableViolation; +use ruff_diagnostics::AlwaysFixableViolation; use ruff_macros::{derive_message_formats, violation}; #[derive(Debug, PartialEq, Eq)] @@ -42,7 +42,7 @@ pub struct UnusedNOQA { pub codes: Option, } -impl AlwaysAutofixableViolation for UnusedNOQA { +impl AlwaysFixableViolation for UnusedNOQA { #[derive_message_formats] fn message(&self) -> String { let UnusedNOQA { codes } = self; @@ -89,7 +89,7 @@ impl AlwaysAutofixableViolation for UnusedNOQA { } } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { "Remove unused `noqa` directive".to_string() } } diff --git a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs index 10c11798700cb..63c9f5c378b0b 100644 --- a/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs +++ b/crates/ruff_linter/src/rules/tryceratops/rules/verbose_raise.rs @@ -1,6 +1,6 @@ use ruff_python_ast::{self as ast, ExceptHandler, Expr, Stmt}; -use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix}; +use ruff_diagnostics::{AlwaysFixableViolation, Diagnostic, Edit, Fix}; use ruff_macros::{derive_message_formats, violation}; use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor}; use ruff_text_size::Ranged; @@ -35,13 +35,13 @@ use crate::registry::AsRule; #[violation] pub struct VerboseRaise; -impl AlwaysAutofixableViolation for VerboseRaise { +impl AlwaysFixableViolation for VerboseRaise { #[derive_message_formats] fn message(&self) -> String { format!("Use `raise` without specifying exception name") } - fn autofix_title(&self) -> String { + fn fix_title(&self) -> String { format!("Remove exception name") } } diff --git a/crates/ruff_linter/src/settings/rule_table.rs b/crates/ruff_linter/src/settings/rule_table.rs index 16438adf94bd5..25e8c13ea5ecf 100644 --- a/crates/ruff_linter/src/settings/rule_table.rs +++ b/crates/ruff_linter/src/settings/rule_table.rs @@ -5,10 +5,10 @@ use ruff_macros::CacheKey; use crate::registry::{Rule, RuleSet, RuleSetIterator}; /// A table to keep track of which rules are enabled -/// and Whether they should be autofixed. +/// and Whether they should be fixed. #[derive(Debug, CacheKey, Default)] pub struct RuleTable { - /// Maps rule codes to a boolean indicating if the rule should be autofixed. + /// Maps rule codes to a boolean indicating if the rule should be fixed. enabled: RuleSet, should_fix: RuleSet, } @@ -34,7 +34,7 @@ impl RuleTable { self.enabled.intersects(&RuleSet::from_rules(rules)) } - /// Returns whether violations of the given rule should be autofixed. + /// Returns whether violations of the given rule should be fixed. #[inline] pub const fn should_fix(&self, rule: Rule) -> bool { self.should_fix.contains(rule) diff --git a/crates/ruff_linter/src/test.rs b/crates/ruff_linter/src/test.rs index 2924814c08542..36041cdf085ca 100644 --- a/crates/ruff_linter/src/test.rs +++ b/crates/ruff_linter/src/test.rs @@ -9,7 +9,7 @@ use anyhow::Result; use itertools::Itertools; use rustc_hash::FxHashMap; -use ruff_diagnostics::{AutofixKind, Diagnostic}; +use ruff_diagnostics::{Diagnostic, FixKind}; use ruff_python_ast::PySourceType; use ruff_python_codegen::Stylist; use ruff_python_index::Indexer; @@ -19,8 +19,8 @@ use ruff_python_trivia::textwrap::dedent; use ruff_source_file::{Locator, SourceFileBuilder}; use ruff_text_size::Ranged; -use crate::autofix::{fix_file, FixResult}; use crate::directives; +use crate::fix::{fix_file, FixResult}; use crate::linter::{check_path, LinterResult}; use crate::message::{Emitter, EmitterContext, Message, TextEmitter}; use crate::packaging::detect_package_root; @@ -102,7 +102,7 @@ pub(crate) fn max_iterations() -> usize { } /// A convenient wrapper around [`check_path`], that additionally -/// asserts that autofixes converge after a fixed number of iterations. +/// asserts that fixes converge after a fixed number of iterations. pub(crate) fn test_contents<'a>( source_kind: &'a SourceKind, path: &Path, @@ -140,7 +140,7 @@ pub(crate) fn test_contents<'a>( let source_has_errors = error.is_some(); - // Detect autofixes that don't converge after multiple iterations. + // Detect fixes that don't converge after multiple iterations. let mut iterations = 0; let mut transformed = Cow::Borrowed(source_kind); @@ -238,20 +238,20 @@ Source with applied fixes: let rule = diagnostic.kind.rule(); let fixable = diagnostic.fix.is_some(); - match (fixable, rule.autofixable()) { - (true, AutofixKind::Sometimes | AutofixKind::Always) - | (false, AutofixKind::None | AutofixKind::Sometimes) => { + match (fixable, rule.fixable()) { + (true, FixKind::Sometimes | FixKind::Always) + | (false, FixKind::None | FixKind::Sometimes) => { // Ok } - (true, AutofixKind::None) => { - panic!("Rule {rule:?} is marked as non-fixable but it created a fix. Change the `Violation::AUTOFIX` to either `AutofixKind::Sometimes` or `AutofixKind::Always`"); + (true, FixKind::None) => { + panic!("Rule {rule:?} is marked as non-fixable but it created a fix. Change the `Violation::FIX_KIND` to either `FixKind::Sometimes` or `FixKind::Always`"); }, - (false, AutofixKind::Always) => { - panic!("Rule {rule:?} is marked to always-fixable but the diagnostic has no fix. Either ensure you always emit a fix or change `Violation::AUTOFIX` to either `AutofixKind::Sometimes` or `AutofixKind::None") + (false, FixKind::Always) => { + panic!("Rule {rule:?} is marked to always-fixable but the diagnostic has no fix. Either ensure you always emit a fix or change `Violation::FIX_KINDd` to either `FixKind::Sometimes` or `FixKind::None") } } - assert!(!(fixable && diagnostic.kind.suggestion.is_none()), "Diagnostic emitted by {rule:?} is fixable but `Violation::autofix_title` returns `None`.`"); + assert!(!(fixable && diagnostic.kind.suggestion.is_none()), "Diagnostic emitted by {rule:?} is fixable but `Violation::fix_title` returns `None`.`"); // Not strictly necessary but adds some coverage for this code path let noqa = directives.noqa_line_for.resolve(diagnostic.start()); diff --git a/crates/ruff_macros/src/map_codes.rs b/crates/ruff_macros/src/map_codes.rs index 8575ebc1338c2..d9d0c5112a2d1 100644 --- a/crates/ruff_macros/src/map_codes.rs +++ b/crates/ruff_macros/src/map_codes.rs @@ -388,7 +388,7 @@ fn generate_iter_impl( fn register_rules<'a>(input: impl Iterator) -> TokenStream { let mut rule_variants = quote!(); let mut rule_message_formats_match_arms = quote!(); - let mut rule_autofixable_match_arms = quote!(); + let mut rule_fixable_match_arms = quote!(); let mut rule_explanation_match_arms = quote!(); let mut from_impls_for_diagnostic_kind = quote!(); @@ -404,8 +404,8 @@ fn register_rules<'a>(input: impl Iterator) -> TokenStream { // Apply the `attrs` to each arm, like `[cfg(feature = "foo")]`. rule_message_formats_match_arms .extend(quote! {#(#attrs)* Self::#name => <#path as ruff_diagnostics::Violation>::message_formats(),}); - rule_autofixable_match_arms.extend( - quote! {#(#attrs)* Self::#name => <#path as ruff_diagnostics::Violation>::AUTOFIX,}, + rule_fixable_match_arms.extend( + quote! {#(#attrs)* Self::#name => <#path as ruff_diagnostics::Violation>::FIX_KIND,}, ); rule_explanation_match_arms .extend(quote! {#(#attrs)* Self::#name => #path::explanation(),}); @@ -445,9 +445,9 @@ fn register_rules<'a>(input: impl Iterator) -> TokenStream { match self { #rule_explanation_match_arms } } - /// Returns the autofix status of this rule. - pub const fn autofixable(&self) -> ruff_diagnostics::AutofixKind { - match self { #rule_autofixable_match_arms } + /// Returns the fix status of this rule. + pub const fn fixable(&self) -> ruff_diagnostics::FixKind { + match self { #rule_fixable_match_arms } } } diff --git a/crates/ruff_macros/src/violation.rs b/crates/ruff_macros/src/violation.rs index 8356d0d56ce7e..0f39001b1a57b 100644 --- a/crates/ruff_macros/src/violation.rs +++ b/crates/ruff_macros/src/violation.rs @@ -59,7 +59,7 @@ pub(crate) fn violation(violation: &ItemStruct) -> Result { Self { body: Violation::message(&value), - suggestion: Violation::autofix_title(&value), + suggestion: Violation::fix_title(&value), name: stringify!(#ident).to_string(), } } @@ -82,7 +82,7 @@ pub(crate) fn violation(violation: &ItemStruct) -> Result { Self { body: Violation::message(&value), - suggestion: Violation::autofix_title(&value), + suggestion: Violation::fix_title(&value), name: stringify!(#ident).to_string(), } } diff --git a/crates/ruff_notebook/src/notebook.rs b/crates/ruff_notebook/src/notebook.rs index 66b91199a449a..5b87bc86e332f 100644 --- a/crates/ruff_notebook/src/notebook.rs +++ b/crates/ruff_notebook/src/notebook.rs @@ -363,7 +363,7 @@ impl Notebook { /// Return the Jupyter notebook index. /// /// The index is built only once when required. This is only used to - /// report diagnostics, so by that time all of the autofixes must have + /// report diagnostics, so by that time all of the fixes must have /// been applied if `--fix` was passed. pub fn index(&self) -> &NotebookIndex { self.index.get_or_init(|| self.build_index()) diff --git a/crates/ruff_workspace/src/options.rs b/crates/ruff_workspace/src/options.rs index 7963ef48f2346..928d0f400fa2e 100644 --- a/crates/ruff_workspace/src/options.rs +++ b/crates/ruff_workspace/src/options.rs @@ -203,13 +203,13 @@ pub struct Options { )] pub extend_select: Option>, - /// A list of rule codes or prefixes to consider autofixable, in addition to those + /// A list of rule codes or prefixes to consider fixable, in addition to those /// specified by `fixable`. #[option( default = r#"[]"#, value_type = "list[RuleSelector]", example = r#" - # Enable autofix for flake8-bugbear (`B`), on top of any rules specified by `fixable`. + # Enable fix for flake8-bugbear (`B`), on top of any rules specified by `fixable`. extend-fixable = ["B"] "# )] @@ -238,7 +238,7 @@ pub struct Options { )] pub external: Option>, - /// Enable autofix behavior by-default when running `ruff` (overridden + /// Enable fix behavior by-default when running `ruff` (overridden /// by the `--fix` and `--no-fix` command-line flags). #[option(default = "false", value_type = "bool", example = "fix = true")] pub fix: Option, @@ -247,13 +247,13 @@ pub struct Options { #[option(default = "false", value_type = "bool", example = "fix-only = true")] pub fix_only: Option, - /// A list of rule codes or prefixes to consider autofixable. By default, - /// all rules are considered autofixable. + /// A list of rule codes or prefixes to consider fixable. By default, + /// all rules are considered fixable. #[option( default = r#"["ALL"]"#, value_type = "list[RuleSelector]", example = r#" - # Only allow autofix behavior for `E` and `F` rules. + # Only allow fix behavior for `E` and `F` rules. fixable = ["E", "F"] "# )] @@ -448,7 +448,7 @@ pub struct Options { )] pub show_source: Option, - /// Whether to show an enumeration of all autofixed lint violations + /// Whether to show an enumeration of all fixed lint violations /// (overridden by the `--show-fixes` command-line flag). #[option( default = "false", @@ -570,12 +570,12 @@ pub struct Options { )] pub typing_modules: Option>, - /// A list of rule codes or prefixes to consider non-autofix-able. + /// A list of rule codes or prefixes to consider non-fixable. #[option( default = "[]", value_type = "list[RuleSelector]", example = r#" - # Disable autofix for unused imports (`F401`). + # Disable fix for unused imports (`F401`). unfixable = ["F401"] "# )] diff --git a/docs/configuration.md b/docs/configuration.md index 8cce70bcc6c11..e97374b62014a 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -17,7 +17,7 @@ If left unspecified, Ruff's default configuration is equivalent to: select = ["E", "F"] ignore = [] -# Allow autofix for all enabled rules (when `--fix`) is provided. +# Allow fix for all enabled rules (when `--fix`) is provided. fixable = ["ALL"] unfixable = [] @@ -109,8 +109,8 @@ If you're wondering how to configure Ruff, here are some **recommended guideline - Start with a small set of rules (`select = ["E", "F"]`) and add a category at-a-time. For example, you might consider expanding to `select = ["E", "F", "B"]` to enable the popular flake8-bugbear extension. -- By default, Ruff's autofix is aggressive. If you find that it's too aggressive for your liking, - consider turning off autofix for specific rules or categories (see [_FAQ_](faq.md#ruff-tried-to-fix-something--but-it-broke-my-code)). +- By default, Ruff's fixes are aggressive. If you find that it's too aggressive for your liking, + consider turning off fixes for specific rules or categories (see [_FAQ_](faq.md#ruff-tried-to-fix-something--but-it-broke-my-code)). ## Using `ruff.toml` @@ -197,7 +197,7 @@ Options: --show-source Show violations with source code. Use `--no-show-source` to disable --show-fixes - Show an enumeration of all autofixed lint violations. Use `--no-show-fixes` to disable + Show an enumeration of all fixed lint violations. Use `--no-show-fixes` to disable --diff Avoid writing any fixed files back; instead, output a diff for each changed file to stdout. Implies `--fix-only` -w, --watch @@ -239,9 +239,9 @@ Rule selection: --extend-per-file-ignores Like `--per-file-ignores`, but adds additional ignores on top of those already specified --fixable - List of rule codes to treat as eligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`) + List of rule codes to treat as eligible for fix. Only applicable when fix itself is enabled (e.g., via `--fix`) --unfixable - List of rule codes to treat as ineligible for autofix. Only applicable when autofix itself is enabled (e.g., via `--fix`) + List of rule codes to treat as ineligible for fix. Only applicable when fix itself is enabled (e.g., via `--fix`) --extend-fixable Like --fixable, but adds additional rule codes on top of those already specified @@ -263,7 +263,7 @@ Miscellaneous: -e, --exit-zero Exit with status code "0", even upon detecting lint violations --exit-non-zero-on-fix - Exit with a non-zero status code if any files were modified via autofix, even if no lint violations remain + Exit with a non-zero status code if any files were modified via fix, even if no lint violations remain Log levels: -v, --verbose Enable verbose logging @@ -433,7 +433,7 @@ First, Ruff provides a special rule code, `RUF100`, to enforce that your `noqa` (and thus suppressed). You can run `ruff check /path/to/file.py --extend-select RUF100` to flag unused `noqa` directives. -Second, Ruff can _automatically remove_ unused `noqa` directives via its autofix functionality. +Second, Ruff can _automatically remove_ unused `noqa` directives via its fix functionality. You can run `ruff check /path/to/file.py --extend-select RUF100 --fix` to automatically remove unused `noqa` directives. @@ -474,7 +474,7 @@ Ruff supports two command-line flags that alter its exit code behavior: - `--exit-non-zero-on-fix` will cause Ruff to exit with a status code of `1` if violations were found, _even if_ all such violations were fixed automatically. Note that the use of `--exit-non-zero-on-fix` can result in a non-zero exit code even if no violations remain after - autofixing. + fixing. ## Shell autocompletion diff --git a/docs/editor-integrations.md b/docs/editor-integrations.md index 45b1e2da4928f..ce76e01fa3986 100644 --- a/docs/editor-integrations.md +++ b/docs/editor-integrations.md @@ -3,7 +3,7 @@ ## VS Code (Official) Download the [Ruff VS Code extension](https://marketplace.visualstudio.com/items?itemName=charliermarsh.ruff), -which supports autofix actions, import sorting, and more. +which supports fix actions, import sorting, and more. ![Ruff VS Code extension](https://user-images.githubusercontent.com/1309177/205175763-cf34871d-5c05-4abf-9916-440afc82dbf8.gif) diff --git a/docs/faq.md b/docs/faq.md index fa82b1abeb885..185958c6272be 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -436,14 +436,14 @@ For more, see the [`dirs`](https://docs.rs/dirs/4.0.0/dirs/fn.config_dir.html) c ## Ruff tried to fix something — but it broke my code? -Ruff's autofix is a best-effort mechanism. Given the dynamic nature of Python, it's difficult to +Ruff's fixes are a best-effort mechanism. Given the dynamic nature of Python, it's difficult to have _complete_ certainty when making changes to code, even for the seemingly trivial fixes. -In the future, Ruff will support enabling autofix behavior based on the safety of the patch. +In the future, Ruff will support enabling fix behavior based on the safety of the patch. -In the meantime, if you find that the autofix is too aggressive, you can disable it on a per-rule or +In the meantime, if you find that the fixes are too aggressive, you can disable it on a per-rule or per-category basis using the [`unfixable`](settings.md#unfixable) mechanic. -For example, to disable autofix for some possibly-unsafe rules, you could add the following to your +For example, to disable the fix for some possibly-unsafe rules, you could add the following to your `pyproject.toml`: ```toml @@ -451,7 +451,7 @@ For example, to disable autofix for some possibly-unsafe rules, you could add th unfixable = ["B", "SIM", "TRY", "RUF"] ``` -If you find a case where Ruff's autofix breaks your code, please file an Issue! +If you find a case where Ruff's fix breaks your code, please file an Issue! ## How can I disable Ruff's color output? diff --git a/docs/usage.md b/docs/usage.md index fd15f4da0dfc1..12f0a6071f637 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -28,7 +28,7 @@ Ruff can also be used as a [pre-commit](https://pre-commit.com) hook: - id: ruff ``` -Or, to enable autofix: +Or, to enable fixes: ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit @@ -51,8 +51,8 @@ Or, to run the hook on Jupyter Notebooks too: ``` Ruff's pre-commit hook should be placed after other formatting tools, such as Black and isort, -_unless_ you enable autofix, in which case, Ruff's pre-commit hook should run _before_ Black, isort, -and other formatting tools, as Ruff's autofix behavior can output code changes that require +_unless_ you enable fixes, in which case, Ruff's pre-commit hook should run _before_ Black, isort, +and other formatting tools, as Ruff's fix behavior can output code changes that require reformatting. ## VS Code diff --git a/playground/src/Editor/SourceEditor.tsx b/playground/src/Editor/SourceEditor.tsx index 33b9b48473d40..fc80574ad931c 100644 --- a/playground/src/Editor/SourceEditor.tsx +++ b/playground/src/Editor/SourceEditor.tsx @@ -61,7 +61,7 @@ export default function SourceEditor({ ? check.fix.message ? `${check.code}: ${check.fix.message}` : `Fix ${check.code}` - : "Autofix", + : "Fix", id: `fix-${check.code}`, kind: "quickfix", edit: check.fix diff --git a/ruff.schema.json b/ruff.schema.json index 07d35210b27b5..e7f51d3037f37 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -67,7 +67,7 @@ } }, "extend-fixable": { - "description": "A list of rule codes or prefixes to consider autofixable, in addition to those specified by `fixable`.", + "description": "A list of rule codes or prefixes to consider fixable, in addition to those specified by `fixable`.", "type": [ "array", "null" @@ -120,7 +120,7 @@ } }, "fix": { - "description": "Enable autofix behavior by-default when running `ruff` (overridden by the `--fix` and `--no-fix` command-line flags).", + "description": "Enable fix behavior by-default when running `ruff` (overridden by the `--fix` and `--no-fix` command-line flags).", "type": [ "boolean", "null" @@ -134,7 +134,7 @@ ] }, "fixable": { - "description": "A list of rule codes or prefixes to consider autofixable. By default, all rules are considered autofixable.", + "description": "A list of rule codes or prefixes to consider fixable. By default, all rules are considered fixable.", "type": [ "array", "null" @@ -545,7 +545,7 @@ } }, "show-fixes": { - "description": "Whether to show an enumeration of all autofixed lint violations (overridden by the `--show-fixes` command-line flag).", + "description": "Whether to show an enumeration of all fixed lint violations (overridden by the `--show-fixes` command-line flag).", "type": [ "boolean", "null" @@ -611,7 +611,7 @@ } }, "unfixable": { - "description": "A list of rule codes or prefixes to consider non-autofix-able.", + "description": "A list of rule codes or prefixes to consider non-fixable.", "type": [ "array", "null" diff --git a/scripts/ecosystem_all_check.py b/scripts/ecosystem_all_check.py index 8111821d9a991..8882142e85f14 100644 --- a/scripts/ecosystem_all_check.py +++ b/scripts/ecosystem_all_check.py @@ -1,5 +1,5 @@ """This is @konstin's scripts for checking an entire checkout of ~2.1k packages for -panics, autofix errors and similar problems. +panics, fix errors and similar problems. It's a less elaborate, more hacky version of check_ecosystem.py """ diff --git a/scripts/ecosystem_all_check.sh b/scripts/ecosystem_all_check.sh index 7c3233cc33b9a..20181082802f3 100755 --- a/scripts/ecosystem_all_check.sh +++ b/scripts/ecosystem_all_check.sh @@ -1,6 +1,6 @@ #!/bin/bash # This is @konstin's setup for checking an entire checkout of ~3k packages for -# panics, autofix errors and similar problems. +# panics, fix errors and similar problems. # # We put this in a docker container because processing random scraped code from GitHub is # [kinda dangerous](https://moyix.blogspot.com/2022/09/someones-been-messing-with-my-subnormals.html) @@ -28,7 +28,7 @@ time docker run --rm -it \ -v "${SCRIPT_DIR}/ecosystem_all_check.py:/app/ecosystem_all_check.py" \ python:3.11 ./ecosystem_all_check_entrypoint.sh "$@" -# grep the autofix errors -grep -R "the rule codes" "${SCRIPT_DIR}/../target/ecosystem_all_results" | sort > "${SCRIPT_DIR}/../target/autofix-errors.txt" +# grep the fix errors +grep -R "the rule codes" "${SCRIPT_DIR}/../target/ecosystem_all_results" | sort > "${SCRIPT_DIR}/../target/fix-errors.txt" # Make sure we didn't have an early exit echo "Done"