diff --git a/crates/ruff_linter/resources/test/fixtures/pylint/swap_with_temporary_variable.py b/crates/ruff_linter/resources/test/fixtures/pylint/swap_with_temporary_variable.py deleted file mode 100644 index 54e2dc330d6d7..0000000000000 --- a/crates/ruff_linter/resources/test/fixtures/pylint/swap_with_temporary_variable.py +++ /dev/null @@ -1,62 +0,0 @@ -# safe fix -def foo(x: int, y: int): - temp: int = x - x = y - y = temp - - -# safe fix inside an if condition -def foo(x: int, y: int): - if x > 5: - temp: int = x - x = y - y = temp - - -# unsafe fix because the swap statements contain a comment -def bar(x: int, y: int): - temp: int = x # comment - x = y - y = temp - - -# not a swap statement -def baz(x: int, y: int): - temp = x - x = y - y = x - - -# not a simple swap statement because temp variable is re-used later -def foobar(x: int, y: int): - temp = x - x = y - y = temp - - # use temp variable again, - # so its declaration can't be removed - z = temp - - -# not a simple swap statement because the temp variable is global -swap_var = 0 - - -def quux(x: int, y: int): - global swap_var - swap_var = x - x = y - y = swap_var - - -# temp is read somewhere else in the code, so this is not a simple swap statement and hence ignored -def foo(x, y): - temp = [] - - def bar(): - print(temp) - - temp = x - x = y - y = temp - bar() diff --git a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs index 81dee25d3a183..26cf91873165d 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs @@ -28,7 +28,6 @@ pub(crate) fn deferred_scopes(checker: &Checker) { Rule::RuntimeImportInTypeCheckingBlock, Rule::SingledispatchMethod, Rule::SingledispatchmethodFunction, - Rule::SwapWithTemporaryVariable, Rule::TooManyLocals, Rule::TypingOnlyFirstPartyImport, Rule::TypingOnlyStandardLibraryImport, @@ -95,10 +94,6 @@ pub(crate) fn deferred_scopes(checker: &Checker) { pylint::rules::global_variable_not_assigned(checker, scope); } - if checker.is_rule_enabled(Rule::SwapWithTemporaryVariable) { - pylint::rules::swap_with_temporary_variable(checker, scope_id, scope); - } - if checker.is_rule_enabled(Rule::RedefinedArgumentFromLocal) { pylint::rules::redefined_argument_from_local(checker, scope_id, scope); } diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 4b0cfba291847..9482940b0c58d 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -288,7 +288,6 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Pylint, "R1706") => rules::pylint::rules::AndOrTernary, (Pylint, "R1708") => rules::pylint::rules::StopIterationReturn, (Pylint, "R1711") => rules::pylint::rules::UselessReturn, - (Pylint, "R1712") => rules::pylint::rules::SwapWithTemporaryVariable, (Pylint, "R1714") => rules::pylint::rules::RepeatedEqualityComparison, (Pylint, "R1722") => rules::pylint::rules::SysExitAlias, (Pylint, "R1730") => rules::pylint::rules::IfStmtMinMax, diff --git a/crates/ruff_linter/src/rules/pylint/mod.rs b/crates/ruff_linter/src/rules/pylint/mod.rs index c8ae94c246f37..de341b1146ba2 100644 --- a/crates/ruff_linter/src/rules/pylint/mod.rs +++ b/crates/ruff_linter/src/rules/pylint/mod.rs @@ -46,10 +46,6 @@ mod tests { #[test_case(Rule::CompareToEmptyString, Path::new("compare_to_empty_string.py"))] #[test_case(Rule::ComparisonOfConstant, Path::new("comparison_of_constant.py"))] #[test_case(Rule::ComparisonWithItself, Path::new("comparison_with_itself.py"))] - #[test_case( - Rule::SwapWithTemporaryVariable, - Path::new("swap_with_temporary_variable.py") - )] #[test_case(Rule::EqWithoutHash, Path::new("eq_without_hash.py"))] #[test_case(Rule::EmptyComment, Path::new("empty_comment.py"))] #[test_case(Rule::EmptyComment, Path::new("empty_comment_line_continuation.py"))] diff --git a/crates/ruff_linter/src/rules/pylint/rules/mod.rs b/crates/ruff_linter/src/rules/pylint/rules/mod.rs index 070ad5797ffbc..2853bb84c9dc7 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/mod.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/mod.rs @@ -79,7 +79,6 @@ pub(crate) use stop_iteration_return::*; pub(crate) use subprocess_popen_preexec_fn::*; pub(crate) use subprocess_run_without_check::*; pub(crate) use super_without_brackets::*; -pub(crate) use swap_with_temporary_variable::*; pub(crate) use sys_exit_alias::*; pub(crate) use too_many_arguments::*; pub(crate) use too_many_boolean_expressions::*; @@ -191,7 +190,6 @@ mod stop_iteration_return; mod subprocess_popen_preexec_fn; mod subprocess_run_without_check; mod super_without_brackets; -mod swap_with_temporary_variable; mod sys_exit_alias; mod too_many_arguments; mod too_many_boolean_expressions; diff --git a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR1712_swap_with_temporary_variable.py.snap b/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR1712_swap_with_temporary_variable.py.snap deleted file mode 100644 index 943005a442499..0000000000000 --- a/crates/ruff_linter/src/rules/pylint/snapshots/ruff_linter__rules__pylint__tests__PLR1712_swap_with_temporary_variable.py.snap +++ /dev/null @@ -1,68 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/pylint/mod.rs ---- -PLR1712 [*] Unnecessary temporary variable - --> swap_with_temporary_variable.py:3:5 - | -1 | # safe fix -2 | def foo(x: int, y: int): -3 | / temp: int = x -4 | | x = y -5 | | y = temp - | |____________^ - | -help: Use `x, y = y, x` instead -1 | # safe fix -2 | def foo(x: int, y: int): - - temp: int = x - - x = y - - y = temp -3 + x, y = y, x -4 | -5 | -6 | # safe fix inside an if condition - -PLR1712 [*] Unnecessary temporary variable - --> swap_with_temporary_variable.py:11:9 - | - 9 | def foo(x: int, y: int): -10 | if x > 5: -11 | / temp: int = x -12 | | x = y -13 | | y = temp - | |________________^ - | -help: Use `x, y = y, x` instead -8 | # safe fix inside an if condition -9 | def foo(x: int, y: int): -10 | if x > 5: - - temp: int = x - - x = y - - y = temp -11 + x, y = y, x -12 | -13 | -14 | # unsafe fix because the swap statements contain a comment - -PLR1712 [*] Unnecessary temporary variable - --> swap_with_temporary_variable.py:18:5 - | -16 | # unsafe fix because the swap statements contain a comment -17 | def bar(x: int, y: int): -18 | / temp: int = x # comment -19 | | x = y -20 | | y = temp - | |____________^ - | -help: Use `x, y = y, x` instead -15 | -16 | # unsafe fix because the swap statements contain a comment -17 | def bar(x: int, y: int): - - temp: int = x # comment - - x = y - - y = temp -18 + x, y = y, x -19 | -20 | -21 | # not a swap statement -note: This is an unsafe fix and may change runtime behavior diff --git a/ruff.schema.json b/ruff.schema.json index 2ed8873a2f522..098f57910d2b0 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -3817,7 +3817,6 @@ "PLR1708", "PLR171", "PLR1711", - "PLR1712", "PLR1714", "PLR1716", "PLR172",