Fix range for try-consider-else (#2228)
This commit is contained in:
@@ -1274,7 +1274,7 @@ For more, see [tryceratops](https://pypi.org/project/tryceratops/1.1.0/) on PyPI
|
||||
| TRY004 | prefer-type-error | Prefer `TypeError` exception for invalid type | 🛠 |
|
||||
| TRY200 | reraise-no-cause | Use `raise from` to specify exception cause | |
|
||||
| TRY201 | verbose-raise | Use `raise` without specifying exception name | |
|
||||
| TRY300 | try-consider-else | Consider `else` block | |
|
||||
| TRY300 | try-consider-else | Consider moving this statement to an `else` block | |
|
||||
| TRY301 | raise-within-try | Abstract `raise` to an inner function | |
|
||||
| TRY400 | error-instead-of-exception | Use `logging.exception` instead of `logging.error` | |
|
||||
|
||||
|
||||
@@ -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