Fix range for try-consider-else (#2228)

This commit is contained in:
Charlie Marsh
2023-01-26 16:36:18 -05:00
committed by GitHub
parent 224334b6d1
commit 291239b9f1
3 changed files with 9 additions and 9 deletions

View File

@@ -13,7 +13,7 @@ define_violation!(
impl Violation for TryConsiderElse {
#[derive_message_formats]
fn message(&self) -> String {
format!("Consider `else` block")
format!("Consider moving this statement to an `else` block")
}
}
@@ -22,10 +22,9 @@ pub fn try_consider_else(checker: &mut Checker, body: &[Stmt], orelse: &[Stmt])
if body.len() > 1 && orelse.is_empty() {
if let Some(stmt) = body.last() {
if let StmtKind::Return { .. } = &stmt.node {
checker.diagnostics.push(Diagnostic::new(
TryConsiderElse,
Range::from_located(&body[0]),
));
checker
.diagnostics
.push(Diagnostic::new(TryConsiderElse, Range::from_located(stmt)));
}
}
}

View File

@@ -5,10 +5,11 @@ expression: diagnostics
- kind:
TryConsiderElse: ~
location:
row: 18
row: 20
column: 8
end_location:
row: 18
column: 13
row: 20
column: 16
fix: ~
parent: ~