mirror of
https://github.com/astral-sh/ruff
synced 2026-01-22 05:51:03 -05:00
Fix range for try-consider-else (#2228)
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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: ~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user