Use expression span for yoda-conditions fixes (#3276)

This commit is contained in:
Charlie Marsh
2023-02-28 11:59:02 -05:00
committed by GitHub
parent 67d1f74587
commit c7e09b54b0
3 changed files with 22 additions and 3 deletions

View File

@@ -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"

View File

@@ -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);

View File

@@ -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: ~