From c7e09b54b0c5fa9338ca4cfcddb739c995bfc0f2 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 28 Feb 2023 11:59:02 -0500 Subject: [PATCH] Use expression span for yoda-conditions fixes (#3276) --- .../test/fixtures/flake8_simplify/SIM300.py | 1 + .../flake8_simplify/rules/yoda_conditions.rs | 4 ++-- ...ke8_simplify__tests__SIM300_SIM300.py.snap | 20 ++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/crates/ruff/resources/test/fixtures/flake8_simplify/SIM300.py b/crates/ruff/resources/test/fixtures/flake8_simplify/SIM300.py index 909eff236d..ac327ca6ca 100644 --- a/crates/ruff/resources/test/fixtures/flake8_simplify/SIM300.py +++ b/crates/ruff/resources/test/fixtures/flake8_simplify/SIM300.py @@ -11,6 +11,7 @@ YODA > age # SIM300 YODA >= age # SIM300 JediOrder.YODA == age # SIM300 0 < (number - 100) # SIM300 +SomeClass().settings.SOME_CONSTANT_VALUE > (60 * 60) # SIM300 # OK compare == "yoda" diff --git a/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs b/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs index 62f1bb61f7..2c1d28c224 100644 --- a/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs +++ b/crates/ruff/src/rules/flake8_simplify/rules/yoda_conditions.rs @@ -160,8 +160,8 @@ pub fn yoda_conditions( if checker.patch(diagnostic.kind.rule()) { diagnostic.amend(Fix::replacement( suggestion, - left.location, - right.end_location.unwrap(), + expr.location, + expr.end_location.unwrap(), )); } checker.diagnostics.push(diagnostic); diff --git a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM300_SIM300.py.snap b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM300_SIM300.py.snap index 0615dc3f13..e0799923ee 100644 --- a/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM300_SIM300.py.snap +++ b/crates/ruff/src/rules/flake8_simplify/snapshots/ruff__rules__flake8_simplify__tests__SIM300_SIM300.py.snap @@ -216,6 +216,24 @@ expression: diagnostics column: 0 end_location: row: 13 - column: 17 + column: 18 + parent: ~ +- kind: + YodaConditions: + suggestion: (60 * 60) < SomeClass().settings.SOME_CONSTANT_VALUE + location: + row: 14 + column: 0 + end_location: + row: 14 + column: 52 + fix: + content: (60 * 60) < SomeClass().settings.SOME_CONSTANT_VALUE + location: + row: 14 + column: 0 + end_location: + row: 14 + column: 52 parent: ~